目录
正在加载目录…
正在阅读专栏 OSTEP 操作系统专栏 第 40 篇 · 共 62 篇 · 65%

OSTEP:Authentication

发布于 2026-09-17 21:41 · 最后编辑于 2026-09-17 22:08 · 版本 v2 · 字数 13,075 · 预计阅读 27 分钟 👁 18 次阅读

OSTEP:Authentication

本篇对应 OSTEP Version 1.10 的 Chapter 54 “Authentication”。核心问题是:操作系统如何可靠地把 security-relevant identity 附着到 process,并据此执行 security policy。

类型与定位

  • 笔记类型:正文翻译/知识整理
  • 翻译基准:官方 Authentication
  • 术语约定:principal、agent、object、credential、authentication、password、salt、biometric 等保留英文或中英并列。
  • 图件说明:原文包含 Figure 54.1 这一张 error-rate 概念图;已在对应位置用 Mermaid 重绘,没有需要单独嵌入的 raster image。

TL;DR

OS 的 access decision 依赖“谁在请求”。用户登录时,系统需要验证其身份;随后把 identity 附着到 shell、process 和 credential 上。传统 authentication factor 包括 what you know、what you have、what you are;password 方案还必须处理猜测、窃取、重放和 server compromise。

目录

章节内容
安全决策中的身份principal、agent、object 与 credential
把 identity 附着到 processprocess inheritance 与 login
Authentication factorsknowledge、possession、inherence
Password 的问题质量、猜测与保护
多因素与实践factor 组合与生命周期

安全决策中的身份

操作系统服务通常由 process 通过 system call 请求。OS 通过 process control block(PCB)知道请求来自哪个 process,并根据其 identity 决定是否执行。

几个角色需要区分:

名词含义
principal能请求资源访问的 security-relevant entity,例如 user、group 或 software system
agent代表 principal 发出请求的 active computing entity,通常是 process
object被请求访问的资源,例如 file 或 IPC channel
credentialOS 保存的、用于记录 access decision 或 identity 的数据

基本关系是:

mermaid
flowchart LR
  P[Principal] -->|identity| A[Agent / Process]
  A -->|system call| O[Object / Resource]
  C[Credential] --> D[OS access decision]
  A --> D
  O --> D

authentication 只回答“你是谁”;authorization/access control 再回答“你能做什么”。二者不能混为一谈。

把 identity 附着到 process

新 process 通常由已有 process 创建,因此一种简单规则是让 child 继承 parent 的 identity:

text
process A --fork()--> process B
identity(B) = identity(A)

OS 可以从 A 的 PCB 读取 identity,创建 B 的 PCB,并复制相关身份信息。这个机制适合普通 process creation,但系统仍需要一个可信的起点:最初的 login process 如何得到正确的 user identity?

用户通常先与 shell、window manager 或 login service 交互。OS 验证用户后,创建或初始化属于该用户的 process,并把 user ID 等身份信息写入受保护的内核数据结构。之后,用户启动的 process 继承这个身份。

关键安全要求:

  • 用户不能任意修改自己的 kernel-managed identity;
  • child process 的身份继承必须遵守系统 policy;
  • 能改变 identity 的 privileged operation 必须受到严格保护;
  • authentication 结果通常会被 process 生命周期内的后续请求复用,因此初次判断必须可靠。

Authentication factors

经典 authentication 依据三类 factor:

Factor含义例子
what you know只有你知道的 secretpassword、PIN、watchword
what you have只有你持有的东西hardware token、smart card、phone
what you are你的生物或行为特征fingerprint、face、voice、typing pattern

单一 factor 不是绝对安全。password 可能被猜出或钓鱼;token 可能丢失;biometric 可能被复制、误识别,且泄露后通常不能像 password 一样简单更换。

Password 的问题

password 是一个只有被认证方知道的 secret。系统要求用户在 login 时提交它,然后判断该 secret 是否与账号匹配。

