Welcome Guest, Not a member yet? Register   Sign In
Host Header Attack
#3

(04-20-2017, 03:01 AM)Martin7483 Wrote: We use this in the index.php

PHP Code:
$default_domain 'www.yourwebsite.com';
$allowed_domains = array('yourwebsite.com','www.yourwebsite.com');

if ( ! 
function_exists('is_https_on'))
{
 
   /**
     * Is HTTPS?
     *
     * Determines if the application is accessed via an encrypted
     * (HTTPS) connection.
     *
     * @return bool
     */
 
   function is_https_on()
 
   {
 
       if ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off')
 
       {
 
           return TRUE;
 
       }
 
           elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) === 'https')
 
       {
 
           return TRUE;
 
       }
 
       elseif ( ! empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off')
 
       {
 
           return TRUE;
 
       }

 
       return FALSE;
 
   }
}

$protocol 'http://';
if ( 
is_https_on() && USE_HTTPS ) {
 
   $protocol 'https://';
}
// define protocol
define('PROTOCOL'$protocol); 

The check if the HTTP_HOST is within the allowed domains

PHP Code:
if( ! in_array($_SERVER['HTTP_HOST'], $allowed_domains) ) {
 
   $_SERVER['HTTP_HOST'] = $default_domain;


The set a constant
PHP Code:
define('BASE_URL'PROTOCOL.$_SERVER['HTTP_HOST']); 

And in the config
PHP Code:
$config['base_url'] = BASE_URL

Spoofing the HTTP_HOST header will have no effect this way

Ok, Thanks a lot, will try this, andd report it back. Heart
Reply


Messages In This Thread
Host Header Attack - by solasoli - 04-20-2017, 01:27 AM
RE: Host Header Attack - by Martin7483 - 04-20-2017, 03:01 AM
RE: Host Header Attack - by solasoli - 04-20-2017, 03:14 AM
RE: Host Header Attack - by solasoli - 04-20-2017, 07:43 AM
RE: Host Header Attack - by Martin7483 - 04-21-2017, 05:44 AM
RE: Host Header Attack - by solasoli - 04-21-2017, 12:20 PM



Theme © iAndrew 2016 - Forum software by © MyBB