Click to See Complete Forum and Search --> : Simple raw socket tutorial
CrowbarOfDeath
10-18-2001, 08:16 PM
I kinda want to learn about raw socket programming, but have been unable to find a simple tutorial on the subject. Does anyone know where I could find the source for a simple program that sends out a single SYN packet and possibly another which can catch a single SYN/ACK packet. I want to fool around and make my own packet sniffer, so anything on that would be helpful as well.
-Thanks
MrNewbie
10-18-2001, 08:23 PM
This may, or may not, be what you want: http://www.ecst.csuchico.edu/~beej/guide/net/
pinoy
10-18-2001, 08:48 PM
Any site that publishes TCP exploits will have some source code (eg rootshell).
If you know sockets then raw sockets are relatively straight forward. It's been a long time since I've done one, but basically you have to build up your own TCP header and optionally the IP header (depends if you've got the IP_HDRINCL option set). So I'd suggest studying the format of the TCP header first then learning how to calculate the checksums etc. Sending an ACK/SYN is a matter of setting bits on this header and the proper sequence/ack number.
As for reading the TCP packets, you can't do that with raw sockets. You have to use libpcap, the packets are filtered by the TCP stack.
jemfinch
10-18-2001, 11:48 PM
You may want to check out the "libpcap" library, if you're more interested in
writing the software than learning from it.
Jeremy
Qubit
10-19-2001, 03:06 PM
Try this: www.whitefang.com/rin (http://www.whitefang.com/rin)
pinoy
10-19-2001, 05:07 PM
Originally posted by jemfinch:
<STRONG>You may want to check out the "libpcap" library, if you're more interested in
writing the software than learning from it.
Jeremy</STRONG>
Like I said, if you only want to write packets, using raw socket is the easy way.
socket(AF_INET, SOCK_RAW, protocol);
But if you want to read TCP/UDP packets you'll have to use "libpcap".
Piix4
10-19-2001, 07:17 PM
hmm you might want to look at some of my lame stuff
members.tripod.co.uk/mekanoid
mmccue
10-26-2001, 01:02 PM
beej's tutorial is great (see link above)... you might also want to look into Richard Stevens' Unix Network Programming 2nd Edition Volume 1, book if you want to get involved with it. Linux Programming Bible, IIRC, has a network programming chapter as well that is decent.
Mike