From 66b9959b6881c4e0ece2f37d4310ef2e34893a73 Mon Sep 17 00:00:00 2001 From: Jordan ERNST Date: Sat, 23 Apr 2022 16:26:56 +0200 Subject: [PATCH] Add ncat --- README.md | 1 + config.json | 7 +++++ pendora-box.py | 84 ++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 89 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bae5cbf..63cb498 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ This too has several functions: ## To-Do +* `chmod +x` :) * Only update once per day, except if `-u` `--update` * Adding more services to listen to ? diff --git a/config.json b/config.json index 13afaae..ae5cf17 100644 --- a/config.json +++ b/config.json @@ -26,5 +26,12 @@ "winPEASany.exe" ] } + }, + "ncat": { + "local_version": "7.92", + "files": [ + "ncat.exe", + "ncat" + ] } } \ No newline at end of file diff --git a/pendora-box.py b/pendora-box.py index ed27909..34c6e72 100644 --- a/pendora-box.py +++ b/pendora-box.py @@ -6,6 +6,9 @@ import base64 import sys from os import geteuid import subprocess +from io import BytesIO +import zipfile +import rpmfile def compute_file_hash(filepath): @@ -32,6 +35,27 @@ def get_last_release_info(repo, credz): return release['tag_name'] +def extract_bin(archtype, binpath, destpath, content): + ioobj = BytesIO(content) # Get a File object from bytes ;) + + if archtype == 'zip': + with zipfile.ZipFile(ioobj, "r") as zf: + filenames = zf.namelist() + for fn in filenames: + if binpath in fn: + with open(destpath, 'wb') as f: + f.write(zf.read(fn)) + break + elif archtype == 'rpm': + with rpmfile.RPMFile(fileobj=ioobj) as rpm: + # Extract a fileobject from the archive + fd = rpm.extractfile(binpath) + + with open(destpath, 'wb') as f: + f.write(fd.read()) + ioobj.close() + + def githubmastersync(reponame, filepaths, credz): for filepath in filepaths: localfile = pathlib.Path('files').joinpath(pathlib.Path(filepath).name) @@ -81,17 +105,68 @@ def githubreleasesync(reponame, repoinfo, credz): content = requests.get(urldl, auth=credz).content with open(localfile, 'wb') as f: f.write(content) + print('-> Updated!') + + with open("config.json", "r") as jsonfile: + data = json.load(jsonfile) + + data['githubreleasesync'][reponame]['local_version'] = last_version + + with open("config.json", "w") as jsonfile: + json.dump(data, jsonfile, indent=4) + + +def ncatsync(conf): + r = requests.get('https://nmap.org/dist/') + last_version = r.text.split('The latest Nmap release is version ')[1].split('.\n')[0] + local_version = conf['local_version'] + + for filename in conf['files']: + localfile = pathlib.Path('files').joinpath(pathlib.Path(filename).name) + print(f" * {localfile} ", end='') + + if filename == "ncat.exe": + archtype = 'zip' + binpath = 'ncat.exe' + destpath = 'files/ncat.exe' + urldl = f'https://nmap.org/dist/nmap-{last_version}-win32.zip' + + elif filename == "ncat": + archtype = 'rpm' + binpath = './usr/bin/ncat' + destpath = 'files/ncat' + urldl = f'https://nmap.org/dist/ncat-{last_version}-1.x86_64.rpm' + + if not localfile.exists(): + content = requests.get(urldl).content + extract_bin(archtype, binpath, destpath, content) + + print('-> Installed! ;)') + else: + if local_version == last_version: + print('-> Up-to-date.') + + else: + content = requests.get(urldl).content + extract_bin(archtype, binpath, destpath, content) with open("config.json", "r") as jsonfile: data = json.load(jsonfile) - data['githubreleasesync'][reponame]['local_version'] = last_version + data['ncat']['local_version'] = last_version with open("config.json", "w") as jsonfile: json.dump(data, jsonfile, indent=4) - print('-> Updated!') + with open("config.json", "r") as jsonfile: + data = json.load(jsonfile) + + data['ncat']['local_version'] = last_version + + with open("config.json", "w") as jsonfile: + json.dump(data, jsonfile, indent=4) + def update(config): print("Updating...") @@ -105,6 +180,8 @@ def update(config): for reponame, repoinfo in config['githubreleasesync'].items(): githubreleasesync(reponame, repoinfo, credz) + ncatsync(config['ncat']) + def print_menu(menu_options): for key in menu_options.keys(): @@ -158,7 +235,7 @@ def listen_smb(files_dir, version): print(f' -> {iname}: \\\\{ips[iname]}\\share\\winPEASany.exe') else: print(f' -> {iname}: \\\\{ips[iname]}:{port}\\share\\winPEASany.exe # This syntax (:port) is not supported on Windows ?') - + if version == 1: cmd = ['smbserver.py', '-port', str(port), 'share', files_dir] elif version == 2: @@ -229,6 +306,7 @@ if __name__ == '__main__': update(config) + print('Choose a service to start a listener:') menu_options = { 1: 'HTTP', 2: 'SMB1',