Anasayfa / Cyber Security / Detect Phishing Attacks with Free Open‑Source Tools: A Step‑by‑Step Guide

Detect Phishing Attacks with Free Open‑Source Tools: A Step‑by‑Step Guide

phishing detection

Phishing remains one of the most common ways cyber‑criminals infiltrate organizations. While commercial solutions are powerful, a well‑crafted toolbox of open‑source utilities can give you comparable visibility without breaking the budget. In this guide we’ll walk through everything you need to set up, configure, and run a practical phishing‑detection pipeline—from email analysis to network traffic inspection—using free tools you can install on a modest Linux server.

What You’ll Need

  • A fresh Ubuntu 22.04 LTS (or similar Debian‑based) server with at least 2 GB RAM.
  • Root or sudo access.
  • Internet connectivity for package downloads and API calls.
  • Basic familiarity with the Linux command line.
  • An email account (or a test mailbox) to feed samples into the system.

Step 1: Prepare Your Environment

Start by updating the OS and installing essential utilities. Open a terminal and run:

sudo apt update && sudo apt upgrade -y
sudo apt install -y git curl wget python3-pip build-essential libssl-dev libffi-dev python3-venv

Creating a dedicated user for the detection stack keeps permissions tidy:

sudo adduser --system --group phishdetector
sudo mkdir -p /opt/phishdetector && sudo chown phishdetector:phishdetector /opt/phishdetector

All subsequent installations will live under /opt/phishdetector.

Step 2: Pull in PhishTank’s Community Feed

PhishTank provides a public CSV of reported phishing URLs. We’ll download it daily and feed it to our URL‑checking scripts.

# Switch to the service user
sudo -u phishdetector -i
cd /opt/phishdetector
mkdir phishtank && cd phishtank
python3 -m venv venv
source venv/bin/activate
pip install pandas requests

# Create a simple fetch script (fetch_phishtank.py)
cat > fetch_phishtank.py <<'EOF'
import csv, requests, os, datetime
url = 'https://data.phishtank.com/data/online-valid.csv'
resp = requests.get(url, timeout=30)
resp.raise_for_status()
path = f'phish_{datetime.date.today()}.csv'
with open(path, 'wb') as f:
    f.write(resp.content)
print('Saved', path)
EOF

# Test the script
python fetch_phishtank.py
EOF

Schedule it with cron to run each night at 02:00 AM:

crontab -e
# Add line:
0 2 * * * /opt/phishdetector/phishtank/venv/bin/python /opt/phishdetector/phishtank/fetch_phishtank.py >> /var/log/phishtank.log 2>&1

Step 3: Install and Configure SpamAssassin

SpamAssassin is a battle‑tested email filter that includes phishing heuristics. Install it and enable the phish_check plugin.

sudo apt install -y spamassassin spamc
sudo systemctl enable spamassassin && sudo systemctl start spamassassin

# Enable the plugin
sudo sed -i 's/^#loadplugin Mail::SpamAssassin::Plugin::PhishCheck/loadplugin Mail::SpamAssassin::Plugin::PhishCheck/' /etc/spamassassin/local.cf

# Point it at the PhishTank CSV (we’ll use a wrapper script later)
sudo echo 'phish_check_path /opt/phishdetector/phishtank/phish_$(date +%F).csv' >> /etc/spamassassin/local.cf

sudo systemctl restart spamassassin

Test with a known phishing email (saved as sample.eml):

spamassassin -t < sample.eml

Look for a “PHISHING” tag in the output.

Step 4: Deploy YARA Rules for Payload Inspection

YARA excels at matching patterns in files and attachments. Clone a community‑maintained phishing rule set and compile it.

sudo apt install -y yara
mkdir -p /opt/phishdetector/yara && cd /opt/phishdetector/yara
git clone https://github.com/Neo23x0/signature-base.git
# Use only the phishing rules
cat signature-base/yara/phishing.yar > phishing_rules.yar

yara -w phishing_rules.yar /path/to/attachment.pdf && echo "Match? $?
"

Integrate YARA into the email pipeline by adding a simple wrapper to spamc:

cat > /usr/local/bin/spamc-yara < "$TMP"
# Run YARA on any attachments (assume MIME parts are extracted elsewhere)
yara -r /opt/phishdetector/yara/phishing_rules.yar "$TMP" >/dev/null 2>&1 && echo "X-Yara-Phish: Yes" || echo "X-Yara-Phish: No"
# Pass the original mail to spamc
cat "$TMP" | spamc
rm -f "$TMP"
EOF
sudo chmod +x /usr/local/bin/spamc-yara

# Update your MTA (e.g., Postfix) to use the wrapper
sudo postconf -e 'content_filter = spamc-yara'
sudo systemctl restart postfix

Step 5: Monitor Network Traffic with Zeek

Zeek (formerly Bro) can spot malicious URLs in real‑time network flows. Install it and enable the intel framework to cross‑reference the PhishTank feed.

sudo apt install -y zeek
sudo mkdir -p /opt/phishdetector/zeek && sudo chown $(whoami):$(whoami) /opt/phishdetector/zeek

# Create an intel file that Zeek will read
cat > /opt/phishdetector/zeek/phishing.intel <> /opt/phishdetector/zeek/phishing.intel <> /opt/phishdetector/zeek/local.zeek
echo "redef Intel::read_files += { "/opt/phishdetector/zeek/phishing.intel" };" >> /opt/phishdetector/zeek/local.zeek