其安全性取决于多个条件:

  • password 是否足够长、不可预测;
  • 用户是否在多个服务复用 password;
  • 攻击者能否观察输入、读取网络流量或窃取数据库;
  • 系统是否限制 online guessing 的速度和次数;
  • 系统是否把 password 以可逆明文保存。

系统不应直接保存 password 明文。常见做法是保存带随机 salt 的慢速 password hash:

text
stored = KDF(password, random_salt, cost)

验证时,对用户输入使用同一个 salt 和 cost 重新计算,再比较结果。salt 的作用不是让 password 变得不可猜,而是让预计算 rainbow table 难以复用,并使相同 password 的存储结果不同。cost 则提高每次猜测的计算代价。

更一般的安全原则是 avoid storing secrets:如果系统不需要知道原 secret,就不要保存明文;必须保存时,应使用经过充分研究的 cryptographic hash,并尽量减少副本、日志、backup 和临时文件中的泄露位置。对 password 而言,hash 的目的不是让攻击者“解密”出原文,而是让系统能够验证“用户是否知道该 secret”,同时不直接持有 secret 本身。

password entropy 与 dictionary attack

password 的可猜测空间取决于长度和实际使用的字符分布。一个 1-bit password 只有两个候选值;8-bit password 也只有 256 个候选值,平均尝试 128 次即可猜中。人类通常会选择姓名、单词、日期或 123456 等易记模式,攻击者因此会优先使用按概率排序的 dictionary,而不是盲目遍历所有随机字符串。

这里要区分 online 与 offline attack:

攻击方式攻击者拥有的能力主要防御
online guessing反复向 login service 提交尝试rate limiting、延迟、lockout、monitoring、MFA
offline guessing已窃取 password file,可本地高速计算强 password、每个账号独立 salt、昂贵 KDF

单纯使用同一种快速 hash 会让攻击者为整张 password file 预先计算 dictionary。随机 salt 与每个用户的 hash 一起存储并不需要保密,但会迫使攻击者针对每一个 salt 单独计算猜测,破坏可复用的 rainbow table。salt 不能替代高 entropy password 或 KDF,它只是提高批量猜测的成本。

Linux login 的身份附着过程

一个典型的 Linux/UNIX login 流程可以拆成:

  1. privileged login process 显示 username prompt,用户输入 user name;
  2. login process 请求 password,输入不回显;
  3. 根据 user name 查找 user ID、group、shell、home directory,以及 password salt/hash;
  4. 将输入 password 与 salt 组合后计算 hash,与保存值比较;
  5. 验证成功后 fork 一个 process,设置 user/group identity,切换到 home directory,并 exec 该用户的 shell。

login 通常不向未认证用户透露 user name 不存在还是 password 错误,以免攻击者枚举系统中合法的 user names。之后 shell 启动的 process 继承这个经过认证、由 kernel 保护的 identity;这正是 authentication 结果会影响整个 process lifetime 的具体例子。

需要区分两类攻击:

  • online guessing:攻击者反复向认证服务提交猜测,可通过 rate limiting、lockout、MFA 和 monitoring 降低速度;
  • offline guessing:攻击者获得 password database 后,在本地高速尝试,必须依赖强 password、salt 和高成本 KDF。

What you have:token 与动态凭据

hardware token、smart card、手机或一次性 code 都属于 what you have。若 computer 具备 USB、card reader 等硬件,它可以直接检查 token;否则 token 可以在屏幕上显示短期 code,由用户键入 computer。code 必须频繁变化,否则一旦被观察到,authentication 就从“持有某物”退化成“知道一个静态 secret”。

这类 factor 的优点是为 password 增加了独立证据,缺点是 token 可能丢失、被盗或暂时无法取得。丢失时同时存在两个问题:合法用户无法登录,拾到 token 的人可能冒充用户。因此 recovery 与 revocation 不能成为绕过原有 security policy 的后门。短信 code 在实践中有一定便利性,但 phone number redirection 等风险说明它不应被不加分析地视为强硬件证明。

