From ffd06cb3b92bda75ba6100342df9f916923a7c7f Mon Sep 17 00:00:00 2001 From: Alessandro ZANNI Date: Thu, 3 Nov 2016 22:38:07 +0100 Subject: [PATCH 1/2] possibility to choose timeout and thread number --- pupy/packages/all/portscan.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pupy/packages/all/portscan.py b/pupy/packages/all/portscan.py index 647b7c7b..c632c975 100644 --- a/pupy/packages/all/portscan.py +++ b/pupy/packages/all/portscan.py @@ -8,16 +8,17 @@ open_port = [] class WorkerThread(threading.Thread) : - def __init__(self, queue, tid, remote_ip, ports) : + def __init__(self, queue, tid, remote_ip, ports, settimeout) : threading.Thread.__init__(self) self.queue = queue self.tid = tid self.ports = ports self.remote_ip = remote_ip + self.timeout = settimeout def check_open_port(self, port): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - sock.settimeout(4) + sock.settimeout(self.timeout) result = sock.connect_ex((self.remote_ip, port)) if result == 0: sock.close() @@ -32,13 +33,12 @@ class WorkerThread(threading.Thread) : self.check_open_port(port) self.queue.task_done() -def scan(remote_ip, ports): +def scan(remote_ip, ports, nb_threads, settimeout): queue = Queue.Queue() threads = [] - # 10 threads - for i in range(1, 11): - worker = WorkerThread(queue, i, remote_ip, ports) + for i in range(1, nb_threads): + worker = WorkerThread(queue, i, remote_ip, ports, settimeout) worker.setDaemon(True) worker.start() threads.append(worker) From 81057247bd0fe523c2eeb1c332374d2af7bd3e4b Mon Sep 17 00:00:00 2001 From: Alessandro ZANNI Date: Thu, 3 Nov 2016 22:38:43 +0100 Subject: [PATCH 2/2] timeout and thread number added --- pupy/modules/port_scan.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pupy/modules/port_scan.py b/pupy/modules/port_scan.py index d33efbd9..7c862915 100644 --- a/pupy/modules/port_scan.py +++ b/pupy/modules/port_scan.py @@ -16,7 +16,8 @@ class PortScan(PupyModule): def init_argparse(self): self.arg_parser = PupyArgumentParser(prog="port_scan", description=self.__doc__) self.arg_parser.add_argument('--ports','-p', default="21,22,23,80,139,443,445,3389,7001,8000,8080", help='ports to scan ex: 22,80,443') - self.arg_parser.add_argument('--timeout','-t', default="2", help='timeout (default: %(default)s)') + self.arg_parser.add_argument('--timeout', default=4, help='timeout (default: %(default)s)') + self.arg_parser.add_argument('--threads', default=10, help='number of threads (default: %(default)s)') self.arg_parser.add_argument('target', metavar="ip/range", help='IP/range') def run(self, args): @@ -31,7 +32,7 @@ class PortScan(PupyModule): self.success("Scanning remote host: %s" % host) t1 = datetime.now() - open_ports = self.client.conn.modules['portscan'].scan(host, ports) + open_ports = self.client.conn.modules['portscan'].scan(host, ports, args.threads, args.timeout) if open_ports: self.log('PORT STATE') for p in open_ports: