Click to See Complete Forum and Search --> : network programming with libnet


netranger
July 19th, 2007, 02:48 AM
Hello all readers,
For a student practice i started to learning Libnet since i heard it is all about
raw IP programming. my project is a simple link dropper which placed in a gateway and drop TCP sessions which matches my criteria.
Any help? jumpstart or clue?

Cheers!

rzcodeman
July 19th, 2007, 05:15 AM
Programming with libnet is very simple and straightforward.
The below codes will send a single ip/ icmp packet over the net:


char errbuf[LIBNET_ERRBUF_SIZE];

libnet_t *l; // Libnet context buffer. you always init at-least one of them in this library.
char *device = NULL; // In this case we select default network card to put in use
char *dst = "192.168.100.1"; // Suppose it is ip address of the server
char *src = "192.168.100.100";

u_long src_ip = 0, dst_ip = 0;
libnet_ptag_t t;
char *payload = NULL; // we have no payload
u_short payload_s = 0;



l = libnet_init(
LIBNET_RAW4, /* injection type */
device, /* network interface */
errbuf); /* errbuf */

dst_ip = libnet_name2addr4(l, pDst, LIBNET_RESOLVE); // Resolve dst ip address to a network byte ordered IPv4 address
src_ip = libnet_name2addr4(l, pSrc, LIBNET_RESOLVE);

t = libnet_build_icmpv4_echo(
ICMP_ECHO, /* type */
0, /* code */
0, /* checksum */
0x42, /* id */
0x42, /* sequence number */
NULL, /* payload */
0, /* payload size */
l, /* libnet handle */
0);

t = libnet_build_ipv4(
LIBNET_IPV4_H + LIBNET_ICMPV4_ECHO_H + payload_s, /* length */
0, /* TOS */
0x42, /* IP ID */
0, /* IP Frag */
64, /* TTL */
IPPROTO_ICMP, /* protocol */
0, /* checksum */
src_ip, /* source IP */
dst_ip, /* destination IP */
payload, /* payload */
payload_s, /* payload size */
l, /* libnet handle */
0);


libnet_write(l); // put the packet on the wire
libnet_destroy(l); // destroy the context buffer


Also you may take a look at the link below for a tutorial about libnet:
netwrok programmin with libnet (http://www.packetforum.org/forums/showthread.php?p=80#post80)

netranger
July 19th, 2007, 05:25 AM
Thanks alot,
btw do you have a working code?
i tried to compile libnet but encountered some problems...

rzcodeman
July 20th, 2007, 04:24 AM
Take a look at libnetnt (www.securitybugware.org/libnetnt/) for a ready to use Libnet API for windows NT.

rzcodeman
July 24th, 2007, 05:31 AM
Also here a nice blog regarding network programming.
low level network programming (http://lowlevelnetworkprogramming.blogspot.com/)
network security attacks and exploits (http://networksecurityprogramming.blogspot.com/)
http://www.codeproject.com/useritems/HTTPFilter.asp
(http://www.codeproject.com/useritems/HTTPFilter.asp)