rst and fin
时间:2010-05-14 来源:空灵静世
/*
* main.c
*
* Created on: 2010-5-13
* Author: root
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <libnet.h>
int main(int argc ,char *argv[]){
int packet_size;
libnet_t *l;
libnet_ptag_t tcp_protocol_tag = 0;
libnet_ptag_t ip_protocol_tag = 0;
// libnet_ptag_t ethreal_protocol_tag = 0;
// u_short protocol=IPPROTO_TCP;
u_short srcport = (u_short)atoi(argv[1]);
u_short destport = 22;
// u_char payload[255] = "";
// u_long payload_size = 0;
char *device ="lo";
char error_infomation[LIBNET_ERRBUF_SIZE];
char *destination_ip_str = "127.0.0.1";
char *source_ip_str = "127.0.0.1";
// u_char hardware_source[6] = {0x01,0x02,0x03,0x04,0x05,0x07};
// u_char hardware_destination[6] = {0/*0x00,0x22,0x64,0xAA,0x76,0xE1*/};
u_long destination_ip ;
u_long source_ip;
char seq1[10]={0};
char seq2[10]={0};
char ack1[10]={0};
char ack2[10]={0};
strncpy(seq1,argv[2],strlen(argv[2])-1);
strncpy(seq2,argv[2]+strlen(argv[2])-1,1);
strncpy(ack1,argv[3],strlen(argv[3])-1);
strncpy(ack2,argv[3]+strlen(argv[3])-1,1);
u_int32_t seq = ((u_int32_t)atoi(seq1))*10 + (u_int32_t)atoi(seq2);
u_int32_t ack = ((u_int32_t)atoi(ack1))*10+ (u_int32_t)atoi(ack2);
l = libnet_init(LIBNET_RAW4,device,error_infomation);
destination_ip = libnet_name2addr4(l,destination_ip_str,LIBNET_DONT_RESOLVE);
source_ip = libnet_name2addr4(l,source_ip_str,LIBNET_DONT_RESOLVE);
tcp_protocol_tag = libnet_build_tcp(srcport,destport,seq,ack,TH_RST,32000,0,0,LIBNET_TCP_H,NULL,0,l,tcp_protocol_tag);
ip_protocol_tag = libnet_build_ipv4(LIBNET_IPV4_H+LIBNET_TCP_H,/*IPTOS_LOWDELAY*/0,12345,
0,64,IPPROTO_TCP,0,source_ip,destination_ip,NULL,0,
l,ip_protocol_tag);
packet_size = libnet_write(l);
tcp_protocol_tag = libnet_build_tcp(destport,srcport,ack,seq,TH_RST,32000,0,0,LIBNET_TCP_H,NULL,0,l,tcp_protocol_tag);
ip_protocol_tag = libnet_build_ipv4(LIBNET_IPV4_H+LIBNET_TCP_H,/*IPTOS_LOWDELAY*/0,12345,
0,64,IPPROTO_TCP,0,source_ip,destination_ip,NULL,0,
l,ip_protocol_tag);
packet_size = libnet_write(l);
libnet_destroy(l);
return 0;
}
注意:如果是RST,那么它的序列号的最小值为数据包的最后一个序列号+1或则握手包序列号+2(还没有数据包)
如果是FIN,那么它的序列号的值为数据包的最后一个序列号或则握手包序列号+1(还没有数据包)
* main.c
*
* Created on: 2010-5-13
* Author: root
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <libnet.h>
int main(int argc ,char *argv[]){
int packet_size;
libnet_t *l;
libnet_ptag_t tcp_protocol_tag = 0;
libnet_ptag_t ip_protocol_tag = 0;
// libnet_ptag_t ethreal_protocol_tag = 0;
// u_short protocol=IPPROTO_TCP;
u_short srcport = (u_short)atoi(argv[1]);
u_short destport = 22;
// u_char payload[255] = "";
// u_long payload_size = 0;
char *device ="lo";
char error_infomation[LIBNET_ERRBUF_SIZE];
char *destination_ip_str = "127.0.0.1";
char *source_ip_str = "127.0.0.1";
// u_char hardware_source[6] = {0x01,0x02,0x03,0x04,0x05,0x07};
// u_char hardware_destination[6] = {0/*0x00,0x22,0x64,0xAA,0x76,0xE1*/};
u_long destination_ip ;
u_long source_ip;
char seq1[10]={0};
char seq2[10]={0};
char ack1[10]={0};
char ack2[10]={0};
strncpy(seq1,argv[2],strlen(argv[2])-1);
strncpy(seq2,argv[2]+strlen(argv[2])-1,1);
strncpy(ack1,argv[3],strlen(argv[3])-1);
strncpy(ack2,argv[3]+strlen(argv[3])-1,1);
u_int32_t seq = ((u_int32_t)atoi(seq1))*10 + (u_int32_t)atoi(seq2);
u_int32_t ack = ((u_int32_t)atoi(ack1))*10+ (u_int32_t)atoi(ack2);
l = libnet_init(LIBNET_RAW4,device,error_infomation);
destination_ip = libnet_name2addr4(l,destination_ip_str,LIBNET_DONT_RESOLVE);
source_ip = libnet_name2addr4(l,source_ip_str,LIBNET_DONT_RESOLVE);
tcp_protocol_tag = libnet_build_tcp(srcport,destport,seq,ack,TH_RST,32000,0,0,LIBNET_TCP_H,NULL,0,l,tcp_protocol_tag);
ip_protocol_tag = libnet_build_ipv4(LIBNET_IPV4_H+LIBNET_TCP_H,/*IPTOS_LOWDELAY*/0,12345,
0,64,IPPROTO_TCP,0,source_ip,destination_ip,NULL,0,
l,ip_protocol_tag);
packet_size = libnet_write(l);
tcp_protocol_tag = libnet_build_tcp(destport,srcport,ack,seq,TH_RST,32000,0,0,LIBNET_TCP_H,NULL,0,l,tcp_protocol_tag);
ip_protocol_tag = libnet_build_ipv4(LIBNET_IPV4_H+LIBNET_TCP_H,/*IPTOS_LOWDELAY*/0,12345,
0,64,IPPROTO_TCP,0,source_ip,destination_ip,NULL,0,
l,ip_protocol_tag);
packet_size = libnet_write(l);
libnet_destroy(l);
return 0;
}
注意:如果是RST,那么它的序列号的最小值为数据包的最后一个序列号+1或则握手包序列号+2(还没有数据包)
如果是FIN,那么它的序列号的值为数据包的最后一个序列号或则握手包序列号+1(还没有数据包)
相关阅读 更多 +