What you are:biometric authentication

biometric 不应按 bit-for-bit equality 比较。两次 face image 即使来自同一个人,也会受到光线、角度、mask、姿态、发型和 camera 条件影响;系统通常提取较高层 feature,再按“足够接近”进行判断。

这会产生两类不可同时消除的错误:

结果含义
False negative合法用户被拒绝
False positive冒充者被接受

提高匹配 sensitivity、允许更大的差异,通常会降低 false negative,却增加 false positive;反向调整则相反。两条 error-rate 曲线的交点可用 crossover error rate 描述,但实际阈值应根据场景选择:手机可能更重视不频繁锁死合法用户,银行金库则更重视不放行冒充者。

原文 Figure 54.1 用两条曲线表示 sensitivity 调整时 false positive rate 与 false negative rate 的此消彼长;两条曲线的交点就是 crossover error rate:

mermaid
xychart-beta
    title "Figure 54.1:Crossover Error Rate"
    x-axis "Sensitivity" [低, 较低, 中等, 较高, 高]
    y-axis "Errors" 0 --> 1
    line "False Positive Rate" [0.10, 0.25, 0.50, 0.75, 0.90]
    line "False Negative Rate" [0.90, 0.75, 0.50, 0.25, 0.10]

图中数值是为了重绘趋势而设的示意值,不是原文给出的测量数据;语义与原图一致:提高 sensitivity 会降低一类错误、提高另一类错误。

biometric 还依赖可信的 sensing hardware。若 fingerprint/face pattern 通过不可信 network 传来,攻击者可以伪造任意 bit pattern;scanner 与被保护 machine 物理绑定时,伪造路径更少。biometric 一旦泄露也不像 password 那样容易更换,因此它更适合与其他 factor 组合,而不是被当作完美证明。

多因素与实践

MFA 的安全收益来自不同 factor 的独立性。把两个 password 当作两个 factor 并不能得到真正的 what-you-know + what-you-have。

Authentication factor 没有一种在所有环境中都完美:长而不可预测的 password、设计良好的 token、可信的 biometric reader 都可以在合适的 threat model 下工作;某个 factor 的弱点可以由另一个不共享该失败模式的 factor 弥补。安全设计的目标是选择适合环境的组合,而不是寻找抽象意义上的完美机制。

实际设计还需处理:

  • enrollment:如何首次绑定 token 或 biometric;
  • recovery:factor 丢失后如何恢复而不绕过安全 policy;
  • revocation:设备被盗或员工离职后如何撤销;
  • delegation:process 是否能代表另一个 principal;
  • auditing:记录成功和失败的 authentication event;
  • session lifetime:认证结果可以复用多久。

Non-human principal 与 group identity

并非每个 process 都对应一个正在 login 的人。web server、daemon、embedded device 都可能没有 human user。系统可以建立 webserver、lightbulb 等 non-human user,并把相关 process 绑定到这些 identity;但必须防止任意普通 user 创建一个伪装成该 service 的 process。

常见做法包括:由 privileged administrator 代表该 service 创建 process、使用 service account credential,或允许受控的 ownership transition。UNIX 中 sudo -u webserver apache2 就是一个例子:执行者需要有权使用 sudo,但启动后的 apache2 及其 child processes 以 webserver identity 运行。任何允许“代表另一个 principal”或“改变 process ownership”的机制都必须受到严格保护。

group 也是 security-relevant principal。与其逐个给多个 administrator 授予权限,系统可以建立一个 group,让 policy 依据 membership 做判断。group membership 可以作为 process credential 的一部分,也可以通过 user identity 查询;后者允许一个 user 属于多个 groups,但也增加了另一条获得 access 的路径。

其他身份线索

“what you know / have / are”并不穷尽所有可能。某些环境可能尝试依据 location 认证,例如相信站在特定柜台后的实体;但必须仔细验证 location evidence。也可以根据持续行为(typing pattern、command timing 或是否属于一组 well-behaved users)做判断。行为线索更像动态风险评估,不应不加区分地等同于稳定的人类 identity。