# Start Zeek on the primary interface (replace eth0 if needed)
sudo zeekctl deploy

# View alerts
sudo zeekctl status

Whenever a user browses to a known phishing URL, Zeek will log an intel_notice entry, which you can forward to a SIEM or email.

Step 6: Centralise Indicators with MISP

MISP (Malware Information Sharing Platform) is an open‑source threat‑intel hub. We’ll use it to store PhishTank URLs, YARA hits, and Zeek alerts, giving you a single dashboard.

# Quick install via Docker (recommended for testing)
sudo apt install -y docker.io docker-compose
mkdir -p /opt/phishdetector/misp && cd /opt/phishdetector/misp
cat > docker-compose.yml <<'EOF'
version: '3'
services:
  misp:
    image: harvarditsecurity/misp
    ports:
      - "8080:80"
    environment:
      - MYSQL_ROOT_PASSWORD=misp_root
      - [email protected]
      - MISP_ADMIN_PWD=ChangeMe123
    volumes:
      - ./data:/var/www/MISP/app/files
EOF

docker-compose up -d

# After the container is up, log in at http://your‑server:8080
# Create an API key (Settings → API → Add new key)
# Then push PhishTank data via the API (example using curl)
API_KEY=YOUR_API_KEY
CSV=/opt/phishdetector/phishtank/phish_$(date +%F).csv
while IFS=, read -r id url ...; do
  curl -X POST "http://localhost:8080/events/add" 
    -H "Authorization: $API_KEY" 
    -F "request=add" 
    -F "info=PhishTank URL" 
    -F "attribute[0][type]=url" 
    -F "attribute[0][value]=$url" 
    -F "attribute[0][category]=Network activity" 
    -F "attribute[0][to_ids]=true"
done < <(tail -n +2 "$CSV")

Now any new Zeek or YARA alert can be automatically posted to MISP via a small webhook script.

Step 7: Automate End‑to‑End Alerting

Combine everything with a lightweight orchestrator like cron or systemd timers. Below is a sample systemd service that runs nightly, updates all feeds, and sends a summary email.

# /etc/systemd/system/phish‑update.service
[Unit]
Description=Update phishing detection feeds and push to MISP
After=network.target

[Service]
Type=oneshot
User=phishdetector
ExecStart=/opt/phishdetector/automation/update_all.sh

# /opt/phishdetector/automation/update_all.sh
#!/bin/bash
set -e
source /opt/phishdetector/phishtank/venv/bin/activate
python /opt/phishdetector/phishtank/fetch_phishtank.py
# (re‑run SpamAssassin config reload, Zeek intel reload, MISP push – omitted for brevity)
mail -s "Phishing feeds refreshed $(date +%F)" [email protected] << /etc/systemd/system/phish‑update.timer <<'EOF'
[Unit]
Description=Run phish‑update daily at 02:15

[Timer]
OnCalendar=*-*-* 02:15:00
Persistent=true

[Install]
WantedBy=timers.target
EOF

systemctl daemon-reload
systemctl enable --now phish‑update.timer

With this in place you have a self‑sustaining detection pipeline that ingests community feeds, inspects email and network traffic, and surfaces actionable intel in one place.

Common Mistakes to Avoid

1. Skipping feed updates. Phishing URLs have a short lifespan. Automate the download; a manual pull will leave you blind to new attacks.
2. Running SpamAssassin as root. It needs only limited privileges; using a dedicated user prevents accidental system compromise.
3. Ignoring false positives. YARA rules can be overly broad. Test them on benign samples before deployment.
4. Not normalising URLs. PhishTank may list http://example.com while the user visits https://example.com/. Use a URL‑normalisation library (e.g., Python’s urllib.parse) when matching.
5. Overloading Zeek. Running Zeek on a high‑traffic interface without proper hardware can cause packet loss. Consider sampling or a dedicated tap for critical segments.

Tips and Tricks

• Combine multiple intel sources (OpenPhish, URLhaus) for redundancy.
• Use fail2ban to block repeated phishing source IPs detected by Zeek.
• Export MISP events to STIX2 format for integration with modern SIEMs.
• Schedule a weekly review of YARA rule hits to refine signatures and reduce noise.
• Leverage Docker‑Compose for all services to simplify upgrades and rollback.

Frequently Asked Questions

Do I need a paid API key for PhishTank?

No. PhishTank’s public CSV is free for non‑commercial use. If you need higher‑rate access you can request an API key, but the CSV is sufficient for most small‑to‑medium deployments.

Can these tools protect against spear‑phishing?

They help detect the technical indicators (malicious URLs, attachment signatures) but social‑engineering aspects still require user training and DMARC/DKIM enforcement.

How much bandwidth does Zeek consume?

Zeek processes packets in real time with minimal overhead—typically <1 % of a 1 Gbps link on modest hardware. However, enabling heavy logging (e.g., full HTTP bodies) can increase I/O dramatically.

Conclusion

Detecting phishing doesn’t have to be an expensive, black‑box affair. By stitching together PhishTank, SpamAssassin, YARA, Zeek, and MISP you get a transparent, extensible pipeline that evolves with the threat landscape. Follow the steps above, keep your feeds fresh, and regularly audit your rules, and you’ll stay one step ahead of attackers without spending a dime on licences.

Photo by FlyD on Unsplash

Etiketlendi: