0

I'm trying to play with a security tool using scapy to spoof ASCII characters in a UDP checksum. I can do it, but only when I hardcode the bytes in Hex notation. But I can't convert the ASCII string word into binary notation. This works to send the bytes of He (first two chars of "Hello world"):

sr1(IP(dst=server)/UDP(dport=53, chksum=0x4865)/DNS(rd=1,qd=DNSQR(qname=query)),verbose=0)`

But whenever I try to use a variable of test2 instead of 0x4865, the DNS packet is not transmitted over the network. This should create binary for this ASCII:

test2 = bin(int(binascii.hexlify('He'),16))

sr1(IP(dst=server)/UDP(dport=53, chksum=test2)/DNS(rd=1,qd=DNSQR(qname=query)),verbose=0)

When I print test2 variable is shows correct binary notation representation.

How do I convert a string such as He so that is shows in the checksum notation accepted by scapy, of 0x4865 ??

1
>>> test
'0b100100001100101'
>>> type(test)
<type 'str'>
>>> test2
18533
>>> type(test2)
<type 'int'>

bin() returns a string. Remove the bin() to get an integer, and use that for the chksum input. The following sent out the packet correctly for me:

from binascii import hexlify
from scapy.all import *

test2 = int(hexlify('He'),16)
send(IP(dst='127.0.0.1')/UDP(dport=53, chksum=test2)/DNS(rd=1, qd=DNSQR(qname="query")),verbose=0)
  • 1
    You answered this. Thanks. I had confused the bin() at beginning. When I removed it, it returned what I needed and now works. – Robert Aug 14 '17 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.