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
* `chmod +x` :)
* Only update once per day, except if `-u` `--update`
* Adding more services to listen to ?

View File

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

View File

@ -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',