Understanding the capabilities and techniques of ethical penetration testing
As a man-in-the-middle (MITM) attacker, you gain significant visibility and control over network traffic between a target and the internet. This position allows you to:
One of the most powerful MITM capabilities is the ability to inject JavaScript code into web pages as they load. JavaScript allows attackers to:
Below is a simple JavaScript code that will display an alert message when injected into a web page:
alert('javascript test');
This code (saved as alert.js) will display a popup with the message "JavaScript test" whenever it's injected into a page loaded by the target.
To inject JavaScript code using Bettercap's HSTS hijack plugin, follow these steps:
Create a file named alert.js with the following content:
alert('javascript test');
Modify the hstshijack.cap file to include your JavaScript file:
set hstshijack.payloads *:/root/alert.js
The asterisk (*) means inject into all domains. You can specify particular domains instead.
Execute Bettercap with the following command:
sudo bettercap -iface eth0 -caplet spoof.cap
Then run the HSTS hijack plugin:
hstshijack/hstshijack
| Website Type | Protection | Attack Method | Success Rate |
|---|---|---|---|
| HTTP Websites | None | Direct code injection | High (100%) |
| HTTPS Websites | TLS/SSL Encryption | HTTPS stripping via ARP spoofing | High (if no HSTS) |
| HSTS Websites | HTTP Strict Transport Security | Domain spoofing (e.g., .com → .corn) | Medium (depends on user behavior) |