forked from aancw/spose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spose.py
74 lines (63 loc) · 2.9 KB
/
spose.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
import sys
import argparse
import urllib.request
from colorama import Fore, Style, init
# Initialize colorama for color support
init(autoreset=True)
class Spose:
def __init__(self):
parser = argparse.ArgumentParser(
add_help=True,
description='Squid Pivoting Open Port Scanner'
)
parser.add_argument("--proxy", help="Define proxy address URL (http://x.x.x.x:3128)",
action="store", dest='proxy', required=True)
parser.add_argument("--target", help="Define target IP behind proxy",
action="store", dest='target', required=True)
parser.add_argument("--ports", help="[Optional] Define target ports behind proxy (comma-separated)",
action="store", dest='ports')
parser.add_argument("--allports", help="[Optional] Scan all 65535 TCP ports behind proxy",
action="store_true", dest='allports')
if len(sys.argv) == 1:
parser.print_help()
sys.exit(1)
options = parser.parse_args()
target = options.target
proxy = options.proxy
# Determine the list of ports to scan
if options.allports:
ports = range(1, 65536) # All TCP ports
print(f"{Fore.YELLOW}Scanning all 65,535 TCP ports{Style.RESET_ALL}")
elif options.ports:
ports = [int(port.strip()) for port in options.ports.split(",")]
print(f"{Fore.YELLOW}Scanning specified ports: {options.ports}{Style.RESET_ALL}")
else:
ports = [21, 22, 23, 25, 53, 69, 80, 109, 110, 123, 137, 138, 139, 143, 156, 389, 443,
546, 547, 995, 993, 2086, 2087, 2082, 2083, 3306, 8080, 8443, 10000]
print(f"{Fore.YELLOW}Scanning default common ports{Style.RESET_ALL}")
print(f"{Fore.CYAN}Using proxy address {proxy}{Style.RESET_ALL}")
# Set up proxy
proxy_handler = urllib.request.ProxyHandler({'http': proxy})
opener = urllib.request.build_opener(proxy_handler)
urllib.request.install_opener(opener)
# Scan the ports
for port in ports:
try:
url = f"http://{target}:{port}"
with urllib.request.urlopen(url) as response:
code = response.getcode()
if code in [200, 404, 401]:
print(f"{Fore.GREEN}{target}:{port} seems OPEN{Style.RESET_ALL}")
except urllib.error.HTTPError as e:
# Suppress output for HTTP errors
if e.code in [503]:
continue
except urllib.error.URLError:
# Suppress output for URL errors
continue
except Exception:
# Suppress output for all other exceptions
continue
if __name__ == "__main__":
Spose()