This commit is contained in:
Jordan ERNST 2022-04-23 16:26:56 +02:00
parent a910f30889
commit 66b9959b68
3 changed files with 89 additions and 3 deletions

View File

@ -6,6 +6,7 @@ This too has several functions:
## To-Do ## To-Do
* `chmod +x` :)
* Only update once per day, except if `-u` `--update` * Only update once per day, except if `-u` `--update`
* Adding more services to listen to ? * Adding more services to listen to ?

View File

@ -26,5 +26,12 @@
"winPEASany.exe" "winPEASany.exe"
] ]
} }
},
"ncat": {
"local_version": "7.92",
"files": [
"ncat.exe",
"ncat"
]
} }
} }

View File

@ -6,6 +6,9 @@ import base64
import sys import sys
from os import geteuid from os import geteuid
import subprocess import subprocess
from io import BytesIO
import zipfile
import rpmfile
def compute_file_hash(filepath): def compute_file_hash(filepath):
@ -32,6 +35,27 @@ def get_last_release_info(repo, credz):
return release['tag_name'] 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): def githubmastersync(reponame, filepaths, credz):
for filepath in filepaths: for filepath in filepaths:
localfile = pathlib.Path('files').joinpath(pathlib.Path(filepath).name) localfile = pathlib.Path('files').joinpath(pathlib.Path(filepath).name)
@ -81,6 +105,7 @@ def githubreleasesync(reponame, repoinfo, credz):
content = requests.get(urldl, auth=credz).content content = requests.get(urldl, auth=credz).content
with open(localfile, 'wb') as f: with open(localfile, 'wb') as f:
f.write(content) f.write(content)
print('-> Updated!')
with open("config.json", "r") as jsonfile: with open("config.json", "r") as jsonfile:
data = json.load(jsonfile) data = json.load(jsonfile)
@ -90,8 +115,58 @@ def githubreleasesync(reponame, repoinfo, credz):
with open("config.json", "w") as jsonfile: with open("config.json", "w") as jsonfile:
json.dump(data, jsonfile, indent=4) 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['ncat']['local_version'] = last_version
with open("config.json", "w") as jsonfile:
json.dump(data, jsonfile, indent=4)
print('-> Updated!') 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): def update(config):
print("Updating...") print("Updating...")
@ -105,6 +180,8 @@ def update(config):
for reponame, repoinfo in config['githubreleasesync'].items(): for reponame, repoinfo in config['githubreleasesync'].items():
githubreleasesync(reponame, repoinfo, credz) githubreleasesync(reponame, repoinfo, credz)
ncatsync(config['ncat'])
def print_menu(menu_options): def print_menu(menu_options):
for key in menu_options.keys(): for key in menu_options.keys():
@ -229,6 +306,7 @@ if __name__ == '__main__':
update(config) update(config)
print('Choose a service to start a listener:')
menu_options = { menu_options = {
1: 'HTTP', 1: 'HTTP',
2: 'SMB1', 2: 'SMB1',