影响范围

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 漏洞预警及修复方案的更多相关文章

  1. Redis未授权访问漏洞复现及修复方案

    首先,第一个复现Redis未授权访问这个漏洞是有原因的,在 2019-07-24 的某一天,我同学的服务器突然特别卡,卡到连不上的那种,通过 top,free,netstat 等命令查看后发现,CPU ...

  2. Window 远程桌面漏洞风险,各个厂家的扫描修复方案(CVE-2019-0708)

    自微软公司于2019年5月14日发布远程桌面服务远程代码执行漏洞(CVE-2019-0708)安全公告后,整个业界都一直在密切关注,这个漏洞编号必将在当今网络中掀起腥风血雨.各大厂商也纷纷推出自己的修 ...

  3. Bash漏洞批量检测工具与修复方案

    &amp;amp;lt;img src="http://image.3001.net/images/20140928/14118931103311.jpg!small" t ...

  4. DEDECMS 漏洞修复方案

    目录 DEDECMS支付模块注入漏洞 漏洞文件: /include/payment/alipay.php 漏洞描述: 对输入参数$_GET['out_trade_no']未进行严格过滤 修复方案: 对 ...

  5. Struts2 高危漏洞修复方案 (S2-016/S2-017)

    近期Struts2被曝重要漏洞,此漏洞影响struts2.0-struts2.3所有版本,可直接导致服务器被远程控制从而引起数据泄漏,影响巨大,受影响站点以电商.银行.门户.政府居多. 官方描述:S2 ...

  6. URL存在http host头攻击漏洞-修复方案

    URL存在http host头攻击漏洞-修复方案 spring boot使用注解的方式 -- 第一步:在自定义filter类上添加如下注释 package com.cmcc.hy.mobile.con ...

  7. struts2架构网站漏洞修复详情与利用漏洞修复方案

    struts2从开发出来到现在,很多互联网企业,公司,平台都在使用apache struts2系统来开发网站,以及应用系统,这几年来因为使用较多,被攻击者挖掘出来的struts2漏洞也越来越,从最一开 ...

  8. Linux Glibc库严重安全漏洞修复方案通知(腾讯开发者社区)

    如何查看当前glibc的版本号? rpm -aq | grep glibc 尊敬的用户:       您好!2015年1月28日, 腾讯云安全情报监测到LinuxGlibc库存在一处严重安全漏洞,可以 ...

  9. 应用安全-Web安全-漏洞修复方案整理

    通过HTTP头部字段防御措施整理 X-Frame-Options #反劫持 X-XSS-Protection #开启浏览器防XSS功能 Set X-Frame-Options  CSP X-Conte ...

随机推荐

  1. NFC低功耗模式

  2. gem 更新源设置,ruby安装

    gem sources --remove http://rubygems.org/ gem sources -a http://ruby.taobao.org/ gem sources -l 结果只有 ...

  3. ajax local.href不跳转的原因之一

    ajax local.href不跳转的原因之一 打开F12发现一直报 next.html is not a function…… 后来发现next少了(),看得我尴尬症都犯了

  4. input 禁止 复制 粘贴 剪切 操作

    1.代码 <Input onCopy={(e)=>{ // 禁止拷贝 e.preventDefault(); }} onPaste={(e)=>{ // 禁止粘贴 e.prevent ...

  5. Appium完整安装教程

    Appium安装教程 发布时间: 2014-12-11 10:34    作者: 柒月    来源: 51Testing软件测试网采编 字体:  小  中  大  | 上一篇 下一篇 | 打印  | ...

  6. Git 修改用户名以及提交邮箱

    问题背景: 在已毕业师兄的电脑上提交自己的 Github 代码,(尽管有重新设置了 自己的SSH),但是 Github网站提交结果却显示师兄提交的: 验证当前本地属性: 怎么知道本地有设置?git c ...

  7. window.open()函数

    http://hi.baidu.com/gagahjt/blog/item/7b76e0dee61b20aecd11661c.html open函数详解: window.open("sUrl ...

  8. Linux命令-更新系统时间和硬件时间

    查看系统时间和时区: date 查看系统时间date -R 查看时区 修改时区: tzselect 修改时区 或 cp /usr/share/zoneinfo/Asia/Shanghai /etc/l ...

  9. MPEG-4 压缩编码标准

    文章转自:http://www.cnblogs.com/CoderTian/p/8477021.html 1.MPEG-4标准概述 与MPEG1和MPEG2标准相比,MPEG-4 更加注重多媒体系统的 ...

  10. C#DirectX播放视频

    文章地址:http://www.cnblogs.com/zhangjun1130/archive/2009/09/15/1566814.html 很多人第一次接触到DirectX大都是通过游戏,至于安 ...