Sumeru Cyber Security
  • Sumeru Cyber Security
  • Workarounds for prevalent vulnerabilities
    • Version Disclosure
    • Host Header Attack
    • HttpOnly and Secure Flag
    • Security Headers
    • Clickjacking
    • Weak Password
    • Username Enumeration
    • jQuery Outdated
    • Cross-Origin Resource Sharing
    • AWS S3 Bucket Misconfiguration
    • Directory Listing
    • Laravel Debug Enabled
    • Autocomplete and Remember Password Enabled
    • Brute Force Attack
    • Cross Site Request Forgery
    • SQL Injection
    • PhpMyAdmin page Available Publicly
    • Implementation of BASIC Authentication
    • Cache Browsing
    • Insecure Direct Object Reference
    • Active mixed content over https
    • Improper forgot password implementation
    • ASP.NET Debug Enabled
    • Sensitive Data Sent in GET Request
    • Weak CAPTCHA Implementation
    • Csv Injection
    • Cross Site Scripting
    • Web Server Robot.txt Information Disclosure
    • SSL Related Issues
    • Local File Inclusion
    • Weak CAPTCHA Implementation
    • Automated Form Submission
    • Php.ini File Available Publicly
    • ITLP
    • Internal Path Disclosure
    • Insecure Direct Object Reference
    • Access Token Not Expiring After Logout
  • OWASP A09-Security Logging and Monitoring Failures
  • OWASP API09-Improper Inventory Management v1.0
Powered by GitBook
On this page
  • Introduction
  • How to Test
  • Steps
  • Solutions
  • PHP
  • APACHE
  • ASP.NET
  • References

Was this helpful?

  1. Workarounds for prevalent vulnerabilities

Host Header Attack

PreviousVersion DisclosureNextHttpOnly and Secure Flag

Last updated 5 years ago

Was this helpful?

Introduction

It is common practice for the same web server to host several websites or web applications on the same IP address. This why the host header exists. The host header specifies which website or web application should process an incoming HTTP request. The web server uses the value of this header to dispatch the request to the specified website or web application.

How to Test

Steps

  • Go to the respective site (eg. )

  • Open Burp suite Community Edition. Here, is the to configuration on your browser.

  • In burp suite, go to proxy tab and go to HTTP history. Then sent any request to the repeater by right click on the packet.

  • Change the Host: demo.testfire.net to Host: Attacker.com then the website is goes in attacker.com .

Solutions

PHP

Method 1

This is a simple code to verify the host header. We use $_SERVER['HTTP_HOST'] to declare the host name. In that code, $SERVER['HTTP_HOST'] and required host is same, then proceed to sent the request, if not make the request as error. We have to insert the code in the required php file.

<?php
$host = $_SERVER['HTTP_HOST'];

if($host == "Host_name"){
// make use of $host varaiable for your requiremets
}
else{
echo"invalid access error messages";}
?>

Method 2

In this, we can declared that, what are all the domains will be accessed from the webpage.

$domains = [‘abc.example.com’, ‘foo.bar.com’];
if ( ! in_array($_SERVER[‘SERVER_NAME’], $domains)) {
// error
}

APACHE

Method 1

To mitigate Host Header attacks, we have to create Virtual Host entries in the configuration file. We have to configure in httpd.conf file.

#Configures the virtual host listening for all IPs on PORT 80.
<VirtualHost *:80> 
 ServerName yourdomain.com
 ServerAlias www.yourdomain.com
 DocumentRoot /path/to/your/webroot/directory
</VirtualHost>

Method 2

We can verify the host header by regex pattern. If the regex is not matched, it will redirected to the predefined URL. We can configure in .htaccess or in httpd.conf files.

#It can allow 3rd level subdomain ({0,3}) name and in the length of 1 to 20 ({1,20}). We can change for you convenience.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^([a-zA-Z0-9-_]{1,20}.){0,3}domain.com$ 
RewriteRule ^(.*)$ https://domain.com/ [R=301,L]

ASP.NET

You can use URL Rewrite rules in IIS to find malicious host headers. Perform the steps below:

  1. Go to IIS Manager.

  2. Click on the site.

  3. Double click on “URL Rewrite” (it should be installed).

  4. Click “Add Rule(s)” on the right side.

  5. Select “Blank rule” in Inbound rules. Click “OK”.

  6. Give a name to the rule (eg. Host Header Validation).

  7. .In “Match URL” section, enter (.*) in “Pattern” field.

  8. In “Conditions” section, click “Add”.

  9. Enter {HTTP_HOST} into “Condition input” field.

  10. Select “Does Not Match the Pattern” option from “Check if input string” list

  11. Enter ^([a-zA-Z0-9-_]+.)domain.com$ into “Pattern” field (change domain to your actual domain).

  12. In the “Action” section, select “Abort Request” from the “Action type” list.

  13. Click “Apply” on the right side.

References

https://www.yeahhub.com/host-header-attack-practical-exploitation-and-prevention/
https://niiconsulting.com/checkmate/2018/10/manipulating-host-headers-not-anymore/
https://port135.com/2019/10/15/host-header-attack-and-vulnerability/
https://demo.testfire.net/
Blog
Sent packets to Repeater
Before changing host header
After changing the host header