-
-
Save andrewmackrodt/6b0f4e9a6760def990d3 to your computer and use it in GitHub Desktop.
This file contains 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 | |
$sleep_time_sec = 2; | |
$list_of_sp = array(); | |
$allow_auto_post = true; | |
while (true) { | |
$start = microtime(true); | |
$body = get_page('http://ps20.software.eu.playstation.com'); | |
preg_match('/<script[^>]*>.*?config\.sp\s*=\s*([^;]+);/s', $body, $matches); | |
if (isset($matches[1])) { | |
$sp = json_decode($matches[1]); | |
if (false === array_key_exists($sp, $list_of_sp)) { | |
$redirect_url = "http://ps20.software.eu.playstation.com/redirect.php?sp=$sp"; | |
$claim_url = get_page($redirect_url); | |
// paste into console in browser at 'ps20.software.eu.playstation.com' to preserve http referrer | |
echo "jQuery('<a href=\"$claim_url\">Claim</a>').appendTo(document.body)[0].click();\n"; | |
if ($allow_auto_post) { | |
$claim_html = get_page($claim_url, array(CURLOPT_REFERER => 'http://ps20.software.eu.playstation.com/')); | |
if (1 === preg_match('/name=(?:"emailAddress"|\'emailAddress\')/s', $claim_html)) { | |
$post_result_html = post_page( | |
$claim_url, | |
array( | |
'firstName' => '', | |
'lastName' => '', | |
'addressLine' => '', | |
'addressTown' => '', | |
'Country' => 'UK', | |
'postCode' => '', | |
'emailAddress' => '', | |
'phoneNumber' => '', | |
'submit1994' => 'Submit' | |
), | |
array( | |
CURLOPT_REFERER => $claim_url | |
)); | |
// form submission result checking not implemented | |
$tempnam = tempnam(sys_get_temp_dir(), 'ps20'); | |
file_put_contents($tempnam, $post_result_html); | |
echo "\n$tempnam\n"; | |
$list_of_sp[$sp] = $claim_url; | |
} else { | |
trigger_error('Failed to fetch the submission form', E_USER_WARNING); | |
} | |
} | |
echo "\n"; | |
} | |
} | |
else { | |
trigger_error('Failed to locate the "sp" value', E_USER_WARNING); | |
} | |
$elapsed_sec = microtime(true) - $start; | |
if (($sleep_time_us = 1000000.0 * ($sleep_time_sec - $elapsed_sec)) > 0) { | |
usleep($sleep_time_us); | |
} | |
} | |
//region functions | |
function ch($url, array $opts = array()) { | |
$parsed_url = parse_url($url); | |
$scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] : ''; | |
switch ($scheme) { | |
case 'ftp': | |
case 'https': | |
break; | |
default: | |
$scheme = 'http'; | |
} | |
$ip_address = lookup_ip_address($parsed_url['host']); | |
$modified_url = array( | |
'scheme' => "$scheme://", | |
'host' => $ip_address) | |
+ $parsed_url; | |
if (isset($modified_url['query'])) $modified_url['query'] = "?{$modified_url['query']}"; | |
if (isset($modified_url['fragment'])) $modified_url['fragment'] = "#{$modified_url['fragment']}"; | |
$modified_url = implode('', array_values($modified_url)); | |
$ch = curl_init($modified_url); | |
curl_setopt_array( | |
$ch, | |
$opts + array( | |
CURLOPT_AUTOREFERER => false, | |
CURLOPT_FOLLOWLOCATION => false, | |
CURLOPT_HTTPHEADER => array("Host: {$parsed_url['host']}"), | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_SSL_VERIFYHOST => false, | |
CURLOPT_TIMEOUT => 60, | |
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0' | |
)); | |
return $ch; | |
} | |
function get_page($url, array $opts = array()) { | |
$ch = ch($url, $opts); | |
$body = curl_exec($ch); | |
$info = curl_getinfo($ch); | |
if (false === $body || 200 !== $info['http_code']) { | |
trigger_error('Failed to retrieve the page', E_USER_WARNING); | |
} | |
return $body; | |
} | |
function lookup_ip_address($url) { | |
static $dns_cache = array(); | |
$parsed_url = parse_url($url); | |
$host = isset($parsed_url['host']) ? $parsed_url['host'] : $url; | |
if (false === array_key_exists($host, $dns_cache)) { | |
$ip_address = rtrim(shell_exec(sprintf( | |
"nslookup %s 8.8.8.8 | tail -n2 | head -n1 | awk '{print $2};'", | |
escapeshellarg($host) | |
))); | |
if (false === filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { | |
throw new \Exception("Failed to lookup the hostname for url '$url''"); | |
} | |
$dns_cache[$host] = $ip_address; | |
} | |
else { | |
$ip_address = $dns_cache[$host]; | |
} | |
return $ip_address; | |
} | |
function post_page($url, $data = null, array $opts = array()) { | |
if (is_array($data)) { | |
$data = http_build_query($data); | |
} | |
$ch = ch($url, array( // override any post fields existing in curlopts | |
CURLOPT_POST => true, | |
CURLOPT_POSTFIELDS => $data | |
) + $opts); | |
$body = curl_exec($ch); | |
$info = curl_getinfo($ch); | |
if (false === $body || 200 !== $info['http_code']) { | |
trigger_error('Failed to retrieve the page', E_USER_WARNING); | |
} | |
return $body; | |
} | |
//endregion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment