跳到主要内容

保护应用与数据

AP 网络安全 · 知识点 5

5.1

应用与数据的漏洞与攻击

教学大纲

学习目标 5.1.A: 解释攻击者如何利用应用和文件漏洞造成丢失、损坏、中断或破坏。

  • 5.1.A.1 如果攻击者能够访问存储文件的设备或驱动器,他们就可以读取任何未加密的文件。
  • 5.1.A.2 计算机拥有标准用户和管理员用户。管理员用户可以访问并控制系统设置,通常可以访问系统中的任何文件或应用程序。如果普通用户被赋予了计算机的管理员权限,且攻击者能够攻破该用户的账户,那么攻击者将在系统中获得提升的权限。
  • 5.1.A.3 当访问控制设置配置较弱时,许多用户往往拥有查看系统上文件甚至编辑文件的权限。攻击者可以利用弱访问控制设置来窃取或销毁文件,或者干扰应用程序的运行。

学习目标 5.1.B: 解释应用攻击如何利用漏洞。

  • 5.1.B.1 应用程序是在计算机上运行指令的程序;它们是可执行数据。一些应用程序在用户的计算机上本地运行,而其他应用程序(如 Web 应用程序)则在服务器上运行,用户通过网络进行访问。
  • 5.1.B.2 许多应用程序通过开放式输入字段接收用户输入,用户可以在其中键入字符(例如字母、数字、标点符号)。开发者应在其应用程序中包含用户输入检查,例如在要求输入项目数量时限制为数字输入,以确保用户输入符合预期;应用程序应拒绝超出预期参数的输入。这种在处理用户输入之前验证其是否符合预期标准的过程称为数据验证。未能对用户输入进行验证的应用程序容易受到注入类攻击,即攻击者在输入字段中插入意外的字符串以改变程序的行为。
  • 5.1.B.3 结构化查询语言 (SQL) 是一种用于从数据库请求信息以及修改数据库或数据库中条目的计算机语言。使用未经验证或未清理的用户输入查询数据库的应用程序存在漏洞。
  • 5.1.B.4 SQL 注入攻击将 SQL 命令和控制字符放置在应用程序的用户输入字段中,这可能导致机密性泄露(使应用程序返回比预期更多的信息),或导致完整性受损(修改或删除数据库中的数据)。
  • 5.1.B.5 网站是使用超文本标记语言 (HTML) 编写的,许多网站使用 JavaScript 在网站上创建动态内容或 Web 应用程序。由于 JavaScript 命令在访问网站的用户的浏览器中运行,这些命令可以访问存储在浏览器中的敏感数据,如用户名、密码和加密密钥。
  • 5.1.B.6 跨站脚本 (XSS) 攻击向网站注入恶意代码,随后由用户的浏览器执行。恶意代码可以嵌入在用户点击的链接中(类型 I 或反射型 XSS 攻击),或者可以通过评论框、论坛帖子或访客日志插入到网站上,这将影响任何访问该网站的用户(类型 II 或存储型 XSS 攻击)。
  • 5.1.B.7 当应用程序接收用户输入时,该输入会被写入缓冲区。缓冲区是计算机内存中具有固定大小的指定区域。如果用户输入的数据量超过缓冲区的大小,它可能会溢出到相邻的内存位置并覆盖计算机内存的其他部分。
  • 5.1.B.8 缓冲区溢出攻击向内存中输入了超过分配量的数据,这可能导致系统崩溃或在程序安全策略范围之外执行代码,从而有效地允许攻击者在计算机上执行未经授权的操作,例如访问、修改或删除文件。
  • 5.1.B.9 运行 Web 应用程序的文件存储在服务器的目录中。当用户访问 Web 应用程序时,他们的浏览器会使用超文本传输协议 (HTTP) 发送 GET 请求。GET 请求会访问服务器文件系统中的某个文件。
  • 5.1.B.10 在目录遍历攻击中,攻击者修改 URL 和 GET 请求,试图访问服务器文件系统中的敏感数据(例如用户名和密码)。
    • 5.1.B.10 示例:
  • 一个Web服务器将其托管的网站中的图像存储在/var/www/images/目录中。攻击者修改了请求图像的URL为../../../etc/passwd。..在文件系统中向上移动一级;因此,三个连续的..返回到根路径,攻击者试图访问passwd文件,该文件将返回设备上所有授权用户名的列表。

学习目标 5.1.C: 评估和记录来自应用与数据漏洞的风险。

  • 5.1.C.1 数据安全风险可能涉及机密性被破坏(未经授权的人员可以访问敏感数据)、完整性受损(数据可能被操纵或从其预期状态被更改)以及可用性丧失(数据可能被销毁或加密以防止他人访问)。
  • 5.1.C.2 高数据漏洞风险通常涉及高度敏感的数据(例如受法律或法规管辖的数据),这些数据可能通过极高概率的攻击向量遭到破坏。
    • 5.1.C.2 示例:
      • 开发下一代喷气式发动机(将用于空军飞机)的公司将发动机的技术规格存储在未加密的驱动器上。
  • 5.1.C.3 中等数据漏洞风险通常涉及敏感数据缺乏足够强的加密或不够严格的访问控制。
    • 5.1.C.3 示例:
      • 一家公司将客户的个人身份信息 (PII) 存储在电子表格中,而该电子表格使用的是短密钥进行的加密。
  • 5.1.C.4 低数据漏洞风险通常涉及较不敏感的信息使用较短的密钥进行加密,或者访问控制不够严格。
    • 5.1.C.4 示例:
      • 某组织的 CEO 将他写给高管团队的私人备忘录存储在公司的共享驱动器上,该驱动器未加密且没有任何访问控制。

来源:College Board AP 课程与考试说明

English
SQL injection

Applications 应用程序 are the programs that run on computers, and data is what they process - both are prime targets. If files are stored unencrypted, anyone with access to the drive can read them. If a normal user is given administrative 管理性 privileges, an adversary who steals that account gains sweeping power.

The biggest application danger is bad user input. When a program does not check what a user types, an adversary can slip in commands - an injection attack 注入攻击. Data validation 数据验证 (checking input meets expected rules) is the defense. Key attacks:

  • SQL injection SQL注入 - inserting SQL commands into an input field to read or change a database.
  • Cross-site scripting (XSS) 跨站脚本 - injecting malicious script into a website that runs in another user's browser.

What a SQL injection actually looks like

SQL is a language for querying a database, and its control words are conventionally written in capital letters (SQL itself ignores their case, so select works too) — SELECT, FROM, WHERE, IN, OR, AND. A login form usually builds a query by pasting what you typed into one:

SELECT * FROM users WHERE name = 'alice' AND password = 'secret'

An attacker types SQL into the field instead of a name. Two tricks do most of the damage:

  • A condition that is always true. In the password field of the unsafe query shown, entering ' OR '1'='1 changes its logic to (name = 'alice' AND password = '') OR '1'='1', which is true for every row. The same text in the name field does not automatically bypass the remaining password check.
  • A double dash, which begins a comment in SQL. Entering admin' -- ends the name string and comments out the whole rest of the line, including the password check, so the query becomes … WHERE name = 'admin' and the attacker is logged in as the administrator without a password.

The defence is not to filter for the word SELECT. It is to stop the input being treated as code at all: use parameterised queries 参数化查询 (also called prepared statements), where the database is given the query and the values separately and never mixes them, and add input validation to reject characters the field has no reason to contain.

  • Buffer overflow 缓冲区溢出 - sending more data than a memory buffer 缓冲区 can hold, so it overflows into nearby memory and may run the adversary's code.
  • Directory traversal 目录遍历 - using ../ sequences in a URL to reach files outside the intended folder, such as /etc/passwd.

Rate data risk using both likelihood and impact. Sensitivity, exposure, access controls, encryption and credible threats matter; low-value data or a short key alone does not determine a fixed risk rating.

SQL injection: input pasted into a query changes the query itself
SQL injection: input pasted into a query changes the query itself
词汇 训练
English 中文 拼音
Applications/ˌæplɪˈkeɪʃnz/ 应用程序 yìng yòng chéng xù
administrative/ədˈmɪnɪstrətɪv/ 管理性 guǎn lǐ xìng
injection attack/ɪnˈdʒekʃn əˈtæk/ 注入攻击 zhù rù gōng jī
Data validation/ˈdeɪtə ˌvælɪˈdeɪʃn/ 数据验证 shù jù yàn zhèng
Cross-site scripting (XSS)/krɒs saɪt ˈskrɪptɪŋ/ 跨站脚本 kuà zhàn jiǎo běn
parameterised queries/ˌpærəˈmetəraɪzd ˈkwɪərɪz/ 参数化查询 cān shù huà chá xún
Buffer overflow/ˈbʌfə ˌəʊvəˈfləʊ/ 缓冲区溢出 huǎn chōng qū yì chū
buffer/ˈbʌfə/ 缓冲区 huǎn chōng qū
Directory traversal/daɪˈrektəri træˈvɜːsl/ 目录遍历 mù lù biàn lì
SQL injection/ˌes kjuː ˈel ɪnˈdʒekʃn/ SQL注入 SQL zhù rù
5.2

保护应用与数据:管理性控制与访问控制

教学大纲

学习目标 5.2.A: 解释数据的状态或分类如何影响应用于该数据的类型和程度的安全性。

  • 5.2.A.1 组织根据其所收集、存储、处理和传输的数据类型实施特定的安全控制措施,以符合法律要求。
  • 5.2.A.2 数据可以根据其状态进行分类。
    • 静态数据(Data at rest)存储在驱动器上。重要的是要保护存储数据的物理驱动器免受破坏或盗窃。静态数据也可以进行加密,以便如果对手窃取它,他们无法立即读取数据。
    • 传输中数据(Data in transit)正在从一个设备发送到另一个设备。如果数据通过物理介质(例如电缆)传输,重要的是要保护该介质。传输中数据也可以进行加密,以便如果对手拦截它,他们无法立即读取数据。
    • 使用中数据(Data in use)正在由软件或人员处理。可以使用访问控制来限制谁或什么能够以不同方式使用使用中数据(例如查看或编辑)。数据必须解密才能被使用。
  • 5.2.A.3 组织通常根据数据的敏感性对数据进行分类,并为更敏感的信息优先考虑更高程度的安全性。
  • 5.2.A.4 法律法规可能要求某些类型的数据按照特定规则进行存储、传输和处理。
    • 个人身份信息(PII)是任何允许识别某人的数据,包括但不限于:姓名、签名、电话号码、地址、生物特征数据(例如指纹)、社会安全号码、出生日期和电子邮件地址。这些数据受许多法律保护,其中最著名的是《1974年隐私法》以及针对13岁以下儿童的《1998年儿童在线隐私保护法》。
    • 受保护的医疗信息(PHI)是与个人健康、治疗、任何时间的医疗保健付款相关的任何数据,包括但不限于:测试结果、治疗记录、医院记录、医生就诊笔记和健康提供者付款记录。PHI的保护包含在《1996年健康保险流通与责任法案》中。
    • 支付卡信息(PCI)是组织为通过卡片(例如信用卡)处理支付而收集的数据,包括以下内容:姓名、账号、有效期、地址和CVV代码。这些数据的安全受《支付卡行业数据安全标准》(PCI-DSS)监管。
  • 5.2.A.5 收集受监管数据的组织将对这些数据进行标记,并制定符合这些数据安全存储、传输和处理的法律或监管要求的政策。

学习目标 5.2.B: 识别与应用程序和数据安全管理相关的控制措施。

  • 5.2.B.1 加密政策将描述组织可接受的加密协议和密钥参数,可能包括:
    • 批准用于特定用途的加密算法列表
    • 最小或最大密钥长度
    • 加密密钥生成要求和参数
    • 加密密钥存储要求
  • 5.2.B.2 Web应用程序安全政策将概述组织中测试和缓解Web应用程序漏洞的要求和参数,可能包括:
    • 应用程序接受安全评估的条件参数
    • 基于风险级别的漏洞修复时间表
    • 如何执行应用程序安全评估的参数(例如,使用特定工具或按照特定框架)

学习目标 5.2.C: 确定适当的访问控制模型以保护应用程序和数据。

  • 5.2.C.1 访问控制强制执行哪些用户或应用程序(称为主体)可以访问、修改、添加或删除(称为操作)哪些文件或应用程序(称为对象)。访问控制模型描述了如何确定哪些主体对哪些对象具有何种类型的访问权限。
  • 5.2.C.2 基于角色的访问控制(RBAC)将每个主体分配到一个角色,并定义哪些角色对哪些对象具有何种类型的访问权限。
    • 5.2.C.2 的说明性示例:
      • 公司中的一个角色示例可能是“会计师”,一种对象示例可能是工资单软件。基于角色的访问可用于确保只有被分配给“会计师”角色的主体才能访问工资单软件对象。
  • 5.2.C.3 基于规则的访问控制(RuBAC)检查一组规则以确定主体对特定对象应具有何种类型的访问权限,然后根据规则允许或拒绝访问类型。此访问控制模型通常叠加在另一种访问控制模型之上。
    • 5.2.C.3 的说明性示例:
      • 有一条规则禁止主体(即使那些通常有访问权限的主体)在非本地工作时间访问某个数据库(对象)。当主体尝试访问数据库时,即使他们有权访问它,如果在规则规定的时间之外,他们将被拒绝访问。
  • 5.2.C.4 自主访问控制(DAC)赋予个体主体设置其他主体对其拥有对象的访问类型的权利。在DAC模型中,某些主体被指定为管理员或超级用户,他们有权覆盖其他主体建立的访问控制。
    • 5.2.C.4 的说明性示例:
      • Bob创建了一个文件(一个对象),并决定给予Alice编辑文件的权限,给予Frank仅查看文件的权限,并拒绝其他人访问该文件。
  • 5.2.C.5 强制访问控制(MAC)遵循严格的规则,规定每个主体级别对于高于、等于或低于其级别的对象具有何种类型的访问权限。主体和对象级别由外部管理员分配。
  • 5.2.C.6 Bell-LaPadula模型是一种MAC模型,通常由政府机构和军事组织用于控制信息安全。该模型具有以下两个重要属性:
    • i. 简单安全属性规定主体不得读取高于其级别的对象。
    • ii. *(星号)安全属性规定主体不得写入低于其级别的对象。
    • 这些规则合在一起通常总结为“向上写,向下读”(WURD)。
  • 5.2.C.7 最小特权原则是指实体应仅获得执行其功能所需的精确访问权限,不多也不少。

学习目标 5.2.D: 配置基于Linux系统的访问控制设置。

  • 5.2.D.1 授权是指授予实体对资源具有某种类型访问权限的许可。实施访问控制是为了控制哪些用户对哪些数据具有何种类型的访问权限。
  • 5.2.D.2 Linux中有三种可以设置的文件访问类型,它们始终按以下顺序排列:
    • i. 读取访问权限允许用户查看文件内容。
    • ii. 写入访问权限允许用户对文件进行修改。
    • iii. 执行访问权限允许用户运行二进制文件,如程序。
    • 这些分别缩写为rwx。如果用户只有读取和执行权限(没有写入权限),则显示为r-x。符号“-”表示缺乏该权限。
  • 5.2.D.3 有三个默认实体用于设置权限,且始终按此顺序排列:(1) 文件所有者,(2) 文件组,以及 (3) 所有其他用户。这三组显示时不带空格(例如 rwxrwxrwx)。
  • 5.2.D.4 要查看文件的当前权限设置,请使用命令 ls -l,它将显示默认实体的当前设置。如果权限末尾有一个 + 符号,这意味着为该文件设置了其他权限,可以使用 getfacl 命令查看。
  • 5.2.D.5 要修改文件的权限设置,请使用 chmod 命令。此命令可以与数字方法或符号方法一起使用。
  • 5.2.D.6 要在数字方法中使用 chmod,语法为 chmod ### filename。三个 ### 中的每一个代表上述三个实体之一(所有者、组、其他非组用户)。
    • 第一个 # = 所有者
    • 第二个 # = 组
    • 第三个 # = 其他非组用户
    • 每个实体的权限是通过将授予的访问类型值相加确定的:
    • 0 = 无权限
    • 1 = 执行
    • 2 = 写入
    • 4 = 读取
    • 因此,3 设置为写入和执行,5 设置为读取和执行,6 设置为读取和写入,7 设置为读取、写入和执行。
    • 5.2.D.6 的说明性示例:
      • 命令 chmod 750 test 会将所有者的权限设置为读取、写入和执行,组的权限设置为读取和执行,其他人的权限设置为完全无访问权限。
      • 命令 chmod 543 test 会将所有者的权限设置为读取和执行,组的权限设置为仅读取,其他人的权限设置为写入和执行。
      • 命令 chmod 777 test 会将文件 test 的所有三个实体的权限设置为读取、写入和执行。
  • 5.2.D.7 要在符号方法中使用 chmod,语法为 chmod entity +(or –) permission filename。实体为用户所有者、组和所有其他非组用户。每个实体用单个字母表示。
    • u = 用户所有者
    • g = 组
    • o = 其他
    • a = 所有
    • 可以向任何组合的实体添加或删除权限。
      • = 添加权限
    • – = 删除权限
    • 可以设置的权限是读取、写入和执行。
    • r = 读取
    • w = 写入
    • x = 执行
    • 实体和权限可以在单个命令中组合。要为名为 testfile 的文件为组和用户所有者添加读取和执行权限,命令应为 chmod ug+rx testfile。

来源:College Board AP 课程与考试说明

English

Data is classified by its state - at rest 静态数据 (stored on a drive), in transit 传输中数据 (moving between devices), and in use 使用中数据 (being processed). Data at rest and in transit can be encrypted so a thief cannot read it; conventional processing normally decrypts data in use, so access controls and protection of memory and execution are also needed.

Some data types are regulated 受监管 - the law dictates how they must be stored, transmitted and handled - so an organisation must achieve compliance 合规 by matching its controls to the rules. The course pairs these data types with example U.S. legal frameworks or industry standards. Their scope matters; these are not universal one-to-one rules:

Data type What it is Example framework and scope
personally identifiable information (PII) 个人身份信息 information identifying or linked to a person Privacy Act: U.S. federal-agency records; COPPA: covered online collection from children under 13
protected health information (PHI) 受保护健康信息 identifiable health information in covered contexts HIPAA: covered entities and business associates, with defined scope and exclusions
payment card information (PCI) 支付卡信息 payment-card account and authentication data PCI DSS: an industry security standard for relevant card-data environments

An organisation that collects regulated data must label it and hold policies that keep its storage, transmission and handling compliant - the higher the sensitivity, the higher the required degree of security.

Access control decides which subjects (users) may perform which operations on which objects (files). Four models:

  • Role-based (RBAC) 基于角色的访问控制 - access follows your role (all "accountants" reach the payroll software).
  • Rule-based (RuBAC) 基于规则的访问控制 - access follows conditions (only during business hours), layered on another model.
  • Discretionary (DAC) 自主访问控制 - the owner of a file decides who else may use it.
  • Mandatory (MAC) 强制访问控制 - a central administrator sets strict levels; the Bell-LaPadula model summarises it as "write up, read down".
Four access-control models decide who reaches which object, and how
Four access-control models decide who reaches which object, and how

A guiding idea across all models is the principle of least privilege 最小权限原则 - give each entity exactly the access it needs and no more.

On a Linux system, each file has three permissions - read (r), write (w), execute (x) - for three groups: the owner, the group, and others. The chmod command sets them with numbers, adding 4 (read) + 2 (write) + 1 (execute). So chmod 640 means owner read+write (6), group read (4), others nothing (0).

Linux file permissions: read/write/execute for owner, group, and others
Linux file permissions: read/write/execute for owner, group, and others

Worked example. A principal wants only herself to read and edit a file, her staff group to read it, and no one else to touch it. Read+write = 4+2 = 6 for the owner, read = 4 for the group, nothing = 0 for others, giving chmod 640 file. The listing then shows -rw-r-----. To also let the owner run the file as a program you would add execute (7 = 4+2+1), giving chmod 740.

探索

哪种访问控制模型符合该规则?

每种访问控制模型都有不同的决定者:RBAC(基于角色的访问控制)由你的角色决定,RuBAC(基于规则的访问控制)由条件决定,DAC(自主访问控制)由文件的所有者决定,而MAC(强制访问控制)由中央管理员的级别决定。

词汇 训练
English 中文 拼音
at rest/æt rest/ 静态数据 jìng tài shù jù
in transit/ɪn ˈtrænsɪt/ 传输中数据 chuán shū zhōng shù jù
in use/ɪn juːs/ 使用中数据 shǐ yòng zhōng shù jù
regulated/ˈreɡjʊleɪtɪd/ 受监管 shòu jiān guǎn
compliance/kəmˈplaɪəns/ 合规 hé guī
personally identifiable information (PII)/ˈpɜːsənəli aɪˈdentɪfaɪəbl ˌɪnfəˈmeɪʃn/ 个人身份信息 gè rén shēn fèn xìn xī
protected health information (PHI)/prəˈtektɪd helθ ˌɪnfəˈmeɪʃn/ 受保护健康信息 shòu bǎo hù jiàn kāng xìn xī
payment card information (PCI)/ˈpeɪmənt kɑːd ˌɪnfəˈmeɪʃn/ 支付卡信息 zhī fù kǎ xìn xī
Role-based (RBAC)/rəʊl beɪst/ 基于角色的访问控制 jī yú jué sè de fǎng wèn kòng zhì
Rule-based (RuBAC)/ruːl beɪst/ 基于规则的访问控制 jī yú guī zé de fǎng wèn kòng zhì
Discretionary (DAC)/dɪˈskreʃənəri/ 自主访问控制 zì zhǔ fǎng wèn kòng zhì
Mandatory (MAC)/ˈmændətəri/ 强制访问控制 qiáng zhì fǎng wèn kòng zhì
principle of least privilege/ˈprɪnsɪpl ɒv liːst ˈprɪvɪlɪdʒ/ 最小权限原则 zuì xiǎo quán xiàn yuán zé
5.3

