• 主页
  • 相册
  • 随笔
  • 目录
  • 存档
Total 244
Search AboutMe

  • 主页
  • 相册
  • 随笔
  • 目录
  • 存档

认证与会话管理

2020-06-17

认证的英文是Authentication,授权则是Authorization

1. 密码强度

2011年12月,国内最大的开发者社区CSDN的数据库被黑客公布在网上。令人震惊的是,CSDN将用户的密码明文保存在数据库中,致使600万用户的密码被泄露。明文保存密码的后果很严重,黑客们曾经利用这些用户名与密码,尝试登录了包括QQ、人人网、新浪微博、支付宝等在内的很多大型网站,致使数以万计的用户处于风险中。

彩虹表(Rainbow Table )

虹表的思路是收集尽可能多的密码明文和明文对应的MD5值。这样只需要查询MD5值,就能找到该MD5值对应的明文。一个好的彩虹表,可能会非常庞大,但这种方法确实有效。彩虹表的建立,还可以周期性地计算一些数据的MD5值,以扩充彩虹表的内容

2. 多因素认证

除了支付密码外,手机动态口令、数字证书、宝令、支付盾、第三方证书等都可用于用户认证。这些不同的认证手段可以互相结合,使得认证的过程更加安全。密码不再是唯一的认证手段,在用户密码丢失的情况下,也有可能有效地保护用户账户的安全。

3. Session与认证

密码与证书等认证手段,一般仅仅用于登录(Login)的过程。当登录完成后,用户访问网站的页面,不可能每次浏览器请求页面时都再使用密码认证一次。因此,当认证成功后,就需要替换一个对用户透明的凭证。这个凭证,就是SessionID

此时的认证,只需要知道是哪个用户在浏览当前的页面即可。为了告诉服务器应该使用哪一个Session,浏览器需要把当前用户持有的SessionID告知服务器。最常见的做法就是把SessionID加密后保存在Cookie中,因为Cookie会随着HTTP请求头发送,且受到浏览器同源策略的保护


SessionID一旦在生命周期内被窃取,就等同于账户失窃

4. Session Fixation攻击(固定攻击)

假设A有一辆汽车,A把汽车卖给了B,但是A并没有把所有的车钥匙交给B,还自己藏下了一把。这时候如果B没有给车换锁的话,A仍然是可以用藏下的钥匙使用汽车的。


具体攻击的过程是,用户x(攻击者)先获取到一个未经认证的SessionID,然后将这个SessionID交给用户Y去认证,Y完成认证后,服务器并未更新此SessionID的值(注意是未改变SessionID,而不是未改变Session),所以X可以直接凭借此SessionID登录进Y的账户

  • sessionID:客户端发送请求时,服务器会生成一个session对象,session对象生成一个对应的sessionID返回给客户端

url?sid=xx

  • 其中,sid是用于认证的SessionID
  • 用户登录后,这个Sid没有发生改变,因此黑客可以先构造好此URL,并诱使其他用户打开,当用户登录完成后,黑客也可以直接通过此URL进入用户账户。

4.1. 防御

  • 在登录完成后,重写SessionID
    • 如果使用sid则需要重置sid的值
    • 如果使用Cookie,则需要增加或改变用于认证的Cookie值

5. Session保持攻击

  • 攻击者可以通过不停地发起访问请求,让Session一直“活”下去
  • Cookie的Expire时间是完全可以由客户端控制的。篡改这个时间,并使之永久有效,就有可能获得一个永久有效的Session,而服务器端是完全无法察觉的

The Set-Cookie HTTP response header is used to send cookies from the server to the user agent, so the user agent can send them back to the server later.

Set-Cookie: <cookie-name>=<cookie-value>; Expires=<date>


cookie 就是浏览器储存在用户电脑上的一小段文本文件。cookie 是纯文本格式,不包含任何可执行的代码。一个 Web 页面或服务器告知浏览器按照一定规范来储存这些信息,并在随后的请求中将这些信息发送至服务器,Web 服务器就可以使用这些信息来识别不同的用户。大多数需要登录的网站在用户验证成功之后都会设置一个 cookie,只要这个 cookie 存在并可以,用户就可以自由浏览这个网站的任意页面。再次说明,cookie 只包含数据,就其本身而言并不有害。

因此可以修改本地的cookie文件

5.1. 防御

  • 定期强制销毁Session
  • 当用户客户端发生变化时,要求用户重新登录。比如用户的IP, UserAgent等信息发生了变化,就可以强制销
  • 同一用户可以同时拥有几个有效Session。若每个用户只允许拥有一个Session,则攻击者想要一直保持一个Session也是不太可能的。当用户再次登录时,攻击者所保持的Session将被“踢出”

6. 单点登录(SSO)

用户只需要登录一次就可以访问所有相互信任的应用系统

单点登录的英文全称是Single Sign On,简称SSO.

  • SSO的优点在于风险集中化,就只需要保护好这一个点。
  • sso的缺点同样也很明显,因为风险集中了,所以单点一旦被攻破的话,后果会非常严重,影响的范围将涉及所有使用单点登录的系统。降低这种风险的办法是在一些敏感的系统里,再单独实现一些额外的认证机制。比如网上支付平台,在付款前要求用户再输入一次密码,或者通过手机短信验证用户身份等。

6.1. cookie深入

  • 把cookie聊清楚 - 掘金
1
2
3
4
//读取浏览器中的cookie
console.log(document.cookie);
//写入cookie
document.cookie='myname=laihuamin;path=/;domain=.baidu.com';

7. Authentication

7.1. AAA

  • Authentication: 认证
  • Authorisation: 授权
  • Accounting: 审计

    The user identity is recorded when logging security-relevant events in an audit trail

    (在审计跟踪中记录与安全有关的事件时记录用户身份)

7.2. Communication/message authentication

  • It is indeed from the source it claims to be (origin authentication)
  • It has not been altered or replayed (integrity; anti-replay=freshness)
  • Entity authentication is a pre-requisite of message authentication

7.3. Prominent schemes

  • Client-server authentication solutions
    • Password-based
    • Symmetric key based
    • Hash Function based
    • X.509 certificate based (Public Key Infrastructure (PKI )based)
  • Intra-organisation authentication solutions (single-sign-on, SSO)
    • Kerberos
  • Inter-organisation authentication solutions (federation)
    • Shibboleth

7.4. Generic Challenge/Response authentication protocol

7.5. Client-server authentication

7.5.1. Symmetric-Key based

  • One-way authentication
  • Two-way (mutual) authentication
  • reflection attack
  • 安全假设:密钥安全
  • N是指nonce, 指非密钥
  • 解决,包含发送者信息来进行验证

7.5.2. Hash Function based

  • 安全假设:No Hash collision

7.5.3. Asymmetric-Key based

  • 安全假设:私钥只在特定的人手上
  • Impersonation (Man-in-the-Middle attack)

X.509 - PKI (Public Key Infrastructure)

  • 参考:《https笔记》- PKI

7.6. Enterprise authentication

  • Key Distribution Centre (KDC)
    • one central authority

7.6.1. Problems: authentication without KDC(without temporary secrets)

  1. You either use a different password for each server. Or you use the same password for all the servers.
    1. difficult to manage and remember. / once it is compromised, all the servers are compromised
  2. The password is a long-term secret
    1. the more you use, the more likely it can be compromised.
  3. periodical authentication
    1. A client, C, has to remember user’s password for the whole login session, and uses it whenever proof of her identity is required or whenever he needs/accesses to another server/services
  4. All the service servers have to handle the authN task

For problem 1,2,4

  • Use a trusted third party
  • Use a temporary secret(a session key)
    • proof of identity= the temporary secret
    • ticket = encrypted temporary secret

For problem 3

you have to type in your password each time when you request a different key for accessing to a different server, or your client will have to remember your password for the entire logon session.

We want to expose the password as less as possible, i.e. to use it as less frequently as possible and erase it from the workstation as soon as we can!

  • ticket-granting ticket (TGT),to replace the password in a session
    • TGT is valid for one login session only
    • whereas the previous mentioned ticket is a service ticket - valid for one service-session/server only

7.6.2. Kerberos

Introduction:

  • Kerberos is a trusted third party (centralised) authentication system initially designed for TCP/IP networks.

Stage:

  • User Client-based Login without Kerberos
    • User enters a username and password
    • Server compares it with the data from database
  • Client Authentication
  • Client Service Authorization
  • Client Service Request

Cross-realm kerberos(跨域kerberos)

7.7. Attack

7.7.1. Replay

  • A replay attack (also known as a repeat attack or playback attack) (重放攻击(也称为重复攻击或回放攻击))is a form of network attack in which valid data transmission is maliciously or fraudulently repeated or delayed.[1] This is carried out either by the originator or by an adversary who intercepts the data and re-transmits it, possibly as part of a spoofing attack by IP packet substitution. This is one of the lower-tier versions of a man-in-the-middle attack. Replay attacks are usually passive in nature.

7.7.2. Session hijacking(会话劫持)

会话劫持,有时也称为cookie劫持,是指利用有效的计算机会话–有时也称为会话密钥–来获得对计算机系统中信息或服务的未经授权的访问。特别是,它被用来指窃取用于验证用户对远程服务器身份的cookie

7.8. Defence

  • Timeout Reauthentication
  • KDC credential
  • Security
  • Web Security
  • Note
访问控制
文件上传漏洞
  1. 1. 1. 密码强度
  2. 2. 2. 多因素认证
  3. 3. 3. Session与认证
  4. 4. 4. Session Fixation攻击(固定攻击)
    1. 4.1. 4.1. 防御
  5. 5. 5. Session保持攻击
    1. 5.1. 5.1. 防御
  6. 6. 6. 单点登录(SSO)
    1. 6.1. 6.1. cookie深入
  7. 7. 7. Authentication
    1. 7.1. 7.1. AAA
    2. 7.2. 7.2. Communication/message authentication
    3. 7.3. 7.3. Prominent schemes
    4. 7.4. 7.4. Generic Challenge/Response authentication protocol
    5. 7.5. 7.5. Client-server authentication
      1. 7.5.1. 7.5.1. Symmetric-Key based
      2. 7.5.2. 7.5.2. Hash Function based
      3. 7.5.3. 7.5.3. Asymmetric-Key based
    6. 7.6. 7.6. Enterprise authentication
      1. 7.6.1. 7.6.1. Problems: authentication without KDC(without temporary secrets)
      2. 7.6.2. 7.6.2. Kerberos
    7. 7.7. 7.7. Attack
      1. 7.7.1. 7.7.1. Replay
      2. 7.7.2. 7.7.2. Session hijacking(会话劫持)
    8. 7.8. 7.8. Defence
© 2024 何决云 载入天数...