Unable to send ICMP packets from a raw socket in Python -
i have raw python socket initialized so:
mysocket = socket.socket(socket.af_inet, socket.sock_raw, socket.ipproto_raw) mysocket.setsockopt(socket.ipproto_ip, socket.ip_hdrincl, 1)
my problem can't send packet socket protocol field in ip header specified '1' (icmp). if field else it'll work fine, including '17' (udp) example. don't errors, packet doesn't display in wireshark, , can't receive on server.
i'm generating ip header so:
def getipheader(src, dst, proto): version = 4 ihl = 5 dscp = 0 ecn = 0 totallength = 40 identification = 333 flags = 0 fragmentoffset = 0 timetolive = 128 protocol = proto headerchecksum = 0 sourceip = socket.inet_aton(src) destip = socket.inet_aton(dst) options = 0 version_ihl = (version << 4) | ihl dscp_ecn = (dscp << 2) | ecn flags_fragmentoffset = (flags << 13) | fragmentoffset # '!' ensures arguments converted network byte order header = struct.pack("!bbhhhbbh4s4s", version_ihl, dscp_ecn, totallength, identification, flags_fragmentoffset, timetolive, protocol, headerchecksum, sourceip, destip) return header
and sending so:
icmpheader = struct.pack("!bbhhh", 8, 0, 0, 666, 0) packet = getipheader("192.168.2.15", "8.8.8.8", 1) + icmpheader mysocket.sendto(packet, ("8.8.8.8", 0))
sending udp protocol set works (obviously malformed):
icmpheader = struct.pack("!bbhhh", 8, 0, 0, 666, 0) packet = getipheader("192.168.2.15", "8.8.8.8", 17) + icmpheader mysocket.sendto(packet, ("8.8.8.8", 0))
the worst part if send ping command line, copy exact hex wireshark of ip , icmp data code, still doesn't work, so:
packet = b'\x45\x00\x00\x3c\x24\xad\x00\x00\x80\x01\x43\x4d\xc0\xa8\x02\x0f\x08\x08\x08\x08\x08\x00\x4d\x44\x00\x01\x00\x17\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x61\x62\x63\x64\x65\x66\x67\x68\x69' mysocket.sendto(packet, ("8.8.8.8", 0))
however, before, if change 10th byte of hard coded data '\x11' (17 decimal, udp), can see in wireshark (obviously malformed udp section rest of packet icmp).
i'm running windows 10, python 3.4.1, , firewall off. ideas?
update: i've tried on 2 different computers, windows 8 , windows 10 machine, both worked, it's computer, plot thickens...
Comments
Post a Comment