LulzSec's 3-line PHP Portscan
pastebin.com
pastebin.com
Also, the "lulzier" version does not separately handle the case where a webserver is found but does not return a response containing the needle. It's true that thejester's script is not particularly efficient in wasting a socket connect to do this separate check, but for a one-off task, who cares.
Why the ____ do the normally mindful folks at HN vote this kind of thing up?
Obviously, the popularity of lulzsec is the main factor here.
Why not just:
for ($c = ip2long($argv[1]); $c <= ip2long($argv[2]); $c++)
if (strpos(@file_get_contents('http://'.long2ip(ip2long($argv[1])+$c), false, stream_context_create(array('http’ => array('timeout’ => $argv[3])))), $argv[4]) !== false)
die('H4xed :D — '.long2ip($c)); if (strpos(@file_get_contents('http://'.long2ip($c), false, stream_context_create(array('http’ => array('timeout’ => $argv[3])))), $argv[4]) !== false)I forgot to replace it on line 2, only did it on line 3.
@file_get_contents('http://.long2ip(ip2long($argv[1])+$c)
Since $c is the IP address itself, adding the starting IP again will check a completely different IP.
Besides that, you have a point. I feel like the code would be so much cleaner if they just added a 4th line to declare ip2long($argv[1]) as a variable.
>> also, in our nginx configuration, we deny all HTTP connections to unknown vhosts.
mean that forming the URL as 'http://.long2ip(ip2long($argv[1])+$c) will not work?
iptables -A INPUT DROP
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -s w.x.y.z/xx -j ACCEPTSo, who's bottle_of_rum, then?
Epic failure, implicating LOC is a measurement for code quality. Hint: it's not.
It's usually agreed that accomplishing the same thing in less lines of code is, of course, better. (As long as you've maintained readability, etc)