|
17 | 17 | type=str, nargs='?')
|
18 | 18 | args = parser.parse_args()
|
19 | 19 | if not re.search(flag_re, args.flag):
|
20 |
| - raise ValueError(f'Unexpected flag format. Flag must match the regular expression {flag_re}.') |
| 20 | + raise ValueError( |
| 21 | + f'Unexpected flag format. Flag must match the regular expression {flag_re}.') |
21 | 22 |
|
22 | 23 | packets = rdpcap(args.input)
|
23 | 24 | new_packets = []
|
24 | 25 | for packet in packets:
|
25 | 26 | ip_packet = packet.getlayer('IP')
|
26 |
| - if ip_packet and ip_packet.dport == 433: |
27 |
| - raw_payload = ip_packet.getlayer('TCP').payload |
| 27 | + if ip_packet and ip_packet.src == "10.152.152.150" and ip_packet.dport == 433: |
| 28 | + tcp_packet = ip_packet.getlayer('TCP') |
| 29 | + raw_payload = tcp_packet.payload |
28 | 30 | if not raw_payload:
|
29 | 31 | new_packets.append(packet)
|
30 | 32 | continue
|
|
36 | 38 | length = int.from_bytes(raw_length, 'big')
|
37 | 39 |
|
38 | 40 | base_length = len(key) + len(raw_length)
|
39 |
| - data = xor_data(tcp_payload[base_length: base_length + length], key).decode('utf-8') |
| 41 | + data = xor_data( |
| 42 | + tcp_payload[base_length: base_length + length], key).decode('utf-8') |
40 | 43 | deserialized_data = json.loads(data)
|
41 | 44 | if not re.search(flag_re, deserialized_data['Description']):
|
42 | 45 | new_packets.append(packet)
|
43 | 46 | continue
|
44 | 47 |
|
45 | 48 | deserialized_data['Description'] = args.flag
|
46 |
| - new_json = json.dumps(deserialized_data).encode() |
| 49 | + new_json = json.dumps(deserialized_data, indent=4).encode() |
47 | 50 | new_data = xor_data(new_json, key)
|
48 | 51 | new_length = xor_data(key, len(new_data).to_bytes(2, 'big'))
|
49 | 52 | new_payload = key + new_length + new_data
|
|
55 | 58 |
|
56 | 59 | raw_payload.load = new_payload
|
57 | 60 | packet['TCP'].payload = raw_payload
|
| 61 | + packet['TCP'].explicit = tcp_packet.explicit |
58 | 62 | new_packet = l2.Ether(packet.build())
|
| 63 | + new_packet['TCP'].time = tcp_packet.time |
| 64 | + new_packet.time = packet.time |
59 | 65 | new_packets.append(new_packet)
|
60 | 66 | else:
|
61 | 67 | new_packets.append(packet)
|
62 | 68 | new_plist = PacketList(new_packets)
|
63 | 69 | wrpcap(args.output, new_plist)
|
64 |
| -print(f"Dumped the modified capture to {args.output}; be sure to verify with ctf-solve.py!") |
| 70 | +print( |
| 71 | + f"Dumped the modified capture to {args.output}; be sure to verify with ctf-solve.py!") |
0 commit comments