def build(): try: os.mkdir("app") shutil.copytree("backend", "app/backend") except: shutil.rmtree("app") shutil.copytree("backend", "app/backend") shutil.copy("app.py", "app/main.py") subprocess.check_call( [sys.executable, "-m", "pip", "install", ".", "-t", "app"], stdout=sys.stdout, stderr=subprocess.STDOUT, ) [shutil.rmtree(p) for p in Path("app").glob("**/__pycache__")] [shutil.rmtree(p) for p in Path("app").glob("**/*.dist-info")] env = Environment( built_at=datetime.utcfromtimestamp(int( time.time())).strftime("%Y-%m-%d %H:%M:%S"), entry_point="main:main", script=None, compile_pyc=False, extend_pythonpath=False, shiv_version=VERSION, ) create_archive( [Path("app").absolute()], Path(PYZ_NAME), "/usr/bin/python3 -IS", "_bootstrap:bootstrap", env, True, )
def build(): try: os.mkdir("app") shutil.copytree("../stormspotter/ingestor", "app/stormspotter/ingestor") except: shutil.rmtree("app") shutil.copytree("../stormspotter", "app/stormspotter") shutil.copy("../stormspotter.py", "app/main.py") pip.main(["install", "-r", "requirements-ingestor.txt", "-t", "app"]) [shutil.rmtree(p) for p in Path("app").glob("**/__pycache__")] [shutil.rmtree(p) for p in Path("app").glob("**/*.dist-info")] for pem in Path("../stormspotter/ingestor/certs").glob("*.pem"): with open(pem, 'rb') as infile: customca = infile.read() with open("app/certifi/cacert.pem", 'ab') as outfile: outfile.write(customca) env = Environment( built_at=datetime.utcfromtimestamp(int( time.time())).strftime("%Y-%m-%d %H:%M:%S"), entry_point="main:main", script=None, compile_pyc=False, extend_pythonpath=False, shiv_version=VERSION, ) create_archive([Path("app").absolute()], Path("ingestor.pyz").expanduser(), "/usr/bin/env python3", "_bootstrap:bootstrap", env, True)
def test_archive_permissions(self, sp): with tempfile.TemporaryDirectory() as tmpdir: target = Path(tmpdir, 'test.zip') create_archive(sp, target, validate_interpreter(None), 'code:interact') assert target.stat().st_mode & UGOX == UGOX
def test_create_archive(self, sp): with tempfile.TemporaryDirectory() as tmpdir: target = Path(tmpdir, 'test.zip') create_archive(sp, target, validate_interpreter(None), 'code:interact') assert zipfile.is_zipfile(str(target)) with pytest.raises(ZipAppError): create_archive(sp, target, validate_interpreter(None), 'alsjdbas,,,')
def build_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, )
def build_cme(): print("building CME") try: shutil.rmtree("build") shutil.rmtree("bin") except: pass try: print("remove useless files") os.mkdir("build") os.mkdir("bin") shutil.copytree("cme", "build/cme") except Exception as e: print(e) return subprocess.run([ sys.executable, "-m", "pip", "install", "-r", "requirements.txt", "-t", "build" ], 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(): try: os.mkdir("app") shutil.copytree("stormcollector", "app/stormcollector") except: shutil.rmtree("app") shutil.copytree("stormcollector", "app/stormcollector") shutil.copy("sscollector.py", "app/main.py") subprocess.check_call( [sys.executable, "-m", "pip", "install", ".", "-t", "app"], stdout=sys.stdout, stderr=subprocess.STDOUT, ) [shutil.rmtree(p) for p in Path("app").glob("**/__pycache__")] [shutil.rmtree(p) for p in Path("app").glob("**/*.dist-info")] for pem in Path("certs").glob("*.pem"): with open(pem, "rb") as infile: customca = infile.read() with open("app/certifi/cacert.pem", "ab") as outfile: outfile.write(customca) env = Environment( built_at=datetime.utcfromtimestamp(int(time.time())).strftime( "%Y-%m-%d %H:%M:%S" ), entry_point="main:main", script=None, compile_pyc=False, extend_pythonpath=False, shiv_version=VERSION, ) create_archive( [Path("app").absolute()], Path(PYZ_NAME), "/usr/bin/env python3", "_bootstrap:bootstrap", env, True, )
def test_create_archive(self, sp): with tempfile.TemporaryDirectory() as tmpdir: target = Path(tmpdir, "test.zip") # create an archive create_archive(sp, target, sys.executable, "code:interact") # create one again (to ensure we overwrite) create_archive(sp, target, sys.executable, "code:interact") assert zipfile.is_zipfile(str(target)) with pytest.raises(ZipAppError): create_archive(sp, target, sys.executable, "alsjdbas,,,")
def test_archive_permissions(self, sp): with tempfile.TemporaryDirectory() as tmpdir: target = Path(tmpdir, "test.zip") create_archive(sp, target, sys.executable, "code:interact") assert target.stat().st_mode & UGOX == UGOX
def build_cme(): print("building CME") try: shutil.rmtree("build") shutil.rmtree("bin") except: pass try: print("remove useless files") os.mkdir("build") os.mkdir("bin") shutil.copytree("cme", "build/cme") #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/") except Exception as e: print(e) return subprocess.run([ sys.executable, "-m", "pip", "install", "-r", "requirements.txt", "-t", "build" ], 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, )