HTTP Header (X-Forwarded-For)

๐Ÿ”น What is the X-Forwarded-For Header?

  • It is an HTTP header that stores the original IP address of a client when a request passes through a proxy or load balancer.
  • Web servers use this header for security and access control.

๐Ÿ”น The Exploit

  • The challenge is to bypass an access restriction on a web page.
  • The server checks for a specific IP address in the X-Forwarded-For header to grant access.
  • By modifying the header manually, the user tricks the server into believing they are an authorized user.

๐Ÿ”น Steps to Exploit

  1. Use cURL or a proxy tool (e.g., Burp Suite) to inspect the request headers.
  2. Modify the X-Forwarded-For header value to localhost (127.0.0.1).
  3. Submit the request again.
  4. The server mistakenly grants access.

Prevention Tips

Use authentication mechanisms instead of relying on IP-based filtering.

Implement server-side validation to ensure the header isnโ€™t blindly trusted.

HTTP Header Attacks

1. Commonly Exploited HTTP Headers

๐Ÿ”น X-Forwarded-For (XFF)

  • Used to store the original IP address of a client behind a proxy.
  • Attackers can spoof their IP to bypass access restrictions.

๐Ÿ’ก Example Attack:

๐Ÿ”น If the server trusts this header for authentication, the attacker gets access!

๐Ÿ”น Host Header Injection

  • Some websites determine site functionality based on the Host header.
  • Attackers can modify it to redirect users, bypass authentication, or exploit SSRF.

Example Attack:

๐Ÿ”น If the application relies on Host to generate links, an attacker might be able to redirect traffic to a malicious site.

Prevention:

  • Always use whitelisted hostnames in your application.
  • Avoid relying on the Host header for authentication.

Referer Header Manipulation

  • Some web applications allow or deny access based on the Referer header.
  • Attackers can fake it to bypass CSRF (Cross-Site Request Forgery) protection.

๐Ÿ’ก Example Attack:

๐Ÿ”น If the site only checks the referer and not proper authentication, the attacker gains access!

โœ… Prevention:

  • Do NOT rely solely on referer headers for security.
  • Use CSRF tokens instead.

๐Ÿ”น User-Agent Spoofing

  • Web applications sometimes restrict access based on the browser type (User-Agent).
  • Attackers can change their User-Agent to impersonate another device or bot.

Example Attack:

๐Ÿ”น Some sites grant special access to search engines (like Googlebot). If not verified properly, an attacker can exploit it.

โœ… Prevention:

  • Verify User-Agent strings by checking the request origin IP.
  • Use CAPTCHAs for additional validation.

Linux Privilege Escalation using PHP

๐Ÿ”น The Exploit

  • The user gains SSH access to a low-privilege account.
  • They discover that the user “Alice” can execute PHP as root.
  • By running a PHP reverse shell, they escalate privileges to root access.

๐Ÿ”น Steps to Exploit

Check for misconfigured sudo permissions:

  • Output shows that Alice can run PHP with root privileges.

Set up a listener on the attackerโ€™s machine:

Run a reverse shell payload on the target machine:

The attacker now has root access to the system.

Video Walkthrough

About the Author

Mastermind Study Notes is a group of talented authors and writers who are experienced and well-versed across different fields. The group is led by, Motasem Hamdan, who is a Cybersecurity content creator and YouTuber.

View Articles