Skip to content

Commit d0c615e

Browse files
author
“threedr3am”
committed
feat:添加apache shiro CVE-2020-1957 authentication bypass.
1 parent cb6d7a3 commit d0c615e

File tree

7 files changed

+206
-0
lines changed

7 files changed

+206
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
12+
<modelVersion>4.0.0</modelVersion>
13+
<artifactId>auth-bypass-cve-2020-1957</artifactId>
14+
<build>
15+
<plugins>
16+
<plugin>
17+
<groupId>org.apache.maven.plugins</groupId>
18+
<artifactId>maven-compiler-plugin</artifactId>
19+
<configuration>
20+
<source>7</source>
21+
<target>7</target>
22+
</configuration>
23+
</plugin>
24+
</plugins>
25+
</build>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-web</artifactId>
31+
</dependency>
32+
33+
<dependency>
34+
<groupId>org.apache.shiro</groupId>
35+
<artifactId>shiro-web</artifactId>
36+
<version>1.5.1</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.apache.shiro</groupId>
40+
<artifactId>shiro-spring</artifactId>
41+
<version>1.5.1</version>
42+
</dependency>
43+
</dependencies>
44+
45+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.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: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.threedr3am.bug.shiro.bypass.auth.config;
2+
3+
import com.threedr3am.bug.shiro.bypass.auth.realm.MyRealm;
4+
import java.util.LinkedHashMap;
5+
import java.util.Map;
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("/bypass", "authc");
39+
bean.setFilterChainDefinitionMap(map);
40+
return bean;
41+
}
42+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.threedr3am.bug.shiro.bypass.auth.controller;
2+
3+
import org.springframework.web.bind.annotation.RequestMapping;
4+
import org.springframework.web.bind.annotation.RequestMethod;
5+
import org.springframework.web.bind.annotation.RestController;
6+
7+
/**
8+
* CVE-2020-1957
9+
*
10+
* todo 当存在某个Controller使用了动态Controller时,例:存在接口/bypass和/bypass/{id},就能通过访问 http://localhost:8080/bypass.xxxxx 或 http://localhost:8080/aaaaa/..;/bypass 绕过接口/bypass的认证控制
11+
* todo When there is a dynamic Controller, the Controller USES the example: there are api interface /bypass and /bypass/{id}, you can visit http://localhost:8080/bypass.xxxxx or http://localhost:8080/aaaaa/..;bypass to bypass authentication
12+
*
13+
* todo 漏洞点在于使用了getRequestURI
14+
* todo The vulnerability point is in use 'getRequestURI()'
15+
*
16+
* /aaaaa/..;/bypass
17+
* /bypass.xxxxx
18+
*
19+
* @author threedr3am
20+
*/
21+
@RestController
22+
public class BypassTestController {
23+
24+
/**
25+
*
26+
* 例:配置"/bypass", "authc",请求http://localhost:8080/bypass.xxxxx
27+
*
28+
* Example: configuration "/bypass", "authc", request to http://localhost:8080/bypass.xxxxx bypass
29+
*
30+
* shiro < 1.5.2
31+
*
32+
* @return
33+
*/
34+
@RequestMapping(value = "/bypass", method = RequestMethod.GET)
35+
public String bypass() {
36+
return "bypass1";
37+
}
38+
39+
/**
40+
* @param id
41+
* @return
42+
*/
43+
@RequestMapping(value = "/bypass/{id}", method = RequestMethod.GET)
44+
public String bypass2(String id) {
45+
return "bypass2";
46+
}
47+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.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 com.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+
port: 9999

0 commit comments

Comments
 (0)