-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipe_program_ping3.py
More file actions
32 lines (25 loc) · 818 Bytes
/
pipe_program_ping3.py
File metadata and controls
32 lines (25 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
from scapy.all import *
from SocatAdapter3 import SocatParser, socat_format
parser_obj = SocatParser()
while True:
byte = sys.stdin.buffer.read(1)
ret = parser_obj.addByte(ord(byte))
if ret is not None:
sys.stderr.write("Rx: {}\n".format(ret.summary()))
if ret.haslayer(ICMP):
#Generate the reply
reply_pkt = ret.copy()
reply_pkt[IP].src = ret[IP].dst
reply_pkt[IP].dst = ret[IP].src
reply_pkt[ICMP].type = 0
#Force a checksum recalculation
del reply_pkt[IP].chksum
del reply_pkt[ICMP].chksum
reply_pkt = reply_pkt.__class__(bytes(reply_pkt))
sys.stderr.write("Tx: {}\n".format(reply_pkt.summary()))
#Send it over to Socat
sys.stdout.buffer.write(socat_format(reply_pkt))
sys.stdout.buffer.flush()