用密码学保护存储的数据

教学大纲

学习目标 5.3.A: 解释如何使用加密来保护文件。

  • 5.3.A.1 密码学的目的是隐藏信息。密码算法定义了加密和解密信息的过程。加密是隐藏信息的过程,解密是逆转加密以检索原始信息的过程。
  • 5.3.A.2 加密算法定义了将待加密信息与预定义密钥结合的过程。待加密的信息称为明文。加密算法的输出称为密文。
  • 5.3.A.3 可用于加密算法的可能密钥数量称为密钥空间。密钥空间越大,对手通过随机猜测发现正确密钥所需的时间就越长。
  • 5.3.A.4 根据使用一个密钥还是两个密钥,对密码算法进行分类。
    • 对称加密算法使用相同的密钥来加密和解密信息。
    • 非对称加密算法使用两个不同的密钥——一个用于加密信息,另一个用于解密信息。
  • 5.3.A.5 根据是一次处理一位信息还是以固定大小的位块处理信息,对密码算法进行分类。
    • 分组加密以称为分组的固定大小块处理信息,为每个输入块产生一个输出块。
    • 流式加密连续处理输入信息,一次产生一个元素作为输出。

学习目标 5.3.B: 应用对称加密算法来加密和解密数据。

  • 5.3.B.1 基于计算机的加密算法在二进制数据上运行。最常见的对称加密算法是高级加密标准 (AES)。AES 加密用于保护 Wi-Fi 传输、互联网浏览、磁盘上的文件加密以及处理器层面的硬件加密。
  • 5.3.B.2 AES 是一种对称密钥分组密码,它以 128 位块(16 字节)加密数据。AES 可以使用不同长度的密钥进行操作。较长的密钥会产生更安全的加密,但需要更多的时间来加密和解密。
  • 5.3.B.3 可以使用命令行、专用软件或基于 Web 的工具执行对称加密和解密。
    • 在命令行界面中,用户可以使用 OpenSSL 进行加密或解密。
    • 像 AES Crypt 这样的专用软件是一个开源工具,可以加密和解密文件。
    • 有许多基于 Web 的工具用于加密和解密文件。
  • 5.3.B.4 在 CLI 中使用 OpenSSL,用户可以使用以下命令加密和解密文件(注意:加密密钥是从提供的密码派生的):
    • 要使用 128 位密钥通过 AES 加密名为 test 的文件,请使用命令:openssl enc -aes-128-cbc -e -in test -k password -out test.enc
    • 要使用相同密钥解密密文文件,请使用命令:openssl enc -aes-128-cbc -d -in test.enc -k password -out text

来源:College Board AP 课程与考试说明

English
An Enigma machine: cryptography protects stored and transmitted data from eavesdroppers
An Enigma machine: cryptography protects stored and transmitted data from eavesdroppers
Symmetric vs asymmetric encryption
Hashing and the avalanche effect

Cryptography 密码学 uses mathematical techniques to protect information and support checks such as authenticity and integrity. An encryption algorithm combines the plaintext 明文 with a key 密钥 to produce ciphertext 密文; decryption reverses it. The keyspace 密钥空间 is the set of possible keys. A fully variable n-bit key has $2^n$ possible values. A larger space can increase exhaustive-search work, but practical security also depends on the algorithm and implementation.

Symmetric encryption 对称加密 uses the same key to encrypt and decrypt. The standard is AES 高级加密标准, a block cipher 分组密码 that works on 128-bit blocks and secures Wi-Fi, browsing, and stored files. Because both sides need the same secret key, sharing that key safely is the challenge.

A World War II Enigma cipher machine with keys and rotors
The Enigma machine scrambled messages with rotors — an early, breakable example of encryption
探索

通过移位字母来加密消息

加密是将明文与密钥结合以生成密文的过程。在此简单密码中,密钥即为移位量;只有知道移位量的人才能将消息解密回原文。

词汇 训练
English 中文 拼音
Cryptography/krɪpˈtɒɡrəfi/ 密码学 mì mǎ xué
plaintext/ˈpleɪntekst/ 明文 míng wén
key/kiː/ 密钥 mì yào
ciphertext/ˈsaɪfətekst/ 密文 mì wén
keyspace/ˈkiːspeɪs/ 密钥空间 mì yào kōng jiān
Symmetric encryption/sɪˈmetrɪk enˈkrɪpʃn/ 对称加密 duì chèn jiā mì
AES/ˌeɪ iː ˈes/ 高级加密标准 gāo jí jiā mì biāo zhǔn
block cipher/blɒk ˈsaɪfə/ 分组密码 fēn zǔ mì mǎ
5.4

非对称密码学

教学大纲