逐段翻译说明:原文的 Linux login procedure、password attack、token、biometric error-rate、non-human principal 与 group identity 主要以文字、列表和概念框呈现;本笔记按对应语义位置补入表格、Mermaid 与代码块。官方 PDF 未提供需另存的 raster image,因此没有遗漏图片文件或尺寸调整。

原文逐段补充(Version 1.10)

Authentication 的起点:principal、agent、object 与 credential

OS service 之所以可以执行,取决于 request 的 context;最重要的 context 之一就是“谁在请求”。在现实中,熟悉的人请你买一加仑牛奶,和陌生人提出同样请求,得到的反应并不相同;在 OS 中,administrator 请求安装 program 与随机网页中的 script 请求安装 program,也应触发不同的 policy decision。

能够请求 resource 的 security-meaningful entity 称为 principal,可以是 human user、user group 或复杂 software system。实际执行 request 的 process 或其他 active computing entity 称为 agent;被请求访问的资源称为 object。OS 若已经判断某个 agent 可以访问某 object,便可把这个 decision 记录在 PCB 等 per-process data structure 中;这种由 OS 创建并管理、用于保存未来 access decision 的数据称为 credential。

principal 的 identity 不一定是 human user。某些 system(例如 Android)可以把 privilege 授予特定 program;该 program 的每次运行都带有相应 privilege,其他 program 则没有。无论采用 user、group 还是 program identity,关键都是把正确 identity 安全地附着到正确 process 上,因为 OS 通常会在至少整个 process lifetime 内复用初次 authentication decision。

Parent-child inheritance 不是可信起点

创建 child process 时,OS 可以读取 parent A 的 PCB,把 A 的 identity 复制到新 process B:

text
process A --fork()--> process B
identity(B) = identity(A)

如果 boot 后所有 process 都继承同一个 system identity,这个机制本身没有问题,却无法表达不同 principal 的 security policy。multi-user system 必须在 process chain 的某个起点建立不同 identity。通常 OS 启动一个 privileged login process,由它验证 human user,再创建属于该 user 的 shell 或 window manager;之后由 shell 启动的 process 才通过 parent-child inheritance 继续传播 identity。

因此本章更精确的 CRUX 是:如何 securely identify processes? 对属于多个 principal 的 system,必须保证每个 process 都附有正确 identity,也必须防止 malicious entity 未经允许改变 process identity。

三类 factor 的历史例子

“what you know / what you have / what you are”并非计算机时代才出现:Polybius 描述过 Roman army 使用 watchword 区分 friend 与 foe,这是 what you know;Roman architect Celer 在约公元 100 年写给 imperial procurator 的 recommendation letter,可以作为 what you have 的凭据;《Judges》中的 Gileadites 要求逃亡者正确发音 shibboleth,以区分本地人和 Ephraimites,则是 what you are(语言特征)的早期例子。

Password hash、cryptographic hash 与 salt

系统实际不需要知道 password 的原值,它只需判断用户是否知道该值。因此可以保存 hash(password),把用户提交的 password hash 后与保存结果比较。若攻击者把保存的 hash 当成 password 直接提交,系统会再次 hash 它,hash-of-hash 不会与原保存值匹配。

这里不能把任意快速 hash 当成 password protection。cryptographic hash 应使攻击者除了逐个尝试 guess 外,无法从 hash 推断 password;hash function 很难正确设计,应使用经过专家研究、没有已知缺陷的标准构造。原文以写作时的 SHA-3 作为例子,同时强调合适算法会随时间变化。

即使 hash file 泄露,攻击者仍可使用 dictionary 与计算资源离线尝试;如果所有用户都使用相同 hash,攻击者只需把每个候选 password hash 一次,再与所有账户比较。salt 的做法是:为每个 password 生成独立的随机数(例如 32 或 64 bits),计算 hash(password || salt),并将 salt 与 hash 一起保存。salt 不需要保密;它的作用是阻止“一份 dictionary hash translation”被所有账户复用。若 salt 为 32 bits,预计算每个 dictionary word 的所有 salt 组合需要约 2^32 份结果,攻击者只能针对每个账户重新计算,成本显著提高。

