Skip to content

Commit 000154e

Browse files
author
jingfeng
committed
1 parent a13aad4 commit 000154e

File tree

8 files changed

+184
-0
lines changed

8 files changed

+184
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>1.5.22.RELEASE</version>
9+
<relativePath/>
10+
</parent>
11+
<modelVersion>4.0.0</modelVersion>
12+
13+
<artifactId>auth-bypass-cve-2020-11989</artifactId>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>org.springframework.boot</groupId>
18+
<artifactId>spring-boot-starter-web</artifactId>
19+
</dependency>
20+
21+
<dependency>
22+
<groupId>org.apache.shiro</groupId>
23+
<artifactId>shiro-web</artifactId>
24+
<version>1.5.2</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.apache.shiro</groupId>
28+
<artifactId>shiro-spring</artifactId>
29+
<version>1.5.2</version>
30+
</dependency>
31+
</dependencies>
32+
33+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package me.threedr3am.bug.shiro.bypass.auth;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class Application {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(Application.class, args);
11+
}
12+
13+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package me.threedr3am.bug.shiro.bypass.auth.config;
2+
3+
import java.util.LinkedHashMap;
4+
import java.util.Map;
5+
import me.threedr3am.bug.shiro.bypass.auth.realm.MyRealm;
6+
import org.apache.shiro.mgt.SecurityManager;
7+
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
8+
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
9+
import org.springframework.context.annotation.Bean;
10+
import org.springframework.context.annotation.Configuration;
11+
12+
/**
13+
* @author threedr3am
14+
*/
15+
@Configuration
16+
public class ShiroConfig {
17+
@Bean
18+
MyRealm myRealm() {
19+
return new MyRealm();
20+
}
21+
22+
@Bean
23+
SecurityManager securityManager() {
24+
DefaultWebSecurityManager manager = new DefaultWebSecurityManager();
25+
manager.setRealm(myRealm());
26+
return manager;
27+
}
28+
29+
@Bean
30+
ShiroFilterFactoryBean shiroFilterFactoryBean() {
31+
ShiroFilterFactoryBean bean = new ShiroFilterFactoryBean();
32+
bean.setSecurityManager(securityManager());
33+
bean.setLoginUrl("/login");
34+
bean.setSuccessUrl("/index");
35+
bean.setUnauthorizedUrl("/unauthorizedurl");
36+
Map<String, String> map = new LinkedHashMap();
37+
map.put("/login", "anon");
38+
map.put("/aaaaa/**", "anon");
39+
map.put("/bypass/*", "authc");
40+
bean.setFilterChainDefinitionMap(map);
41+
return bean;
42+
}
43+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package me.threedr3am.bug.shiro.bypass.auth.controller;
2+
3+
import org.springframework.web.bind.annotation.PathVariable;
4+
import org.springframework.web.bind.annotation.RequestMapping;
5+
import org.springframework.web.bind.annotation.RequestMethod;
6+
import org.springframework.web.bind.annotation.RestController;
7+
8+
/**
9+
* todo 这个洞利用价值不大,基本使用shiro做认证的系统,都会利用/** authc兜底
10+
* CVE-2020-11989
11+
*
12+
* todo-1. 通过访问 http://localhost:8080/bypass/bypass/aaa%252Faaa (两次编码的"aaa/aaa") 绕过接口/bypass的认证控制
13+
* * 漏洞点在于tomcat只会对url进行一次解码,而shiro进行了两次解码
14+
* * 两次解码后,路径变成 http://localhost:8080/bypass/bypass/aaa/aaa 绕过了权限 "/bypass/*" 的match
15+
*
16+
* todo-2. 通过访问 http://localhost:8080/;/bypass/bypass/111 绕过接口/bypass的认证控制
17+
* * 漏洞点在于shiro会对;分号进行截断,访问的 /;/bypass/bypass/111 变成了 / ,自然就绕过了权限 "/bypass/*" 的match
18+
* * server:
19+
* context-path: /bypass
20+
*
21+
* @author threedr3am
22+
*/
23+
@RestController
24+
public class BypassTestController {
25+
26+
/**
27+
* @return
28+
*/
29+
@RequestMapping(value = "/bypass/{id}", method = RequestMethod.GET)
30+
public String bypass(@PathVariable(name = "id") String id) {
31+
return "bypass1 -> " + id;
32+
}
33+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package me.threedr3am.bug.shiro.bypass.auth.controller;
2+
3+
import org.apache.shiro.SecurityUtils;
4+
import org.apache.shiro.authc.AuthenticationException;
5+
import org.apache.shiro.authc.UsernamePasswordToken;
6+
import org.apache.shiro.subject.Subject;
7+
import org.springframework.web.bind.annotation.RequestMapping;
8+
import org.springframework.web.bind.annotation.RequestMethod;
9+
import org.springframework.web.bind.annotation.RestController;
10+
11+
/**
12+
* @author threedr3am
13+
*/
14+
@RestController
15+
public class LoginController {
16+
17+
@RequestMapping(value = "/login", method = RequestMethod.POST)
18+
public String login(String username, String password) {
19+
Subject subject = SecurityUtils.getSubject();
20+
try {
21+
subject.login(new UsernamePasswordToken(username, password));
22+
return "登录成功!";
23+
} catch (AuthenticationException e) {
24+
e.printStackTrace();
25+
return "登录失败!";
26+
}
27+
28+
}
29+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package me.threedr3am.bug.shiro.bypass.auth.realm;
2+
3+
import org.apache.shiro.authc.AuthenticationException;
4+
import org.apache.shiro.authc.AuthenticationInfo;
5+
import org.apache.shiro.authc.AuthenticationToken;
6+
import org.apache.shiro.authc.SimpleAuthenticationInfo;
7+
import org.apache.shiro.authc.UnknownAccountException;
8+
import org.apache.shiro.authz.AuthorizationInfo;
9+
import org.apache.shiro.realm.AuthorizingRealm;
10+
import org.apache.shiro.subject.PrincipalCollection;
11+
12+
/**
13+
* @author threedr3am
14+
*/
15+
public class MyRealm extends AuthorizingRealm {
16+
@Override
17+
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
18+
return null;
19+
}
20+
@Override
21+
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
22+
String username = (String) token.getPrincipal();
23+
if (!"threedr3am".equals(username)) {
24+
throw new UnknownAccountException("账户不存在!");
25+
}
26+
return new SimpleAuthenticationInfo(username, "123456", getName());
27+
}
28+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
server:
2+
context-path: /bypass

shiro/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
<artifactId>shiro</artifactId>
1313
<packaging>pom</packaging>
14+
<modules>
15+
<module><![CDATA[auth-bypass(shiro<1.5.3)]]></module>
16+
</modules>
1417

1518

1619
</project>

0 commit comments

Comments
 (0)