学习目标 5.4.A: 确定在发送或接收加密数据时使用的适当非对称密钥。

  • 5.4.A.1 非对称加密允许用户在不预先安排共享密钥的情况下进行安全通信。
  • 5.4.A.2 在使用非对称加密时,每个接收数据的实体必须首先生成一对密钥。密钥对是通过数学过程同时生成的等长二进制字符串。其中一个密钥被指定为公钥,另一个被指定为私钥。这两个密钥互为数学逆元——每个密钥都能反转其配对密钥的操作。任一密钥均可用于加密信息,但只有密钥对中的另一个密钥才能对其进行解密。
  • 5.4.A.3 一旦接收方生成密钥对,私钥必须安全存储。如果私钥泄露、共享、被盗、损坏或受到损害,则必须删除该密钥对并生成新的密钥对,因为加密算法的安全性依赖于私钥的安全性。公钥则发布供任何人查看和使用。
  • 5.4.A.4 要安全地向某人发送信息,发送方将使用接收方的公钥对数据进行加密并发送。只有拥有私钥的接收方才能够解密并阅读该信息。

学习目标 5.4.B: 解释密钥长度如何影响加密数据的安全性。

  • 5.4.B.1 更长的密钥会导致更大的密钥空间。对于二进制密钥,n位长度的密钥具有 $2^n$ 的密钥空间。
  • 5.4.B.2 使用应用程序随机猜测一个 n 位长度的加密密钥意味着,平均而言,攻击者将在 $2^n \div 2$(或 $2^{n-1}$)次尝试后猜中正确的密钥。
  • 5.4.B.3 虽然更长的密钥更安全,但它们也需要更多的时间来加密和解密消息。
  • 5.4.B.4 计算处理能力和效率不断提高,使得软件能够更快地猜测密钥。为了应对处理能力的提升,对称和非对称加密算法的密钥长度建议会定期增加。
  • 5.4.B.5 密钥长度的比较仅在比较同一密码算法的密钥时才有效。
    • 5.4.B.5 的说明示例:
      • AES 256 位密钥比 AES 128 位密钥更安全。
      • RSA 4096 位密钥比 RSA 2048 位密钥更安全。
      • 在确定安全级别时,RSA 和 AES 密钥不能直接相互比较。

学习目标 5.4.C: 应用非对称加密算法对数据进行加密和解密。

  • 5.4.C.1 常见的非对称加密算法包括 RSA 和椭圆曲线密码学 (ECC)。非对称算法广泛应用于许多应用中,包括数字签名和数字证书。
  • 5.4.C.2 与对称加密一样,非对称加密和解密可以使用命令行、专用软件或基于 Web 的工具执行。
    • 在命令行界面中,用户可以使用 OpenSSL 进行加密或解密。
    • 像 RSA Encryption Tool 这样的专用软件是一个开源工具,可以加密和解密文件。
    • 有许多基于 Web 的工具用于加密和解密文件。
  • 5.4.C.3 在 CLI 中,用户可以生成非对称密钥对,并根据需要加密或解密文件。
    • 要生成一个 2048 位的 RSA 密钥对并将密钥保存到名为 rsa.pem 的文件中,请使用命令:openssl genrsa -out rsa.pem 2048
    • 要从 rsa.pem 中提取公钥到名为 public.pem 的文件中,请使用命令:openssl rsa -pubout -in rsa.pem -outform PEM -out public.pem
    • 要使用 RSA 加密和密钥文件 public.pem 加密文件 test,请使用命令:openssl pkeyutl -encrypt -pubin -inkey public.pem -in test -out test.enc
    • 要使用 rsa.pem 文件解密 test.enc 文件,请运行命令:openssl pkeyutl -decrypt -inkey rsa.pem -in test.enc -out test

来源:College Board AP 课程与考试说明

English

Asymmetric encryption 非对称加密 solves the key-sharing problem with a key pair 密钥对 - a public key 公钥 anyone may see and a private key 私钥 kept secret. Each scheme specifies how its keys are used. For public-key encryption, I encrypt with your public key and you decrypt with your private key. Digital signatures use a private signing key and public verification key; signing is not generally “encrypting with the private key”. The sender must also establish that the public key really belongs to the intended recipient.

Asymmetric encryption: encrypt with the public key, decrypt with the private key
Asymmetric encryption: encrypt with the public key, decrypt with the private key

Longer keys mean larger keyspaces and more security, but slower encryption. Common asymmetric algorithms are RSA and elliptic curve cryptography (ECC) 椭圆曲线密码学, used in digital signatures and certificates. Remember: you can only compare key lengths within the same algorithm - an RSA 4096-bit key is not directly comparable to an AES 256-bit key.

A padlock: cryptography locks data so only someone with the matching key can open it
A padlock: cryptography locks data so only someone with the matching key can open it
词汇 训练
English 中文 拼音
Asymmetric encryption/ˌeɪsɪˈmetrɪk enˈkrɪpʃn/ 非对称加密 fēi duì chèn jiā mì
key pair/kiː peə/ 密钥对 mì yào duì
public key/ˈpʌblɪk kiː/ 公钥 gōng yào
private key/ˈpraɪvət kiː/ 私钥 sī yào
elliptic curve cryptography (ECC)/ɪˈlɪptɪk kɜːv krɪpˈtɒɡrəfi/ 椭圆曲线密码学 tuǒ yuán qū xiàn mì mǎ xué
5.5

保护应用

教学大纲

学习目标 5.5.A: 识别“安全设计”(Secure by Design)和“默认安全”(Security by Default)的应用程序安全原则。

  • 5.5.A.1 “安全设计”是一项倡议,鼓励企业在产品开发的各个阶段(包括设计阶段)纳入安全性。当组织实施“安全设计”时,安全性不仅是一个技术功能,更是一种设计原则。
  • 5.5.A.2 “安全设计”包含三个设计原则:
    • i. 企业应对客户的安全结果负责。企业应构建满足客户安全需求的产品。
    • ii. 企业应拥抱彻底的透明度和问责制。快速分享与产品相关的安全新闻和更新可以迅速提升所有人的安全性。
    • iii. 企业应建立组织架构和领导层来实施“安全设计”。企业需要有专注于安全且具有“安全优先”立场的领导者。
  • 5.5.A.3 “安全设计”包含“默认安全”的概念,即软件和设备的安全功能应以默认状态启用。设备和软件开箱即用时应具备安全性,且安全功能已预先开启。

学习目标 5.5.B: 解释用户输入清理如何保护应用程序。

  • 5.5.B.1 当用户在应用程序中输入内容时,应用程序通常会将该输入包裹在特殊字符中以进行处理。这些包裹用户输入的字符称为控制字符,包括单引号、双引号和分号。
  • 5.5.B.2 在创建接收用户输入的程序时,程序员应使用函数来验证用户输入是否符合预期标准,且不包含任何可用于操纵系统的控制字符。该验证函数可以通过移除潜在恶意字符来清理用户输入,或者向用户返回错误并强制用户提供不同的输入。这可以防御多种应用程序攻击,包括:
    • SQL注入攻击
    • XSS攻击
    • 目录遍历攻击

来源:College Board AP 课程与考试说明

English

Two design principles keep applications safe from the start. Secure by design 安全设计 builds security into every phase of development, not as an afterthought. Secure by default 默认安全 means the product ships with its security features already enabled - safe straight out of the box.

Secure by design rests on three principles a company must adopt: (1) take ownership of its customers' security outcomes rather than shifting blame onto users, (2) embrace radical transparency and accountability – sharing security-relevant news and updates quickly so everyone becomes safer, and (3) build the organisational structure and leadership that makes security a first-class goal.

Input sanitization 输入清理 transforms input for a specific destination; validation checks an allowed type, length, range or format. Quotes and semicolons are printable special characters 特殊字符, not necessarily control characters. A legitimate name such as O'Neill should remain intact. A single blacklist is not a universal defense: SQL injection needs parameterised queries with separately bound values; XSS needs safe text rendering or output encoding for the destination context (and a suitable HTML sanitizer when HTML is allowed); directory traversal needs resolved paths confined to an allowed directory. For example, 0 OR 1=1 can change an unsafe numeric SQL expression without using quotes or semicolons. Use fixed SQL such as SELECT name FROM pupils WHERE name = ? and bind the entered name separately.

Building security into every stage of an application's life cycle
Building security into every stage of an application's life cycle
词汇 训练
English 中文 拼音
Secure by design/sɪˈkjʊə baɪ dɪˈzaɪn/ 安全设计 ān quán shè jì
Secure by default/sɪˈkjʊə baɪ dɪˈfɒlt/ 默认安全 mò rèn ān quán
input sanitization/ˈɪnpʊt ˌsænɪtaɪˈzeɪʃn/ 输入清理 shū rù qīng lǐ
special characters/ˈspeʃl ˈkærɪktəz/ 特殊字符 tè shū zì fú
5.6

检测应用与数据攻击

教学大纲

学习目标 5.6.A: 解释如何检测对数据的攻击。

  • 5.6.A.1 设备会跟踪并记录数据被访问的时间以及访问者身份。记录和监控用户活动的过程称为审计(accounting)。分析这些日志可以揭示当对手试图访问、复制、移动或删除数据时的恶意活动。可疑活动包括:
    • 访问通常不会访问的文件
    • 在用户正常模式之外(包括一天中的时间、位置和设备安装类型)访问文件或应用程序
    • 尝试删除或复制敏感文件
  • 5.6.A.2 蜜罐(honeypot)是一个看似包含有价值数据(例如信用卡信息、个人身份信息 PII、密码)的文件,但其中的数据是伪造的。如果有人尝试访问蜜罐,系统可以向防御者发出警报。由于蜜罐是一个假文件,没有任何合法理由去访问它,因此任何尝试访问的行为都将是恶意活动的指标。
  • 5.6.A.3 密码学哈希函数可以为数据生成摘要,并能揭示数据是否已被篡改。如果文件发生意外更改,这可能是恶意活动的迹象。

学习目标 5.6.B: 确定用于检测针对应用程序或数据攻击的控制措施。

  • 5.6.B.1 成本是确定检测性控制措施的一个标准。像蜜罐和使用哈希值检查数据完整性这样的检测性控制措施成本较低。一些组织投资于第三方数据防泄漏(DLP)服务,这些服务在整个组织中监控用户的数据访问、使用和传输,以检测可疑活动;DLP 服务提供强大的检测能力,但成本较高。
  • 5.6.B.2 数据或应用程序的敏感性或关键性是确定检测性控制措施的一个标准。更敏感或关键的数据或应用程序更容易成为对手的目标,应受到更密切的监控。
  • 5.6.B.3 数据分类是确定检测性控制措施的一个标准。被分类为私人、教育、医疗或金融的数据通常具有法律或监管方面的检测和监控要求。

学习目标 5.6.C: 评估检测针对应用程序或数据攻击的方法的影响。

  • 5.6.C.1 为了以有效速度运行,日志分析需要辅以某些自动化技术。蜜罐提供近乎即时的检测能力。
  • 5.6.C.2 某些 DLP 工具、蜜罐和实时自动日志分析会在攻击发生时提供警报。这些工具允许迅速响应,从而在攻击造成更大危害之前阻止攻击。事后日志分析和使用密码学哈希验证数据完整性只能在攻击发生后识别攻击。
  • 5.6.C.3 在应用程序和数据攻击检测中可能会出现假阴性。密码学哈希函数仅能检测数据是否被篡改。对手可以在不篡改数据的情况下查看并窃取数据,而密码学哈希函数无法检测到这一点。蜜罐无法检测那些不尝试访问它的对手。

