How to create a raw socket(customised TCP header) using dpkt?
i m writing a code for port scanner so i need to send a raw packet. i searched and found out that using dpkt library would be better but i didnt find any documentation that would help. So please anyone could help may explaining how to create a packet with customized TCP header i.e set the flags of tcp header as required.
开发者_运维知识库Thank You
Well, this is a bit old but I'll answer anyway since I've been looking to do the same. The dpkt documentation is basically non-existant. The only thing they give you is some samples and Jon Oberheide, the co-developer, wrote some tutorials for it. So if you want to use dpkt it isn't difficult you can figure it out from one of these tutorials:
- http://jon.oberheide.org/blog/2008/08/25/dpkt-tutorial-1-icmp-echo/
- http://jon.oberheide.org/blog/2008/12/20/dpkt-tutorial-3-dns-spoofing/
- Or, http://www.bases-hacking.org/sources/Reseau/IP%20Spoofing/rst_hijack.py as some example code I found helpful, it's well documented. There's lots more code around if you just google it.
If you want an easier API, I've used both of these:
The same guy that wrote dpkt wrote libdnet, which is used by the beastly security scanner Nmap and has python wrappings: http://libdnet.sourceforge.net/. It's got some pretty basic TCP and IP creation functions but the documentation is much better.
Or use this python wrapper for libnet, http://pylibnet.sourceforge.net/. This is very robust and the documentation is great but I couldn't get injection working on OS X. Also every release so far is still beta.
精彩评论