httpoxy 漏洞预警及修复方案
影响范围
PHP、Go、Python等开启CGI(Client)模式的脚本语言
Language | 环境依赖 | HTTP Client |
---|---|---|
PHP | php-fpmmod_php | Guzzle 4+Artax |
Python | wsgiref.handlers.CGIHandlertwisted.web.twcgi.CGIScript | requests |
Go | net/http/cgi | net/http |
漏洞原理
在CGI(RFC 3875)的模式的时候,server 会把请求中的 Header, 加上 HTTP_ 前缀, 注册为环境变量,且重名变量会被覆盖污染,若该变量被脚本调用,即可利用,该漏洞在15年前在LWP中已被发现并修复http://www.nntp.perl.org/group/perl.libwww/2001/03/msg2249.html。
如控制 HTTPHOST 进行 URL 跳转,或者直接控制 HTTP_PROXY 让流量到代理服务器中转,将 HTTP 控制进入环境变量进行shellshock攻击等,所以,所有 HTTP_ 开头的环境变量在CGI模式下都是不可信不安全的。
利用过程如图所示:
可通过
ngrep -q -i -d any -W byline 'proxy' 'dst port 80'
捕获扫描
<?php
$http_proxy = getenv("HTTP_PROXY");
if ($http_proxy) {
$context = array(
'http' => array(
'proxy' => $http_proxy,
'request_fulluri' => true,
), );
$s_context = stream_context_create($context);
} else {
$s_context = NULL;
}
$ret = file_get_contents("http://www.chaitin.cn/", false, $s_context);
PoC
curl "http://target" -H "Proxy: test env"
利用条件
- 后端信任接收的 Header
- 污染控制的变量被脚本调用
- 开启CGI(Client)模式
- 服务器能对外通信
修复方案
最为有效的方式就是在脚本调用变量之前及时阻断或者限制内部调用时的可信变量
Nginx
在配置中加入
fastcgi_param HTTP_PROXY "";
Apache
根据官方建议patchhttps://www.apache.org/security/asf-httpoxy-response.txt
IIS
运行 appcmd set config /section:requestfiltering /+requestlimits.headerLimits.[header='proxy',sizelimit='0']
来阻止恶意代理被调用
如果要清理header,可以使用如下规则
<system.webServer>
<rewrite>
<rules>
<rule name="Erase HTTP_PROXY" patternSyntax="Wildcard">
<match url="*.*" />
<serverVariables>
<set name="HTTP_PROXY" value="" />
</serverVariables>
<action type="None" />
</rule>
</rules>
</rewrite>
</system.webServer>
参考来源
https://httpoxy.org/
https://www.symfony.fi/entry/httpoxy-vulnerability-hits-php-installations-using-fastcgi-and-php-fpm-and-hhvm
附其他语言测试用例
bash
#!/bin/bash export http_proxy=$HTTP_PROXY
`curl http://www.chaitin.cn`
python
#!/usr/bin/python import requests
import os
import sys
from wsgiref.handlers import CGIHandler if sys.version_info < (3,):
def b(x):
return x
else:
import codecs def b(x):
return codecs.latin_1_encode(x)[0] def application(environ, start_response):
status = '200 OK' r = requests.get("http://www.chaitin.cn/") output = """
Made internal subrequest to http://www.chaitin.cn/ and got:
os.environ[HTTP_PROXY]: %(proxy)s
os.getenv('HTTP_PROXY'): %(getenv-proxy)s
wsgi Proxy header: %(wsgi-env-proxy)s
status code: %(status)d
text: %(text)s
""" % {
'proxy': os.environ['HTTP_PROXY'] if 'HTTP_PROXY' in os.environ else 'none',
'getenv-proxy': os.getenv('HTTP_PROXY', 'none'),
'wsgi-env-proxy': environ['HTTP_PROXY'] if 'HTTP_PROXY' in environ else 'none',
'status': r.status_code,
'text': r.text
} response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(b(output))))] start_response(status, response_headers) return [b(output)] if __name__ == '__main__':
CGIHandler().run(application)
Go
package main import (
"fmt"
"io"
"log"
"net/http"
"net/http/cgi"
) func main() {
if err := cgi.Serve(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
header := w.Header()
header.Set("Content-Type", "text/plain; charset=utf-8") response, err := http.Get("http://www.chaitin.cn/") if err != nil {
log.Fatal(err)
} else {
defer response.Body.Close() fmt.Fprint(w, "Response body from internal subrequest:")
_, err := io.Copy(w, response.Body)
fmt.Fprintln(w, "") if err != nil {
log.Fatal(err)
}
} fmt.Fprintln(w, "Method:", r.Method)
fmt.Fprintln(w, "URL:", r.URL.String()) query := r.URL.Query()
for k := range query {
fmt.Fprintln(w, "Query", k+":", query.Get(k))
} r.ParseForm()
form := r.Form
for k := range form {
fmt.Fprintln(w, "Form", k+":", form.Get(k))
}
post := r.PostForm
for k := range post {
fmt.Fprintln(w, "PostForm", k+":", post.Get(k))
} fmt.Fprintln(w, "RemoteAddr:", r.RemoteAddr) if referer := r.Referer(); len(referer) > 0 {
fmt.Fprintln(w, "Referer:", referer)
} if ua := r.UserAgent(); len(ua) > 0 {
fmt.Fprintln(w, "UserAgent:", ua)
} for _, cookie := range r.Cookies() {
fmt.Fprintln(w, "Cookie", cookie.Name+":", cookie.Value, cookie.Path, cookie.Domain, cookie.RawExpires)
}
})); err != nil {
fmt.Println(err)
}
} http://www.tuicool.com/articles/Brmm6zm
httpoxy 漏洞预警及修复方案的更多相关文章
- Redis未授权访问漏洞复现及修复方案
首先,第一个复现Redis未授权访问这个漏洞是有原因的,在 2019-07-24 的某一天,我同学的服务器突然特别卡,卡到连不上的那种,通过 top,free,netstat 等命令查看后发现,CPU ...
- Window 远程桌面漏洞风险,各个厂家的扫描修复方案(CVE-2019-0708)
自微软公司于2019年5月14日发布远程桌面服务远程代码执行漏洞(CVE-2019-0708)安全公告后,整个业界都一直在密切关注,这个漏洞编号必将在当今网络中掀起腥风血雨.各大厂商也纷纷推出自己的修 ...
- Bash漏洞批量检测工具与修复方案
&amp;lt;img src="http://image.3001.net/images/20140928/14118931103311.jpg!small" t ...
- DEDECMS 漏洞修复方案
目录 DEDECMS支付模块注入漏洞 漏洞文件: /include/payment/alipay.php 漏洞描述: 对输入参数$_GET['out_trade_no']未进行严格过滤 修复方案: 对 ...
- Struts2 高危漏洞修复方案 (S2-016/S2-017)
近期Struts2被曝重要漏洞,此漏洞影响struts2.0-struts2.3所有版本,可直接导致服务器被远程控制从而引起数据泄漏,影响巨大,受影响站点以电商.银行.门户.政府居多. 官方描述:S2 ...
- URL存在http host头攻击漏洞-修复方案
URL存在http host头攻击漏洞-修复方案 spring boot使用注解的方式 -- 第一步:在自定义filter类上添加如下注释 package com.cmcc.hy.mobile.con ...
- struts2架构网站漏洞修复详情与利用漏洞修复方案
struts2从开发出来到现在,很多互联网企业,公司,平台都在使用apache struts2系统来开发网站,以及应用系统,这几年来因为使用较多,被攻击者挖掘出来的struts2漏洞也越来越,从最一开 ...
- Linux Glibc库严重安全漏洞修复方案通知(腾讯开发者社区)
如何查看当前glibc的版本号? rpm -aq | grep glibc 尊敬的用户: 您好!2015年1月28日, 腾讯云安全情报监测到LinuxGlibc库存在一处严重安全漏洞,可以 ...
- 应用安全-Web安全-漏洞修复方案整理
通过HTTP头部字段防御措施整理 X-Frame-Options #反劫持 X-XSS-Protection #开启浏览器防XSS功能 Set X-Frame-Options CSP X-Conte ...
随机推荐
- 微信公众帐号开发教程第4篇-----开发模式启用及接口配置Java
欢迎加入群:347245650 345531810 进行讨论相互交流 我的微信号:572839485 我的微信公众账号 我的微社区欢迎关注 索取源码←请点击 图床:没有服务器 拖拽图片 外网即 ...
- 北京SAP-AGS CoE support consultant intern 面试总结
7月4号去大连SAP面试.通过的话直接去北京SAP參加实习(有幸已通过). SAP一直是我理想的公司,大二的时候曾试图參加SAP大连vt项目,当时下了非常大决心,假设通过了就先留在大连,可惜英语群面就 ...
- [置顶] 关于Qt的学习
初学习QT,希望用此来记录学习的轨迹....... 1.Qt版本为Qt5.1.0 2.使用Qt-Creator进行变成. 3.第一个例子 打印出“Hello World” 3.1 打开Qt-Crea ...
- ionic 滚动条问题
方案一: 设置 ion-content ---> overflow-scroll="false"
- UML基础——统一建模语言简介
到了21世纪——准确地说是2003年,UML已经获得了业界的认同.在我所见过的专业人员的简历中,75%都声称具备UML的知识.然而,在同绝大多数求职人员面谈之后,可以明显地看出他们并不真正了解UML. ...
- ajax调用webservice服务
ajax调用是 html方向调用的, 而sqlconnection是 java代码调用的,本质差不多 <html> <head> <title>通过ajax调用we ...
- lamp 一键安装
下载安装(ssh登录服务器,执行如下操作即可,需要用到root用户权限来安装) 源码编译安装 wget http://dl.wdlinux.cn:5180/lanmp_laster.tar.gz ta ...
- Linux-软件包管理-脚本安装包
打开网页: http://sourceforge.net/projects/webadmin/files/webmin/下载1.6.10软件包 下载并放到linux系统中 ls 查看当前目录下所有信息 ...
- Linux环境源码编译安装SVN
zhoulf 2015/2/28 原创 安装说明 安装环境:Red Hat Enterprise Linux 安装方式:源码安装 软件:apr-1.5.0.tar.gz.apr-iconv-1.2.1 ...
- mosquitto 启动命令
启动命令 mosquitto [-c config file] [ -d | --daemon ] [-p port number] [-v] -c 后面跟的是启动mosquitto可以调整的参数,比 ...