{"id":840,"date":"2013-06-24T15:38:50","date_gmt":"2013-06-24T15:38:50","guid":{"rendered":"https:\/\/trouble.org\/?p=840"},"modified":"2013-06-24T18:26:46","modified_gmt":"2013-06-24T18:26:46","slug":"shotgun-scanning","status":"publish","type":"post","link":"https:\/\/trouble.org\/?p=840","title":{"rendered":"shotgun scanning"},"content":{"rendered":"<p>UDP scanning has always been slow. Slower than slow, slower than molasses, really fucking slow.<\/p>\n<p><a href=\"http:\/\/blog.surveymonkey.com\/wp-content\/uploads\/2012\/04\/shotgun20barrel.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.surveymonkey.com\/wp-content\/uploads\/2012\/04\/shotgun20barrel.jpg\" width=\"202\" height=\"298\" class=\"alignright\" \/><\/a><\/p>\n<p>So when I started being interested in scanning for IPMI out in the wild, which runs on UDP 623, I first fired up trusty ol&#8217; nmap&#8230; but bless it&#8217;s heart, it&#8217;s a cautious, robust scanner that is outrun by crippled snails on UDP scanning.<\/p>\n<p>So I\u00a0thought\u2026 well, most scans don&#8217;t really need a request-response-follow-up\u2026 so\u2026 well, I can just forge the requesting address\u2026 spread out collectors\u2026 then receive it in one location. \u00a0Then I thought\u2026 why am I writing a receiver? \u00a0I&#8217;ll just run tcpdump on the receiving end, and process that\u2026 and that also gives all the packets and data, not just what I think of parsing out at the time.<\/p>\n<p>I wrote my &#8220;scanner&#8221; (not sure what to call it, more like a shotgun, it doesn&#8217;t really receive any data ;))\u00a0in perl, of course (below.) \u00a0I was playing with the speeds and delays &#8211; scanning a \/8 or A CIDR block in 5-10 mins for a single UDP port A is pretty simple, but I never really know if I&#8217;m missing traffic &#8211; so many systems, so little time, are all the packets really working?<\/p>\n<p>This might be an old technique or discredited or something&#8230; nothing is new under the sun, after all.  But it worked for me. And it&#8217;s really, really simple, because it&#8217;s all the connection details and grabbing and parsing responses, and queuing up all the scans&#8230; that takes a fair bit of code &#8211; this is just a few for loops and bam.<\/p>\n<p>And it sure beat the alternatives I knew about, at least, which is scanning for a year or so to do the same you can do in a day. \u00a0It&#8217;d be interesting to do a few nets simultaneously to see if any methods or speeds were better than others. \u00a0But for now&#8230;.<\/p>\n<div class=\"codecolorer-container perl blackboard\" style=\"overflow:auto;white-space:nowrap;height:800px;\"><div class=\"perl codecolorer\"><span class=\"co1\">#!\/usr\/bin\/env perl<\/span><br \/>\n<br \/>\n<span class=\"kw2\">use<\/span> Try<span class=\"sy0\">::<\/span><span class=\"me2\">Tiny<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"kw2\">use<\/span> Net<span class=\"sy0\">::<\/span><span class=\"me2\">RawIP<\/span><span class=\"sy0\">;<\/span><br \/>\n<br \/>\n<span class=\"re0\">$src<\/span> <span class=\"sy0\">=<\/span> <span class=\"re0\">$ARGV<\/span><span class=\"br0\">&#91;<\/span><span class=\"nu0\">0<\/span><span class=\"br0\">&#93;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"re0\">$dst<\/span> <span class=\"sy0\">=<\/span> <span class=\"re0\">$ARGV<\/span><span class=\"br0\">&#91;<\/span><span class=\"nu0\">1<\/span><span class=\"br0\">&#93;<\/span><span class=\"sy0\">;<\/span><br \/>\n<br \/>\n<a href=\"http:\/\/perldoc.perl.org\/functions\/die.html\"><span class=\"kw3\">die<\/span><\/a> <span class=\"st0\">&quot;Usage: $0 (faux?)source-IP (real)dest-class-A<span class=\"es0\">\\n<\/span>&quot;<\/span> <span class=\"kw1\">unless<\/span> <span class=\"re0\">$src<\/span> <span class=\"sy0\">!=<\/span> <span class=\"st0\">&quot;&quot;<\/span> <span class=\"sy0\">&amp;&amp;<\/span> <span class=\"re0\">$dst<\/span> <span class=\"sy0\">!=<\/span> <span class=\"st0\">&quot;&quot;<\/span><span class=\"sy0\">;<\/span><br \/>\n<br \/>\n<span class=\"co1\"># take a breather for delay seconds<\/span><br \/>\n<span class=\"re0\">$NET_MOD<\/span> <span class=\"sy0\">=<\/span> <span class=\"nu0\">90<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"re0\">$DELAY<\/span> &nbsp; <span class=\"sy0\">=<\/span> <span class=\"nu0\">15<\/span><span class=\"sy0\">;<\/span><br \/>\n<br \/>\n<span class=\"re0\">$src_port<\/span> <span class=\"sy0\">=<\/span> <span class=\"nu0\">623<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"re0\">$dst_port<\/span> <span class=\"sy0\">=<\/span> <span class=\"nu0\">623<\/span><span class=\"sy0\">;<\/span><br \/>\n<br \/>\n<span class=\"re0\">$torpackedo<\/span> <span class=\"sy0\">=<\/span> <span class=\"st0\">&quot;<span class=\"es0\">\\x<\/span>06<span class=\"es0\">\\x<\/span>00<span class=\"es0\">\\x<\/span>ff<span class=\"es0\">\\x<\/span>07<span class=\"es0\">\\x<\/span>00<span class=\"es0\">\\x<\/span>00<span class=\"es0\">\\x<\/span>00<span class=\"es0\">\\x<\/span>00<span class=\"es0\">\\x<\/span>00<span class=\"es0\">\\x<\/span>00<span class=\"es0\">\\x<\/span>00<span class=\"es0\">\\x<\/span>00<span class=\"es0\">\\x<\/span>00<span class=\"es0\">\\x<\/span>09<span class=\"es0\">\\x<\/span>20<span class=\"es0\">\\x<\/span>18<span class=\"es0\">\\x<\/span>c8<span class=\"es0\">\\x<\/span>81<span class=\"es0\">\\x<\/span>00<span class=\"es0\">\\x<\/span>38<span class=\"es0\">\\x<\/span>8e<span class=\"es0\">\\x<\/span>04<span class=\"es0\">\\x<\/span>b5&quot;<\/span><span class=\"sy0\">;<\/span><br \/>\n<br \/>\n<span class=\"re0\">$new_socket<\/span> <span class=\"sy0\">=<\/span> <span class=\"kw2\">new<\/span> Net<span class=\"sy0\">::<\/span><span class=\"me2\">RawIP<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#123;<\/span>udp <span class=\"sy0\">=&gt;<\/span><span class=\"br0\">&#123;<\/span><span class=\"br0\">&#125;<\/span><span class=\"br0\">&#125;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<br \/>\n<span class=\"co1\"># do an \/8<\/span><br \/>\n<span class=\"kw1\">for<\/span> <span class=\"re0\">$two<\/span> <span class=\"br0\">&#40;<\/span><span class=\"nu0\">0<\/span><span class=\"sy0\">..<\/span><span class=\"nu0\">255<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp;<span class=\"re0\">$dest<\/span> <span class=\"sy0\">=<\/span> <span class=\"st0\">&quot;$dst.$two&quot;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp;<a href=\"http:\/\/perldoc.perl.org\/functions\/print.html\"><span class=\"kw3\">print<\/span><\/a> <span class=\"st0\">&quot;loading up the network torpedos for $dest<span class=\"es0\">\\n<\/span>&quot;<\/span><span class=\"sy0\">;<\/span><br \/>\n<br \/>\n&nbsp; &nbsp;<span class=\"kw1\">for<\/span> <span class=\"re0\">$three<\/span> <span class=\"br0\">&#40;<\/span><span class=\"nu0\">0<\/span><span class=\"sy0\">..<\/span><span class=\"nu0\">255<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; <span class=\"re0\">$dest<\/span> <span class=\"sy0\">=<\/span> <span class=\"st0\">&quot;$dst.$two.$three&quot;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; <a href=\"http:\/\/perldoc.perl.org\/functions\/print.html\"><span class=\"kw3\">print<\/span><\/a> <span class=\"st0\">&quot;<span class=\"es0\">\\t<\/span>clearing torpedo tubes &amp; decks for $dest<span class=\"es0\">\\n<\/span>&quot;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp;<br \/>\n&nbsp; &nbsp; &nbsp; <span class=\"co1\"># do a \/24<\/span><br \/>\n&nbsp; &nbsp; &nbsp; <span class=\"kw1\">for<\/span> <span class=\"re0\">$four<\/span> <span class=\"br0\">&#40;<\/span><span class=\"nu0\">0<\/span><span class=\"sy0\">..<\/span><span class=\"nu0\">255<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class=\"re0\">$dest<\/span> <span class=\"sy0\">=<\/span> <span class=\"st0\">&quot;$dst.$two.$three.$four&quot;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class=\"co1\"># print &quot;\\tpew pew =&gt; $dest\\n&quot;;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class=\"re0\">$new_socket<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">set<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ip &nbsp;<span class=\"sy0\">=&gt;<\/span> <span class=\"br0\">&#123;<\/span>saddr &nbsp;<span class=\"sy0\">=&gt;<\/span> <span class=\"re0\">$src<\/span><span class=\"sy0\">,<\/span> daddr <span class=\"sy0\">=&gt;<\/span> <span class=\"re0\">$dest<\/span><span class=\"br0\">&#125;<\/span><span class=\"sy0\">,<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; udp <span class=\"sy0\">=&gt;<\/span> <span class=\"br0\">&#123;<\/span>source <span class=\"sy0\">=&gt;<\/span> <span class=\"re0\">$src_port<\/span><span class=\"sy0\">,<\/span> dest &nbsp;<span class=\"sy0\">=&gt;<\/span> <span class=\"re0\">$dst_port<\/span><span class=\"sy0\">,<\/span> data <span class=\"sy0\">=&gt;<\/span> <span class=\"re0\">$torpackedo<\/span> <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class=\"br0\">&#125;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re0\">$new_socket<\/span><span class=\"sy0\">-&gt;<\/span><a href=\"http:\/\/perldoc.perl.org\/functions\/send.html\"><span class=\"kw3\">send<\/span><\/a><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class=\"br0\">&#125;<\/span> catch <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\"># warn &quot;couldn't send packet to $dest (Error: $_)\\n&quot;;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class=\"br0\">&#125;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp;<br \/>\n&nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp;<br \/>\n<span class=\"co1\"># &nbsp; &nbsp; if ($three &gt; 0 &amp;&amp; !($three % $NET_MOD)) {<\/span><br \/>\n<span class=\"co1\"># &nbsp; &nbsp; &nbsp; &nbsp;print &quot;\\n...breathing for a few seconds...\\n&quot;;<\/span><br \/>\n<span class=\"co1\"># &nbsp; &nbsp; &nbsp; &nbsp;sleep($NET_MOD);<\/span><br \/>\n<span class=\"co1\"># &nbsp; &nbsp; }<\/span><br \/>\n&nbsp; &nbsp;<span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp;<a href=\"http:\/\/perldoc.perl.org\/functions\/print.html\"><span class=\"kw3\">print<\/span><\/a> <span class=\"st0\">&quot;<span class=\"es0\">\\n<\/span>...mopping the blood off the decks, hold on $DELAY seconds<span class=\"es0\">\\n<\/span><span class=\"es0\">\\n<\/span>&quot;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp;<a href=\"http:\/\/perldoc.perl.org\/functions\/sleep.html\"><span class=\"kw3\">sleep<\/span><\/a><span class=\"br0\">&#40;<\/span><span class=\"re0\">$DELAY<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>UDP scanning has always been slow. Slower than slow, slower than molasses, really fucking slow. So when I started being interested in scanning for IPMI out in the wild, which runs on UDP 623, I first fired up trusty ol&#8217; nmap&#8230; but bless it&#8217;s heart, it&#8217;s a cautious, robust scanner that is outrun by crippled [&hellip;]<\/p>\n","protected":false},"author":44,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[96,146,154,46,19],"tags":[222,223,221,185,224,220],"class_list":["post-840","post","type-post","status-publish","format-standard","hentry","category-art","category-hack","category-ipmi-2","category-perl","category-philosophy","tag-222","tag-buck-shot","tag-mossberg","tag-network","tag-scanning","tag-shogun"],"_links":{"self":[{"href":"https:\/\/trouble.org\/index.php?rest_route=\/wp\/v2\/posts\/840","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/trouble.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/trouble.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/trouble.org\/index.php?rest_route=\/wp\/v2\/users\/44"}],"replies":[{"embeddable":true,"href":"https:\/\/trouble.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=840"}],"version-history":[{"count":6,"href":"https:\/\/trouble.org\/index.php?rest_route=\/wp\/v2\/posts\/840\/revisions"}],"predecessor-version":[{"id":846,"href":"https:\/\/trouble.org\/index.php?rest_route=\/wp\/v2\/posts\/840\/revisions\/846"}],"wp:attachment":[{"href":"https:\/\/trouble.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=840"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/trouble.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=840"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/trouble.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}