学习su18梳理shiro历史漏洞
导言
大概是写到CVE-2020的时候,我找到了更好的研究方式,第一是加入了“漏洞百出”和“赛博回忆录”知识星球,我学习到一些思维上的方式。对目前的我最重要的就是“把漏洞抽象”这件事。以往就是不断地复现,但是对漏洞本质理解,也就是最深层的原因,漏洞抽象成某种模式的思考欠缺。其次是看到大佬的文章有价值的炮灰,他写作的方式就是通过大量阅读(外文文章为主),漏洞也不怎么复现就是看一下漏洞成因和布丁,然后抽象出漏洞利用方式,然后主动去挖漏洞。 所以后面的文章,要快速的复现完。然后去学习一下大佬的思维方式。
前言
本篇为学习篇:
- 学习大佬如何学习(su18),主要是模仿他的博客风格进行写作。
- 学习shiro漏洞
Authentication:验证用户的身份/登录,用户需要提供系统可以用理解和信任的某种身份证明。您在 Shiro 中所做的几乎所有操作都基于当前执行的用户,称为Subject。您可以轻松地在代码中的任何位置检索Subject。shiro可连接LDAP/AD/JDBC等安全数据源获取Realm,Realm可自定义,可使用一个或多个Realm对用户进行认证,可通过定义配置文件而不用修改源代码。shiro支持RememberMe,以便可以下次记住我。
Authorization:授权功能,也称为访问控制,是确定应用程序中资源的访问权限的过程,即谁可以访问什么。同样基于Subject,支持多种Realms。检测基于角色(role)或者权限(permission),其中使用通配符检测,称之为Wildcard Permissions,使之简单易读。可使用cache。
Session Management:shiro支持会话管理(session),传统上只有web或者EJB环境才支持session。shiro中所有内容都是基于接口的,并使用POJO实现,这允许使用JavaBeans兼容的配置格式(JSON、YAML、Spring XML等)。shiro会话可使用集群。可以有事件监听器,允许监听session生命周期的所有事件,并做出反映。Shiro 会话保留发起会话的主机的 IP 地址。这使您可以确定用户所在的位置并做出相应的反应。Shiro网络部分实现了HttpSession接口,在web应用总使用Shiro无需修改web代码。shiro可以使用sso登录。
Cryptography:shiro集成了密码学。使用公钥或私钥对电子邮件等数据进行加密的密码,以及对密码等数据进行不可逆加密的哈希值
Permissions:一些使用通配符权限(Wildcard Permissions)的实例,简化配置。Shiro支持实例级别的权限控制校验,例如domain:action:instance
Caching:Shiro中的缓存是一个基本功能,但是其实现是由更底层的缓存机制,比如(JBossCache,Hazelcast等),Shiro提供的缓存支持基本上是一个抽象(包装器)api。其提供了三个重要接口CacheManager/Cache/CacheManagerAware
上面是我自己写的,但是书写的过程参考了su18,su18先刷了一下官方文档,我个人觉得,他是有很强的技术功底的,所以文档中的技术点大致能看懂,我个人看可能还需要反应一会,或者去搜索一下。
初识
他根据已知信息先翻了一下源码,找到几个可学习的类,通过这几个类完成了分析一次认证流程
- SecurityManager
- Subject
- Realm
我也根据自己的理解分析了一遍源码,但是分析之后再看了一下su18写的,发现他写的太细致了,很多细节都看到了,然后他还自己动手写了一些类,以便于完善认知更细致的掌握。下面我根据它看源码的思路,自己也写一遍。 ## SecurityManager org.apache.shiro.mgt.DefaultSecurityManager
是最shiro的一个核心接口,接口负责了一个Subject(用户)的全部安全操作:
- 本接口定义了
createSubject
,login
,logout
三个方法用来创建Subject、登录和退出 - 扩展了
org.apache.shiro.authc .Authenticator
接口提供了authenticate
方法进行认证 - 扩展了
org.apache.shiro.authz.Authorizer
接口,提供了对Permission和Role的校验方法。包括has/is/check相关命名的方法 - 扩展了
org.apache.shiro.session.mgt .SessionManager
接口,提供了start
,getSession
方法用来创建可获取会话
shiro为securitymanager提供了一个默认的实现类org.apache.shiro.mgt .DefaultSecurityManager
,同时实现了相关功能。 DefaultSecurityManager中包含如下属性
- rememberMeManager :在Subject与应用程序的会话中记住Subject的标识。
- subjectFactory:默认使用用DefaultSubjectFactory ,来创建Subject实现类
- sessionManager:默认使用DefaultSessionManager ,用于创建,维持和清除所有应用程序会话
- authorizer:默认使用ModularRealmAuthorizer,为所有给定的Subject提供授权操作
- authenticator :默认使用ModularRealmAuthenticator ,为应用程序中的账户提供身份验证
- PrincipalCollection ,与Subject相关的所有principal的集合。principal只是一个标识属性的安全术语。当Subject第一次创建的时候PrincipalCollection组织所有内部的principals,他们来自于realms。
- realms ,它是一个安全组件,它可以访问特定于应用程序的安全实体,如用户、角色和权限,以确定身份验证和授权操作。包括CasRealm、JdbcRealm等。
- cacheManager ,缓存管理,由用户自行配置,在认证和授权时先经过,用来提升认证授权速度。 ## Subject
org.apache.shiro.subject .Subject
代表应用程序中一个用户的状态,包括认证(登录/注销)、授权(访问控制)和会话访问。是单用户安全的主体。开发人员基本使用SecurityUtils.getSubject()
来获取Subject
。 通过org.apache.shiro.mgt .DefaultSubjectFactory
可知,通过其createSubject