Last active
November 29, 2018 20:34
-
-
Save andreferraro/1017f8d5e717c5c16a0ca61fff4218d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$url = "http://applicant-test.us-east-1.elasticbeanstalk.com/"; | |
$sessionId = ""; | |
$token = ""; | |
$inverseToken = ""; | |
$replacements = array( | |
"a" => "z", "b" => "y", "c" => "x", "d" => "w", "e" => "v", "f" => "u", "g" => "t", | |
"h" => "s", "i" => "r", "j" => "q", "k" => "p", "l" => "o", "m" => "n", "n" => "m", | |
"o" => "l", "p" => "k", "q" => "j", "r" => "i", "s" => "h", "t" => "g", "u" => "f", | |
"v" => "e", "w" => "d", "x" => "c", "y" => "b", "z" => "a" | |
); | |
echo "Acessando " . $url . "\n"; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_VERBOSE, 0); | |
curl_setopt($ch, CURLOPT_HEADER, 1); | |
$response = curl_exec($ch); | |
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); | |
$header = substr($response, 0, $header_size); | |
$body = substr($response, $header_size); | |
$arr = explode("\n", $header); | |
for($i = 0; $i < count($arr); $i++ ) { | |
if ( strpos($arr[$i], "PHPSESSID") > -1 ) { | |
// Set-Cookie: PHPSESSID=f8fr5bd6vd57g73prge6q5bc4n; path=/ | |
$sessionId = preg_replace("/.*PHPSESSID=([^;]*);.*/", "\\1", $arr[$i]); | |
} | |
} | |
$arr = explode("\n", $body); | |
for($i = 0; $i < count($arr); $i++ ) { | |
if ( strpos($arr[$i], "token") > -1 ) { | |
// <input type="hidden" name="token" id="token" value="wz52827915w9932w2ww3z49xx16v0v1w" /> | |
$token = preg_replace("/.*value=\"([^;]*)\".*/", "\\1", $arr[$i]); | |
} | |
} | |
$split_token = str_split($token); | |
for ($x = 0; $x < strlen($token); $x++) { | |
if ( floatval($split_token[$x]) != 0 ) { | |
$inverseToken .= $split_token[$x]; | |
} else { | |
$inverseToken .= $split_token[$x] == "0" ? "0" : array_search($split_token[$x], $replacements); | |
} | |
} | |
echo "TOKEN: " . $token . "\n"; | |
echo "TOKEN INVERTIDO: " . $inverseToken . "\n"; | |
echo "PHPSESSID: " . $sessionId . "\n"; | |
echo "Enviando clique...\n"; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, "token=" . $inverseToken); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded')); | |
$strCookie = 'PHPSESSID=' . $sessionId . '; path=/'; | |
curl_setopt( $ch, CURLOPT_COOKIE, $strCookie ); //We set our session in the headers of the request! | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_REFERER, $url); | |
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Origin: ' . $url)); | |
$output = curl_exec ($ch); | |
curl_close ($ch); | |
// RESPOSTA: <span id="answer">93</span> | |
$resposta = preg_replace("/.*>([^;]*)<.*/", "\\1", $output); | |
echo "RESPOSTA: " . $resposta . "\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment