-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsecam.py
More file actions
191 lines (161 loc) Β· 6.63 KB
/
insecam.py
File metadata and controls
191 lines (161 loc) Β· 6.63 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import socket
import threading
import requests
import platform
import re
import subprocess
import urllib3
import colorama
from colorama import Fore, Style
colorama.init(autoreset=True)
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
COMMON_PORTS = [80, 443, 554, 8000, 8001, 8080, 8443, 8888, 37777, 5000]
COMMON_PATHS = [
"/", "/admin", "/login", "/viewer", "/webadmin", "/video", "/stream", "/live",
"/snapshot", "/onvif-http/snapshot", "/system.ini", "/config", "/setup",
"/cgi-bin/", "/api/", "/camera", "/img/main.cgi"
]
HTTPS_PORTS = [443, 8443, 8444]
HEADERS = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '
'(KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'}
TIMEOUT = 5
PORT_SCAN_TIMEOUT = 1.5
def print_banner():
cctv_ascii = f'''
{Fore.RED} ______!fsc!_....-' .g8888888p. '-------....._
.' // .g8: :8p..---....___ \\'.
| Unnamed // () d88: :88b|==========! !|
| // 888: :888|==========| !|
|___ \\_______'T88888888888P''----------'//|
| \\ {Fore.YELLOW}""""""""""""""""""""/ |{Fore.RED}
| !...._____ .="""=. .[] ____...! |
| / ! .g$p. ! .[] : |
| ! : $$$$$ : .[] : |
| ! ! 'T$P' ! .[] '.|
| \\__ "=._.=" .() __ |
|.--' '----._______________________.----' '--.|
'._____________________________________________.{Style.RESET_ALL}'
{Fore.CYAN}InSecCam - CCTV Scanner{Style.RESET_ALL}
'''
print(cctv_ascii)
def get_default_gateway():
try:
import netifaces
gws = netifaces.gateways()
default_gw = gws.get('default')
if default_gw and netifaces.AF_INET in default_gw:
return default_gw[netifaces.AF_INET][0]
except ImportError:
print(f"{Fore.YELLOW}[!] netifaces not installed. For more robust gateway detection, run: pip install netifaces{Style.RESET_ALL}")
except Exception as e:
print(f"[!] Error detecting default gateway with netifaces: {e}")
system = platform.system().lower()
try:
if system == "windows":
output = subprocess.run("ipconfig", capture_output=True, text=True).stdout
gateways = re.findall(r"Default Gateway[ .:]*([\d\.]+)", output)
for gw in gateways:
if gw and gw != "0.0.0.0":
return gw
else:
output = subprocess.run("ip route", capture_output=True, text=True).stdout
match = re.search(r"default via ([\d\.]+)", output)
if match:
return match.group(1)
except Exception as e:
print(f"[!] Error detecting default gateway: {e}")
return None
def get_protocol(port):
return "https" if port in HTTPS_PORTS else "http"
def scan_ports(ip):
print(f"{Fore.YELLOW}[π] Scanning common CCTV ports on IP: {ip}{Style.RESET_ALL}")
open_ports = []
lock = threading.Lock()
def scan_port(port):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.settimeout(PORT_SCAN_TIMEOUT)
try:
if sock.connect_ex((ip, port)) == 0:
with lock:
open_ports.append(port)
print(f" {Fore.GREEN}β
Port {port} OPEN{Style.RESET_ALL}")
else:
print(f" {Fore.RED}β Port {port} closed{Style.RESET_ALL}")
except:
pass
threads = []
for port in COMMON_PORTS:
t = threading.Thread(target=scan_port, args=(port,))
t.daemon = True
t.start()
threads.append(t)
for t in threads:
t.join()
return sorted(open_ports)
def analyze_port(ip, port):
protocol = get_protocol(port)
base_url = f"{protocol}://{ip}:{port}"
print(f"{Fore.YELLOW}[π] Analyzing port {port} ({protocol.upper()}){Style.RESET_ALL}")
try:
resp = requests.get(base_url, headers=HEADERS, timeout=TIMEOUT, verify=False)
server = resp.headers.get('Server', 'N/A')
content_type = resp.headers.get('Content-Type', 'N/A')
status = resp.status_code
print(f" Status Code: {status}")
print(f" Server: {server}")
print(f" Content-Type: {content_type}")
text = resp.text.lower()
keywords = ['camera', 'hikvision', 'dahua', 'axis', 'surveillance', 'webcam', 'nvr', 'dvr']
found_keywords = [k for k in keywords if k in text]
if found_keywords:
print(f" π₯ CCTV Keywords found in page: {', '.join(found_keywords)}")
for path in COMMON_PATHS:
url = f"{base_url}{path}"
try:
head = requests.head(url, headers=HEADERS, timeout=TIMEOUT, verify=False)
if head.status_code in [200, 401, 403]:
print(f" {Fore.CYAN}π Found camera endpoint: {url} (HTTP {head.status_code}){Style.RESET_ALL}")
except:
continue
if status == 401:
auth = resp.headers.get('WWW-Authenticate', 'N/A')
print(f" π Authentication required: {auth}")
except requests.RequestException as e:
print(f" β Request error: {e}")
def check_login_pages(ip, open_ports):
print(f"{Fore.YELLOW}[π] Checking for login/auth pages on {ip}{Style.RESET_ALL}")
def check_path(port, path):
protocol = get_protocol(port)
url = f"{protocol}://{ip}:{port}{path}"
try:
r = requests.get(url, headers=HEADERS, timeout=TIMEOUT, verify=False)
if r.status_code in [200, 401, 403]:
print(f" {Fore.MAGENTA}π Login page found: {url} (HTTP {r.status_code}){Style.RESET_ALL}")
return True
except:
return False
return False
found_any = False
for port in open_ports:
for path in COMMON_PATHS:
if check_path(port, path):
found_any = True
if not found_any:
print(f" {Fore.RED}β No login pages detected{Style.RESET_ALL}")
def main():
print_banner()
print("=== InSecCam CCTV Scanner ===")
gw_ip = get_default_gateway()
if not gw_ip:
print("[!] Could not detect default gateway IP. You can manually specify target IP in the code.")
return
print(f"[*] Default gateway IP detected: {gw_ip}")
open_ports = scan_ports(gw_ip)
if not open_ports:
print("[!] No open CCTV-related ports found on gateway.")
return
for port in open_ports:
analyze_port(gw_ip, port)
check_login_pages(gw_ip, open_ports)
if __name__ == "__main__":
main()