-
Notifications
You must be signed in to change notification settings - Fork 461
Open
Labels
Description
Hi, so I am doing a project with CapeV2 sandbox and I have a task to add PeSieve as an auxiliary module to join the analysis process on a PID.
Currently, I am able to make PeSieve execute on the PID, now all that is left is uploading the results.
My question is: after a scan, it generates a folder (process_{pid}) with the results. I am trying in my code after the scan to locate the folder in the Windows guest and basically upload every file in it to Cape Host but currently I have no luck. Am i missing something?
import time
import os
import logging
import subprocess
from threading import Thread
from lib.common.abstracts import Auxiliary
from lib.common.results import upload_to_host
log = logging.getLogger(__name__)
class PESieve(Auxiliary, Thread):
def __init__(self, options, config):
Auxiliary.__init__(self, options, config)
Thread.__init__(self)
self.pesieve_path = "C:\\Users\\CapeUser\\Desktop\\pesieve\\pe-sieve64.exe"
self.pids = [] # List to track PIDs
def add_pid(self, pid):
"""Add a PID to the tracking list."""
if pid not in self.pids:
self.pids.append(pid)
log.info("Added PID: %s to PESieve", pid)
def del_pid(self, pid):
"""Remove a PID from the tracking list."""
if pid in self.pids:
self.pids.remove(pid)
log.info("Removed PID from PESieve")
def run(self):
log.info("Running PE-sieve on PIDs")
while True:
for pid in self.pids:
try:
# Run PE-sieve and wait for it to complete
process = subprocess.Popen([self.pesieve_path, '/pid', str(pid)], shell=False)
process.wait()
log.info("PE-sieve run on PID: %s", pid)
# Check and upload the process_<PID> folder
self.upload_process_folder(pid)
except Exception as e:
log.error(f"Failed to run PE-sieve on PID {pid}: {e}")
time.sleep(1)
def upload_process_folder(self, pid):
process_folder_path = os.path.join(os.path.dirname(self.pesieve_path), f'process_{pid}')
if os.path.exists(process_folder_path) and os.path.isdir(process_folder_path):
# Upload each file in the folder
for root, dirs, files in os.walk(process_folder_path):
for file in files:
file_path = os.path.join(root, file)
upload_to_host(file_path, os.path.join("pesieve", os.path.basename(file_path)))
log.info(f"Uploaded {os.path.basename(file_path)} for PID {pid}")
else:
log.error(f"Folder for PID {pid} not found or is not a directory")
def stop(self):
pass
``