密码系统的安全性仍取决于 password 本身是否易猜。原文举例:1-bit password 平均只需极少尝试,8-bit password 也只有 256 个候选值,平均 128 次即可命中。人类偏好可记忆的 names、words、日期和 123456 等 pattern,因此攻击者会按概率排序的 specialized dictionary 先尝试;对典型网站,这类 dictionary attack 曾能猜中约 90% 的 password。remote login service 应在少量失败后大幅降低验证速度,通常比简单 lockout 更能避免长期 dictionary attack。

Password vault 与“避免保存 secret”

password vault/key chain 是一个由独立 master password 加密的 file,存储其他 passwords。用户只需记住 vault password;vault 还可以生成不需人工记忆的 strong passwords。其安全性仍受 vault password 和 vault file access 的双重约束,dictionary attack 也不会凭空消失。

若 cloud vault 接收 cleartext passwords,用户就把 secret 交给了一个本来不必知道它的第三方;若 cloud 只存加密后的 vault,风险较低。更一般的原则是 avoid storing secrets:不需要保存的 password、cryptographic key 不要保存;必须保存时使用强 hash,或用 secure cipher 加密,并尽量减少 copies,同时检查 temporary files、backups、logs、executable 与运行中 heap,因为 secrets 可能从这些位置泄露。

Linux login 的两个安全细节

官方的 Unix login procedure 是:privileged login process 回显 user name、但不回显 password;根据 name 查出 user ID、group ID、初始 shell、home directory、salt 与 salted hash;重新计算并比较;成功后 fork,设置 user/group,切换 home directory,exec 对应 shell。user name 不存在和 password 错误时通常返回相同的失败结果,避免未认证攻击者枚举合法 user names。

原文还留下两个值得思考的细节:为什么 user name 可以回显而 password 不回显?回显 user name 是否只是 convenience 与 security 的 trade-off?以及在另一个用户 logout 后,同一 terminal 如何安全地启动下一次 login?这些细节说明 authentication 不仅是 hash comparison,也是一个由 privileged process、terminal、process creation 和 identity transition 共同完成的 protocol。

What you have:token 的动态性与现实取舍

带 USB 等接口的 hardware token 可以由 OS 直接检测;没有专用 reader 时,token 可以在小屏幕显示短字符串,由用户键入 computer。后者不是 computer 对 token 的直接证明,而是假设只有 token holder 才能知道当前 string。string 必须每隔几秒或每次 authentication 改变,否则观察者一旦记住它,factor 就从“what you have”退化成“what you know”。

token 丢失会产生双重问题:合法用户失去登录凭据,拾到 token 的人可能冒充用户;MFA 可以让偷到 token 却不知道 password 的攻击者仍无法登录。SMS code 在理论上容易受到 phone loss 或 message redirection 的影响,但现实中的攻击成本、用户是否随身携带 phone、以及发现丢失后的响应速度,也都属于实际 threat model。原文借此提醒:理论上可 subvert 不代表实际机制没有合理 security,系统设计应同时考虑 convenience 与攻击可行性。

Biometric 的 hardware 与 threshold

biometric system 不是把两张图片做 bit-for-bit equality。camera 采集的是受 lighting、angle、mask、photo spoof、姿态和 hairstyle 影响的一组 bits;system 通常抽取 nose length、eye color、mouth shape 等 higher-level features,再按“close enough”进行判断。识别 hardware 还可能根本不存在于 server 或 embedded device 上。

匹配 sensitivity 越严格,合法用户因外观轻微变化而被拒绝的 false negative 越多;越宽松,冒充者被接受的 false positive 越多。两条 error-rate 曲线的交点是 crossover error rate,但不一定是正确 operational threshold:smartphone 可能更在乎少锁住合法用户,bank vault 则更在乎不放行冒充者。

