diff --git a/genRevShell.py b/genRevShell.py index 44c8219..453c345 100755 --- a/genRevShell.py +++ b/genRevShell.py @@ -5,6 +5,7 @@ import sys import pty import util import time +import random import threading import readline import base64 @@ -137,11 +138,9 @@ if __name__ == "__main__": # choose random port if listen_port is None: - sock = util.openServer(local_address) - if not sock: - exit(1) - listen_port = sock.getsockname()[1] - sock.close() + listen_port = random.randint(10000,65535) + while util.isPortInUse(listen_port): + listen_port = random.randint(10000,65535) payload = generatePayload(payload_type, local_address, listen_port) diff --git a/util.py b/util.py index 78e2fe6..7ad255c 100755 --- a/util.py +++ b/util.py @@ -11,6 +11,12 @@ import io from PIL import Image from bs4 import BeautifulSoup +def isPortInUse(port): + import socket + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + return s.connect_ex(('127.0.0.1', port)) == 0 + + def getAddress(interface="tun0"): if not interface in ni.interfaces(): interfaces = ni.interfaces()