Nginx-host绕过——复现

目录

一、环境搭建

1.配置 

2.添加host文件

3.上传pwnhub文件 

4.给mhz、tmp 权限 

 5.建库建表

二、 绕过Nginx Host限制

第一种 

第二种 

第三种 


一、环境搭建

在/usr/local/nginx/conf/下创建一个demo.conf ,在配置文件中包含一下 

1.配置 

[root@bogon /]# cat /usr/local/nginx/conf/nginx.conf 
http {
    include /usr/local/nginx/conf/demo.conf;
    }
[root@bogon /]# cat /usr/local/nginx/conf/demo.conf 
# 2023.mhz.pw
server {
    listen 80;     
    server_name 2023.mhz.pw;  
    root /usr/local/nginx/html/mhz/web;
    index index.html index.php;

    location / {
        try_files $uri $uri/ /index.php;
        }
 
    location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}

 然后重启nginx

2.添加host文件

192.168.111.128 2023.mhz.pw 

 

 

3.上传pwnhub文件 

4.给mhz、tmp 权限 

[root@bogon sbin]#chmod -R 777 mhz/
[root@bogon mhz]# cd protected/
[root@bogon mhz]# mkdir tmp
[root@bogon mhz]# chmod 777 tmp/

 5.建库建表

create databases security;
use security;
SET NAMES utf8;
SET FOREIGN_KEY_CHECKS = 0;

DROP TABLE IF EXISTS `flags`;
CREATE TABLE `flags` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `flag` varchar(256) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4;

DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `username` varchar(256) NOT NULL,
  `password` varchar(32) NOT NULL,
  `email` varchar(256) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8mb4;

SET FOREIGN_KEY_CHECKS = 1;

二、 绕过Nginx Host限制

三种方式

第一种 

 Nginx在处理Host的时候,会将Host用冒号分割成hostname和port,port部分被丢弃。所以,我们可以设置Host的值为2023.mhz.pw:xxx'"@example.com,这样就能访问到目标server

第二种 

当我们传入两个Host头的时候,Nginx将以第一个为准,而PHP-FPM将以第二个为准。也就是说,传入:Host: 2023.mhz.pw; Host: xxx'"@example.com 

  Nginx将认为Host2023.mhz.pw,并交给目标Server块处理;但PHP中使$_SERVER['HTTP_HOST']取到的值却xxx'"@example.com。这样也可以绕过

第三种 

原理就是,我们在发送https数据包的时候,SNI中指定的域名将会被nginx作为Server Name,而无需和HTTP报文中的Host头保持一致。 我们可以直接使用Brupsuite来测试这个trick,比如我在后端编写PHP代码echo $_SERVER[‘HTTP_HOST’]。正常访问是会显示此时的Host头。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值