若 biometric scanner 位于不可信远端,网络上传来的只是任意 bit pattern,攻击者可以伪造 fingerprint representation;scanner 与被保护 machine 物理绑定时,伪造机会更少。不同 factor 可能在不同场景失败,因此设计目标不是寻找完美 mechanism,而是选用适合环境的 mechanism,并在必要时组合第二或第三 factor。

原文 References 补充

  • [B+09] Guido Bertoni、Joan Daemen、Michael Peeters、Gilles Van Assche, “The road from Panama to Keccak via RadioGatun”——SHA-3 的设计资料。
  • [C100] Celer the Architect, “Letter of recommendation to Tiberius Claudius Hermeros”,约公元 100 年。
  • [G13] Dan Goodin, “Anatomy of a hack: even your ‘complicated’ password is easy to crack”,2013——dictionary attack 的实际案例。
  • [JB-500] Judges 12:5–6——使用 shibboleth 的早期 biometric/authentication 例子。
  • [KA16] Swati Khandelwal, “VK.com Hacked! 100 Million Clear Text Passwords Leaked Online”——明文 password 泄露案例。
  • [M+02] Tsutomu Matsumoto 等, “Impact of Artificial ‘Gummy’ Fingers on Fingerprint Systems”,SPIE 4677,2002。
  • [MT79] Robert Morris、Ken Thompson, “Password Security: A Case History”,Communications of the ACM 22(11),1979——早期 Unix password 与 salting。
  • [P-46] Polybius,The Histories,约公元前 146 年——Roman army watchword 的记载。
  • [TR78] Marcello Truzzi, “On the Extraordinary: An Attempt at Clarification”,Zetetic Scholar 1(1),1978。

源文档核验记录

  • 源文档:OSTEP Version 1.10 官方 security-authentication.pdf。
  • 页数:19 页(含正文与 References)。
  • 章节范围:54.1 Introduction、54.2 Attaching Identities To Processes、54.3 How To Authenticate Users?、54.4 Authentication By What You Know、54.5 Authentication by What You Have、54.6 Authentication by What You Are、54.7 Authenticating Non-Humans、54.8 Summary。
  • 图件核对:Figure 54.1 Crossover Error Rate 已在 biometric 段落的对应位置重绘;原 PDF 没有需要另存的独立 raster 图片。
  • 内容核对:已覆盖 principal/agent/object/credential、process identity inheritance、三类 authentication factor、password hash/salt/dictionary attack、password vault、Linux login procedure、token、SMS 与现实 threat model、biometric threshold/error rate/hardware、non-human principal、sudo、group identity、location/behavior clues、完整官方 References;未额外保留原文不存在的 challenge-response 章节。

关键结论

  • Authentication 建立 identity;authorization 决定 identity 是否拥有某项 access。
  • OS 需要把经过验证的 identity 放进受保护的 process/credential state。
  • process inheritance 简化了身份传播,但不能取代 login 时的可信认证。
  • password security 同时受 human choice、online defense、database protection 和 KDF 参数影响。
  • MFA 的 factor 应来自不同类别,并配合 enrollment、revocation 和 recovery policy。

官方总结的完整身份链路是:系统在 boot 时启动一个负责认证用户的 trusted process;用户提供一种或多种 authentication information,系统验证后把 identity 赋给新的 user process;该 process 再启动其他 process,并通常通过 parent-child inheritance 传播 identity。只有经过保护的机制才能改变 process identity 或让 process 代表另一个 principal。这个链路解释了为什么 authentication 是后续 security policy 的起点,而不是一次孤立的 login 操作。

与已有笔记的关系

参考资料

← 返回列表
← 上一篇 OSTEP:Virtual Machine Monitors 下一篇 → OSTEP:Access Control

评论 (0)

暂无评论,来留下第一条吧。
登录 或 注册 后才能发表评论