学习目标 5.6.D: 通过验证文件的哈希值来识别文件是否已被篡改。

  • 5.6.D.1 密码学哈希函数可以帮助识别文件中的更改,因为它们是可重复的:对于给定的哈希函数,相同的输入始终产生相同的输出。
  • 5.6.D.2 可以使用计算机上的命令行、网站或专用软件计算哈希值。
    • 在 Windows PowerShell 中,如果用户想要为名为 testfile 的文件生成 SHA256 哈希值,他们将使用命令:Get-FileHash testfile -Algorithm SHA256
    • 在 BASH 中,同样的操作可以通过以下命令完成:sha256sum testfile
    • 在 Apple 电脑上常用的命令行终端 zsh 中,这可以通过以下命令完成:shasum -a 256 testfile
  • 5.6.D.3 可以对文件进行哈希处理并记录其哈希输出。然后在稍后再次对文件进行哈希处理,并将第二次哈希输出与该文件之前的哈希输出进行比较。如果文件的哈希值发生变化,则说明文件在第一次和第二次哈希生成之间已被篡改。

学习目标 5.6.E: 应用检测技术,通过分析日志文件来识别和报告应用程序攻击的指标。

  • 5.6.E.1 SQL 注入攻击可以通过审查应用程序和服务器日志中的用户输入来检测,查找 SQL 控制词和符号,例如:
    • 单引号 (') 或双引号 (")
    • 布尔条件,如 OR 1=1
    • 双破折号(表示 SQL 中的注释):--
    • SQL 控制词(总是大写),如 WHERE, IN, FROM
  • 5.6.E.2 XSS 攻击可以通过审查用户输入中的可疑标签来检测,特别是 标签。
  • 5.6.E.3 对于 Web 应用程序,可以通过检查用户在请求中发送给 Web 应用程序的数据量来检测缓冲区溢出。通常检查的字段包括 URL 长度、Cookie 长度、查询字符串长度和总请求长度。这些字段中的长字符串可能是尝试缓冲区溢出攻击的指标。
  • 5.6.E.4 目录遍历攻击可以通过审查应用程序和服务器日志来检测。包含 ../ 序列路径的 HTTP GET 请求是对手试图进行目录遍历的指标。

来源:College Board AP 课程与考试说明

English

To detect data attacks, systems perform accounting 审计记录 - logging who accessed what and when. But logs are huge, so log analysis must be automated to run at a useful speed; a human reading raw logs is far too slow. A clever complement is a honeypot 蜜罐 - a fake file that looks valuable; unexpected access gives an alert to investigate. Administrators or scanners may also access a decoy, so an alert alone is not proof of an attack. Watch especially for attempts to delete or copy sensitive files. Cryptographic hashes also help: re-hash a file and compare - if the digest changed, the file was altered.

Choosing detective controls means weighing cost (honeypots are cheap; a data loss prevention (DLP) 数据泄露防护 service is powerful but pricey) against the sensitivity of the data. To read a specific attack from logs, look for its signature: SQL injection shows OR 1=1 and --; XSS shows <script> tags; directory traversal shows ../ sequences; a buffer overflow shows unusually long input strings.

Checking that a file has not been altered

A cryptographic hash turns a file of any size into a short fixed-length value. A change normally gives a different digest, but collisions exist. A match to the publisher's trusted full digest is strong evidence that the bytes match, rather than mathematical proof. You do this at the command line:

Shell Command
BASH (Linux, and most servers) sha256sum testfile
zsh, the usual terminal on Apple computers shasum -a 256 testfile

Both print the SHA-256 hash of testfile. If it differs from the published value by even one character, the file has been altered — by corruption in transit, or by an attacker who replaced it.

⚠️ A hash proves integrity, not authenticity. An attacker who can replace the file on a web page can usually replace the published hash beside it too; that is why a signed hash, or one fetched over a separate trusted channel, is stronger evidence.

词汇 训练
English 中文 拼音
accounting/əˈkaʊntɪŋ/ 审计记录 shěn jì jì lù
honeypot/ˈhʌnɪpɒt/ 蜜罐 mì guàn
data loss prevention (DLP)/ˈdeɪtə lɒs prɪˈvenʃn/ 数据泄露防护 shù jù xiè lòu fáng hù
5.6

考试技巧

English
  • Match each application attack to its evidence in a log: OR 1=1 / -- = SQL injection; <script> = XSS; ../ = directory traversal; very long input = buffer overflow.
  • Learn the four access-control models by their decider: RBAC = your role, RuBAC = a condition, DAC = the file's owner, MAC = a central admin. Least privilege underlies them all.
  • Read Linux permissions by adding 4+2+1 per group - chmod 750 = owner rwx (7), group r-x (5), others none (0). Practice converting both ways.
  • Symmetric = one shared key (fast, AES); asymmetric = a public/private key pair (solves key sharing, RSA/ECC). Encrypt with the recipient's public key.
  • Match input defenses to the destination: parameter binding for SQL, context-specific output protection for XSS, and allowed-directory checks for paths. Input sanitization is not one universal character filter; a honeypot is a detective control.

该知识点的互动课程

逐步完成,配合即时检查练习。

历年真题

更多 AP 网络安全 知识点

登录或创建账户

IGCSE, A-Level & AP