From 3c92425126e9787b2d0cc88ce135fc053d4652bb Mon Sep 17 00:00:00 2001 From: Jordan ERNST Date: Thu, 28 Apr 2022 16:23:08 +0200 Subject: [PATCH] Replace nc.exe for a better one --- README.md | 1 + config.json | 9 +++++--- pendora-box.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 65 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ed12047..8fe048b 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ This too has several functions: ## To-Do +* Chisel * Prettier code * Only update once per day, except if `-u` `--update` * Adding more services to listen to ? diff --git a/config.json b/config.json index dbcf5d1..410bb74 100644 --- a/config.json +++ b/config.json @@ -17,9 +17,6 @@ "MS11-046/ms11-046.exe", "MS11-046/MS11_46_k8.exe", "MS10-059/MS10-059.exe" - ], - "diegocr/netcat": [ - "nc.exe" ] }, "githubreleasesync": { @@ -51,5 +48,11 @@ "ncat.exe", "ncat" ] + }, + "netcat": { + "local_version": "1.12", + "files": [ + "nc.exe" + ] } } \ No newline at end of file diff --git a/pendora-box.py b/pendora-box.py index 9dbba1b..e22a987 100644 --- a/pendora-box.py +++ b/pendora-box.py @@ -10,6 +10,8 @@ from io import BytesIO import zipfile import rpmfile import gzip +from bs4 import BeautifulSoup +import re def compute_file_hash(filepath): @@ -191,6 +193,59 @@ def ncatsync(conf): json.dump(data, jsonfile, indent=4) +def netcatsync(conf): + # https://eternallybored.org/misc/netcat/ seems to be the most stable from all tested. (04/2022) + r = requests.get('https://eternallybored.org/misc/netcat/') + soup = BeautifulSoup(r.content, 'lxml') + versions = [] + for link in soup.find_all('a', {'href': re.compile('netcat.+win.+')}): + version = link['href'].split('-')[-1].split('.zip')[0] + versions.append(version) + + last_version = max(versions) + local_version = conf['local_version'] + + for filename in conf['files']: + # nc64.exe is also available in the archive feel free to add it. + localfile = Path('files').joinpath(Path(filename).name) + print(f" * {localfile} ", end='') + + archtype = 'zip' + binpath = filename + destpath = f'files/{filename}' + urldl = f'https://eternallybored.org/misc/netcat/netcat-win32-{last_version}.zip' + + 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['netcat']['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['netcat']['local_version'] = last_version + + with open("config.json", "w") as jsonfile: + json.dump(data, jsonfile, indent=4) + + def update(config): print("Updating...") with open("credz.json", "r") as jsonfile: @@ -204,6 +259,7 @@ def update(config): githubreleasesync(reponame, repoinfo, credz) ncatsync(config['ncat']) + netcatsync(config['netcat']) make_executable() @@ -366,7 +422,8 @@ def menu_choice(menu_options): elif option == 3: listen_smb(files_dir, 2) elif option == 0: - sys.exit('Quitting') + print('Quitting') + sys.exit() else: print('Invalid option. Please enter a valid number.')