NetExec/build_collector.py

108 lines
3.0 KiB
Python
Raw Normal View History

# -*- coding: latin-1 -*-
import os
import shutil
import subprocess
import sys
import time
import zipfile
from datetime import datetime
from pathlib import Path
from shiv.bootstrap import Environment
# from distutils.ccompiler import new_compiler
from shiv.builder import create_archive
from shiv.cli import __version__ as VERSION
def build_cme():
2021-03-08 20:14:35 +00:00
print("building CME")
2021-03-08 20:03:04 +00:00
try:
shutil.rmtree("build")
shutil.rmtree("bin")
except:
pass
try:
2021-03-08 20:14:35 +00:00
print("remove useless files")
os.mkdir("build")
2020-09-11 20:56:27 +00:00
os.mkdir("bin")
shutil.copytree("cme", "build/cme")
2021-03-08 20:03:04 +00:00
#remove useless file > 10mo
shutil.copy("cme/data/netripper/PowerShell/Invoke-NetRipper.ps1", "cme/data/")
shutil.rmtree("cme/data/netripper")
os.mkdir("cme/data/netripper/")
os.mkdir("cme/data/netripper/PowerShell/")
shutil.move("cme/data/Invoke-NetRipper.ps1", "cme/data/netripper/PowerShell/")
shutil.copy("cme/data/invoke-vnc/Invoke-Vnc.ps1", "cme/data/")
shutil.rmtree("cme/data/invoke-vnc/")
os.mkdir("cme/data/invoke-vnc/")
shutil.move("cme/data/Invoke-Vnc.ps1", "cme/data/invoke-vnc/")
shutil.rmtree("cme/data/powersploit/Recon/Dictionaries/")
shutil.rmtree("cme/data/powersploit/Exfiltration/NTFSParser/")
shutil.rmtree("cme/data/powersploit/CodeExecution/Invoke-ReflectivePEInjection_Resources/")
shutil.rmtree("cme/data/powersploit/Exfiltration/LogonUser/")
shutil.rmtree("cme/data/powersploit/Tests/")
2021-03-08 20:03:04 +00:00
except Exception as e:
print(e)
return
2020-09-20 14:51:23 +00:00
subprocess.run(
[sys.executable, "-m", "pip", "install", "-r", "requirements.txt" ,"-t", "build"],
2020-09-20 14:51:23 +00:00
check=True
)
#[shutil.rmtree(p) for p in Path("build").glob("**/__pycache__")]
[shutil.rmtree(p) for p in Path("build").glob("**/*.dist-info")]
env = Environment(
built_at=datetime.utcfromtimestamp(int(time.time())).strftime(
"%Y-%m-%d %H:%M:%S"
),
entry_point="cme.crackmapexec:main",
script=None,
compile_pyc=False,
extend_pythonpath=True,
shiv_version=VERSION,
)
create_archive(
[Path("build").absolute()],
Path("bin/cme"),
"/usr/bin/env -S python3 -sE",
"_bootstrap:bootstrap",
env,
True,
)
def build_cmedb():
2021-03-08 20:14:35 +00:00
print("building CMEDB")
env = Environment(
built_at=datetime.utcfromtimestamp(int(time.time())).strftime(
"%Y-%m-%d %H:%M:%S"
),
entry_point="cme.cmedb:main",
script=None,
compile_pyc=False,
extend_pythonpath=True,
shiv_version=VERSION,
)
create_archive(
[Path("build").absolute()],
Path("bin/cmedb"),
"/usr/bin/env -S python3 -sE",
"_bootstrap:bootstrap",
env,
True,
)
if __name__ == "__main__":
try:
build_cme()
2021-03-08 20:14:35 +00:00
build_cmedb()
except:
pass
finally:
2020-09-11 20:56:27 +00:00
shutil.rmtree("build")