poc: psutil for process watcher

This commit is contained in:
Zamitto 2024-07-01 20:23:39 -03:00
parent 9870213fff
commit 0c1a75eedd
2 changed files with 12 additions and 0 deletions

View File

@ -3,3 +3,4 @@ cx_Freeze
cx_Logging; sys_platform == 'win32' cx_Logging; sys_platform == 'win32'
lief; sys_platform == 'win32' lief; sys_platform == 'win32'
pywin32; sys_platform == 'win32' pywin32; sys_platform == 'win32'
psutil

View File

@ -2,7 +2,9 @@ import sys
from http.server import HTTPServer, BaseHTTPRequestHandler from http.server import HTTPServer, BaseHTTPRequestHandler
import json import json
import urllib.parse import urllib.parse
import psutil
from downloader import Downloader from downloader import Downloader
from time import time
torrent_port = sys.argv[1] torrent_port = sys.argv[1]
http_port = sys.argv[2] http_port = sys.argv[2]
@ -34,6 +36,15 @@ class Handler(BaseHTTPRequestHandler):
self.send_response(200) self.send_response(200)
self.end_headers() self.end_headers()
if self.path == "/process":
start_time = time()
process_path = set([proc.info["exe"] for proc in psutil.process_iter(['exe'])])
self.send_response(200)
self.send_header("Content-type", "application/json")
self.end_headers()
self.wfile.write(json.dumps(list(process_path)).encode('utf-8'))
print(time() - start_time)
def do_POST(self): def do_POST(self):
if self.path == "/action": if self.path == "/action":
if self.headers.get(self.rpc_password_header) != rpc_password: if self.headers.get(self.rpc_password_header) != rpc_password: