cmd编译可以通过执行没有结果_Jsp挖掘(6)-JSP命令执行漏洞

b8b448bf07573a027a6c56a7de5445a0.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

fad4799c17c485b1ff29cd228edcf3c2.png

抓去数据包

数据执行的语句:

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

闭合:

"%26 dir *

af5877bdc8147d0a88e3e4e5a9ae5910.png

执行的结果:

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

8a117cce0957826ffb5a7e244e0f1012.png

尝试其他的查看:

"%26 netstat -a

f57d46afbd5c8b419563ea9a9a1d0a87.png

返回相关信息

1b82c16394b830737b814f9d0bf663fd.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、系统的代码层面,可以关键点执行的相关函数过滤相关的关键词,或者是全局过滤中过滤敏感字符和命令执行相关的代码。

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

参数编码

0de0325bc62157d5a02216ae957da17a.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

​公众号:

c45664678ffde34baa6ca92db1930db8.png

thelostworld:

0373216de0ca01c3e0a79d568b3f9229.png

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值