执行多条cmd命令_Jsp挖掘(6)-JSP命令执行漏洞

810734c7e5aec5ca8d7b53e9b3a987e5.png

JSP命令执行漏洞

一、代码执行成因

调用Runtime但是没有对传入参数没有过滤和限制:

jsp调用命令行的只需要在<%%> 中编写使用Runtime类即可调用命令行

Windows 用“&”,linux用“;”号来分隔多条命令

'cmd.exe /c type "E:jspWebGoat-5.3_RC1tomcatwebappswebgoatlesson_plansEnglishBasicAuthentication.html"'

注入数据"%26dir *

二、实例子操作

http://localhost:8080/WebGoat/attack?Screen=11&menu=1100

ce03ed48977666511f915f40bb505787.png

抓去数据包

数据执行的语句:

'cmd.exe /c type "C:WebGoat-5.4tomcatwebappsWebGoatlesson_plansEnglishBasicAuthentication.html"'

闭合:

"%26 dir *

a2b6303314da0362940db8ed211cfdf9.png

执行的结果:

'cmd.exe /c type "C:WebGoat-5.4tomcatwebappsWebGoatlesson_plansEnglishAccessControlMatrix.html"& dir *"'

b7696d08066f4c47988b36e7c7c3498c.png

尝试其他的查看:

"%26 netstat -a

a318c33114cc406d62e8b36142a95663.png

返回相关信息

fd3ba3c021be0e33cc16247a0520e150.png

防护方法:

找到系统的相关命令执行的源码:

执行系统的关键源代码 private String exec(WebSession s, String[] command) { System.out.println("Executing OS command: " + Arrays.asList(command)); ExecResults er = Exec.execSimple(command); // the third argument (index 2) will have the command injection in it if ((command[2].indexOf("&") != -1 || command[2].indexOf(";") != -1) && !er.getError()) { makeSuccess(s); } return (er.toString()); } ---------------------------------------------------------------------------------- 过滤危险字符 private String exec(WebSession s, String command) { System.out.println("Executing OS command: " + command); if ((command.indexOf("&") != -1 || command.indexOf(";") != -1) || command.indexOf(""") != -1) || command.indexOf("|") != -1))//添加的过滤的特殊符合 { return ""; } ExecResults er = Exec.execSimple(command); if ((command.indexOf("&") != -1 || command.indexOf(";") != -1) && !er.getError()) { makeSuccess(s); } return (er.toString()); }

保存Java文件,重起tomcat环境

将修改的.java文件编译成.class文件替换对应的原来的.class文件防护就OK。

参考前面怎么本地编译.java文件。

url:https://mp.weixin.qq.com/s?__biz=MzIyNjk0ODYxMA==&mid=2247483687&idx=1&sn=8551b072266d69f6eb323d2a76f9b77f&chksm=e869e24adf1e6b5c25d5fe542826d6af754903b53889f020839fe1985770021b3290b8504c97&token=699917353&lang=zh_CN#rd

三、防护总结:

1、安全产品waf等等过滤相关的关键词。

2、系统的代码层面,可以关键点执行的相关函数过滤相关的关键词,或者是全局过滤中过滤敏感字符和命令执行相关的代码。

分黑名单(不允许的一些字符)、白名单(运行的字符)。

参数编码

dc4b6c9c6429bb5a4524201409847b99.png

Unix 中

可以通过编码方式,避免命令的注入

/bin/bash script.sh;rm *

/bin/bash –c “sh script.sh; rm *”

四、注意了解:

相关命令执行文章:https://www.cnblogs.com/unixcs/p/10475131.html

参考文献:https://blog.csdn.net/weixin_43706468/article/details/88819431

​公众号:

e29bf4e4f756801574bafa9e94932799.png

thelostworld:

3896382d5f48b57e023debff0c49e6c6.png

个人知乎​:https://www.zhihu.com/people/fu-wei-43-69/columns

​个人简书:https://www.jianshu.com/u/bf0e38a8d400

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值