News for hackers. Stuff that matters.
Re:LulzSec's 3-line PHP Portscan by pak on Friday June 24, 2011 @11:34AM (#2692568)
Meh. Neither are particularly inspiring. Yeah, thejester's is pedantically long and uses way too many variables, while lulzsec seems to have an aversion to variables, running ip2long($argv[1]) up to three times per loop.

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.

Re:LulzSec's 3-line PHP Portscan by trotsky on Friday June 24, 2011 @12:09PM (#2692719)
Thank you, all the best from the superior coders at Lulz Security.

Why the ____ do the normally mindful folks at HN vote this kind of thing up?

Re:LulzSec's 3-line PHP Portscan by colonelxc on Friday June 24, 2011 @12:28PM (#2692812)
I am just as confused as you. Any coder here should be able to whip up an equivalent script in their language of choice in a few minutes.

Obviously, the popularity of lulzsec is the main factor here.

Re:LulzSec's 3-line PHP Portscan by middus on Friday June 24, 2011 @11:00AM (#2692460)
This does not really scan ports, it just looks for a web server on a bunch of IP addresses. In doing so, it only checks port 80.
Re:LulzSec's 3-line PHP Portscan by mrspeaker on Friday June 24, 2011 @11:06AM (#2692486)
That's why they call it a portscanner, not a portsscanner ;)
Re:LulzSec's 3-line PHP Portscan by PawelDecowski on Friday June 24, 2011 @11:25AM (#2692541)
What's with the weird for loop?

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));
Re:LulzSec's 3-line PHP Portscan by pak on Friday June 24, 2011 @11:36AM (#2692575)
I think you meant

           if (strpos(@file_get_contents('http://'.long2ip($c), false, stream_context_create(array('http’ => array('timeout’ => $argv[3])))), $argv[4]) !== false)
Re:LulzSec's 3-line PHP Portscan by PawelDecowski on Friday June 24, 2011 @11:39AM (#2692591)
Well spotted.

I forgot to replace it on line 2, only did it on line 3.

Re:LulzSec's 3-line PHP Portscan by zbanks on Friday June 24, 2011 @11:38AM (#2692585)
Your code has a bug on line 2.

@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.

Re:LulzSec's 3-line PHP Portscan by PawelDecowski on Friday June 24, 2011 @11:40AM (#2692594)
Yeah, I missed it. Thanks for spotting.
Re:LulzSec's 3-line PHP Portscan by woodall on Friday June 24, 2011 @12:08PM (#2692713)
The Jester's version really isn't that bad once you remove all the echos and variable assignments; which I kind of like(readability).

http://pastebin.com/wpv1RXta

Re:LulzSec's 3-line PHP Portscan by taylorbuley on Friday June 24, 2011 @11:09AM (#2692495)
I wonder how many times a day Pastebin gets Fed requests for their access logs
Re:LulzSec's 3-line PHP Portscan by IgorPartola on Friday June 24, 2011 @11:33AM (#2692561)
Doesn't this:

>> 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?

Re:LulzSec's 3-line PHP Portscan by pak on Friday June 24, 2011 @11:39AM (#2692589)
Yes, but I believe their intent was to rewrite the other script as it functioned, not for it to be any more effective.
Re:LulzSec's 3-line PHP Portscan by IgorPartola on Friday June 24, 2011 @11:47AM (#2692611)
I suppose. I wonder what would be a better way to find their web server. Maybe looking for IPs that run a web server using nginx, but don't respond to the host specified in their rDNS record. Then again, that would lead to way too many hosts.
Re:LulzSec's 3-line PHP Portscan by getsat on Friday June 24, 2011 @12:07PM (#2692708)
I doubt they'll set up a PTR record. What they'd do if they're smart is firewall their box so it only accepts port 80 requests from Cloudflare's systems. Anything else can be discarded, e.g.:

  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 ACCEPT
Re:LulzSec's 3-line PHP Portscan by IgorPartola on Friday June 24, 2011 @12:21PM (#2692777)
Probably. There are a lot of hosting/VPS companies out there that have instant provisioning and don't ask too many questions. I imagine it would be pretty hard to find them this way unless they do something stupid.
Re:LulzSec's 3-line PHP Portscan by JackWebbHeller on Friday June 24, 2011 @10:35AM (#2692368)
You'll find it at the bottom, but Portscan script alone: http://pastebin.com/KFyFaDmz
Re:LulzSec's 3-line PHP Portscan by cjzhang on Friday June 24, 2011 @12:36PM (#2692845)
lulzier hunter - by bottle_of_rum

So, who's bottle_of_rum, then?

Re:LulzSec's 3-line PHP Portscan by jasonmoo on Friday June 24, 2011 @11:44AM (#2692603)
Creative and adept use of php is always a fun read.
Re:LulzSec's 3-line PHP Portscan by Ruudjah on Friday June 24, 2011 @11:04AM (#2692475)
> Presenting LULZIERhunter.php, taking what Jester wrote in 60 lines and turning it into 3 lines:

Epic failure, implicating LOC is a measurement for code quality. Hint: it's not.

Re:LulzSec's 3-line PHP Portscan by rbxbx on Friday June 24, 2011 @11:38AM (#2692586)
Right, but that's generally in reference to more LoC > less LoC.

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)

Re:LulzSec's 3-line PHP Portscan by thirsteh on Friday June 24, 2011 @11:12AM (#2692505)
3 lines is usually better than 60 lines. See Python.
Re:LulzSec's 3-line PHP Portscan by getsat on Friday June 24, 2011 @11:51AM (#2692634)
I'm really surprised that The Jester can't code that well. LulzSec is just mocking him publicly (again).

Edit: http://twitter.com/LulzSec/status/84223058382028800