Posted January 19Jan 19 You are reading Part 44 of the 57-part series: Harden and Secure Linux Servers. [Level 5]This series covers progressive security measures, from fundamental hardening techniques to enterprise-grade defense strategies. Each article delves into a specific security practice, explaining its importance and providing step-by-step guidance for implementation.To explore more security best practices, visit the main guide for a full breakdown of all levels and recommendations.A honeypot is a decoy system designed to attract and deceive attackers, allowing security teams to monitor, analyze, and learn from cyber threats without exposing production systems. Honeypots help:✅ Detect unauthorized access attempts early.✅ Gather intelligence on attack techniques and behavior.✅ Divert attackers away from critical infrastructure.✅ Enhance security defenses by studying real-world threats.By deploying a honeypot, you can track and mitigate cyber threats before they cause real harm.How to Set Up a Honeypot in Linux Using CowrieCowrie is a popular SSH and Telnet honeypot that mimics a real Linux system, logging all attacker interactions.1. Install DependenciesEnsure your system is updated and install necessary packages:sudo apt update && sudo apt upgrade -y sudo apt install git python3-venv python3-dev libssl-dev libffi-dev -y2. Clone and Set Up CowrieClone the Cowrie repository:git clone https://github.com/cowrie/cowrie.git /opt/cowrieChange to the Cowrie directory:cd /opt/cowrieCreate a virtual Python environment:python3 -m venv cowrie-env source cowrie-env/bin/activateInstall dependencies:pip install --upgrade pip pip install -r requirements.txtCopy and configure the default settings:cp cowrie.cfg.dist cowrie.cfg3. Configure Cowrie as an SSH HoneypotEdit the Cowrie configuration file:sudo nano /opt/cowrie/cowrie.cfgModify the following settings:[ssh] enabled = true # Enable SSH honeypot listen_port = 2222 # Change to an unused port [telnet] enabled = false # Disable Telnet unless required [output_textlog] enabled = true # Log attacker activity to a file [output_jsonlog] enabled = true # Save logs in JSON format🔹 Tip: Ensure listen_port = 2222 to avoid interfering with the real SSH service on port 22.4. Start and Enable CowrieStart the honeypot manually:./start.shEnable Cowrie to start at boot:sudo cp bin/cowrie.service /etc/systemd/system/ sudo systemctl daemon-reload sudo systemctl enable cowrie sudo systemctl start cowrie5. Redirect SSH Traffic to the HoneypotSince Cowrie listens on port 2222, redirect incoming SSH traffic to it:sudo iptables -t nat -A PREROUTING -p tcp --dport 22 -j REDIRECT --to-port 2222(This ensures attackers connecting to SSH port 22 are redirected to Cowrie.)6. Monitor Honeypot ActivityCowrie logs attacker activity in:Plaintext logs: /opt/cowrie/log/cowrie.logtail -f /opt/cowrie/log/cowrie.logJSON logs (for security tools & SIEMs): /opt/cowrie/log/cowrie.jsoncat /opt/cowrie/log/cowrie.json | jq .Captured SSH sessions: /opt/cowrie/var/lib/cowrie/tty/🔹 Use a SIEM tool like Splunk or Graylog to analyze Cowrie logs for patterns.Alternative: Use Dionaea for Malware TrappingDionaea is a honeypot designed to capture malware samples from network-based attacks.1. Install Dionaeasudo apt install dionaea -y2. Start Dionaeasudo systemctl start dionaea sudo systemctl enable dionaea3. Monitor Captured Malware Samplescat /var/dionaea/log/dionaea.log7. Isolate the Honeypot in a Separate NetworkSince honeypots intentionally attract attackers, never deploy them on a production network.✅ Use a dedicated VLAN or subnet.✅ Restrict outbound traffic from the honeypot.✅ Monitor honeypot connections using Wireshark or Zeek.8. Forward Honeypot Logs to a Security Monitoring SystemTo centralize honeypot data, send logs to a SIEM like Splunk, Graylog, or ELK.Example: Forward logs to a remote log server using rsyslogEdit the rsyslog config file:sudo nano /etc/rsyslog.confAdd:*.* @remote-log-server:514Restart rsyslog:sudo systemctl restart rsyslogBest Practices for Honeypot Deployment✅ Deploy honeypots in an isolated network (avoid direct exposure to production systems).✅ Regularly monitor and analyze logs for attack patterns.✅ Limit outbound connections to prevent honeypot exploitation.✅ Use multiple honeypots (SSH, HTTP, malware traps) for better insights.✅ Report high-priority threats to security teams or threat intelligence platforms.By implementing a honeypot, you gain valuable insights into attacker behavior, improve security defenses, and detect threats before they reach critical systems.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.