20.01.2014 Views

Lectures notes for 2010 - KTH

Lectures notes for 2010 - KTH

Lectures notes for 2010 - KTH

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Building a UDP packet from scratch<br />

/* simple example of building a UDP packet from scratch, based on the program:<br />

PingPong - 970621 by Willy TARREAU <br />

http://www.insecure.org/sploits/inetd.internal_udp_ports.DOS.attack.html<br />

As this program uses RAW sockets, you must be root to run it<br />

*/<br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

struct sockaddr addrfrom;<br />

struct sockaddr addrto;<br />

int s;<br />

u_char outpack[65536];<br />

struct iphdr *ip;<br />

struct udphdr *udp;<br />

main(int argc, char **argv) {<br />

struct sockaddr_in *from;<br />

struct sockaddr_in *to;<br />

struct protoent *proto;<br />

int i;<br />

char *src,*dest;<br />

int srcp, destp;<br />

int packetsize,datasize;<br />

if (argc!=5) {fprintf(stderr,"Usage: %s src_addr src_port dst_addr dst_port\n", argv[0]);<br />

fprintf(stderr,"src_addr and dst_addr must be given as IP addresses (xxx.xxx.xxx.xxx)\n");<br />

exit(2);}<br />

src=argv[1]; srcp=atoi(argv[2]); dest=argv[3]; destp=atoi(argv[4]);<br />

Maguire Building a UDP packet from scratch 4: 24 of 74<br />

maguire@kth.se <strong>2010</strong>.03.21 Internetworking/Internetteknik

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!