36-2 shiro越权 - shiro越权介绍

223 篇文章 3 订阅 ¥299.90 ¥99.00

一、Apache Shiro 简介

        Apache Shiro 是一个强大且易用的 Java 安全框架,负责执行身份验证、授权、密码和会话管理。无论是最小的移动应用程序还是最大的网络和企业应用程序,都可以通过使用 Shiro 的 API 快速、轻松地实现安全功能。

二、Shiro权限绕过原因

Apache Shiro 是 Java 的安全管理框架,可与 Spring 框架一起使用。它通过拦截器来控制和拦截用户对资源的访问。常见的拦截器包括:

  1. anon:匿名拦截器,用于允许未登录用户访问静态资源或移动端接口。
  2. authc:登录拦截器,要求用户登录认证后才能访问的资源。

三、Shiro权限绕过的限制条件:

  • 网站同时使用 Shiro 和 Spring 框架。
  • Shiro 版本必须满足特定的要求。

四、CVE-2016-6802

CVE-2016-6802是一个影响shiro安全框架的安全漏洞,特别是在shiro版本小于1.5.0的情况下。这个漏洞涉及shiro与spring的URI中末尾的斜杠(/)导致的权限绕过问题

问题的关键在于shiro中的URL路径匹配机制。在shiro中,/*通配符可以匹配零个或多个字符串,而/-只能匹配到路径的最后一个部分。

具体来说,考虑这样的情况:

  1. /admin - 由于
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
对于dp-boot项目,升级Shiro 1.10.1的步骤如下: 1. 在pom.xml文件中升级Shiro依赖版本到1.10.1: ```xml <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-core</artifactId> <version>1.10.1</version> </dependency> ``` 2. 修改Shiro配置文件,将Shiro.ini改为Shiro.yml格式,并做相应的修改: ```yaml shiro: # realm配置 realms: - name: jdbcRealm # ... # filter配置 filters: anon: org.apache.shiro.web.filter.authc.AnonymousFilter authc: org.apache.shiro.web.filter.authc.FormAuthenticationFilter perms: org.apache.shiro.web.filter.authz.PermissionsAuthorizationFilter roles: org.apache.shiro.web.filter.authz.RolesAuthorizationFilter # filterChain配置 filterChainDefinitions: '/login': anon '/logout': logout '/register': anon '/static/**': anon '/admin/**': authc, roles[admin] '/user/**': authc, roles[user] '/api/**': authc, perms[api:access] ``` 3. 修改Shiro配置类,使用Yaml配置方式: ```java @Configuration public class ShiroConfig { @Bean public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager) { ShiroFilterFactoryBean filterFactoryBean = new ShiroFilterFactoryBean(); filterFactoryBean.setSecurityManager(securityManager); Map<String, Filter> filters = new LinkedHashMap<>(); filters.put("anon", new AnonymousFilter()); filters.put("authc", new FormAuthenticationFilter()); filters.put("perms", new PermissionsAuthorizationFilter()); filters.put("roles", new RolesAuthorizationFilter()); filterFactoryBean.setFilters(filters); Map<String, String> filterChainDefinitionMap = new LinkedHashMap<>(); filterChainDefinitionMap.put("/login", "anon"); filterChainDefinitionMap.put("/logout", "logout"); filterChainDefinitionMap.put("/register", "anon"); filterChainDefinitionMap.put("/static/**", "anon"); filterChainDefinitionMap.put("/admin/**", "authc, roles[admin]"); filterChainDefinitionMap.put("/user/**", "authc, roles[user]"); filterChainDefinitionMap.put("/api/**", "authc, perms[api:access]"); filterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap); return filterFactoryBean; } @Bean public SecurityManager securityManager(Realm realm) { DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager(); securityManager.setRealm(realm); return securityManager; } @Bean public Realm realm() { JdbcRealm jdbcRealm = new JdbcRealm(); jdbcRealm.setDataSource(dataSource()); jdbcRealm.setAuthenticationQuery("SELECT password FROM users WHERE username = ?"); jdbcRealm.setUserRolesQuery("SELECT role_name FROM user_roles WHERE username = ?"); return jdbcRealm; } @Bean public DataSource dataSource() { // ... } // ... } ``` 4. 修改ShiroRealm类,将doGetAuthenticationInfo和doGetAuthorizationInfo方法的返回值类型改为SimpleAuthenticationInfo和SimpleAuthorizationInfo: ```java public class ShiroRealm extends JdbcRealm { @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { UsernamePasswordToken upToken = (UsernamePasswordToken) token; String username = upToken.getUsername(); String password = getPasswordForUser(username); if (password == null) { throw new UnknownAccountException("No account found for user [" + username + "]"); } SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(username, password.toCharArray(), getName()); return info; } @Override protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { String username = (String) principals.getPrimaryPrincipal(); SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); Set<String> roles = getRolesForUser(username); info.setRoles(roles); return info; } // ... } ``` 5. 测试项目运行是否正常。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

狗蛋的博客之旅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值