iOS安全编码指南 Secure Coding Guide -- 02 Types of Security Vulnerabilities 上

IOS安全编码指南 Secure Coding Guide -- 02 Types of Security Vulnerabilities 上

Most software security vulnerabilities(|ˌvʌlnərəˈbɪləti|) fall into one of a small set of categories:

  • buffer overflows
  • unvalidated input
  • race conditions
  • access-control problems
  • weaknesses in authentication(|ɔːˌθentɪˈkeɪʃn| n 验证), authorization(|ˌɔːθəraɪˈzeɪʃn| n 授权、批准), or cryptographic([ˌkrɪptə'græfɪk] adj 有关密码的、用密码写的) practices

This chapter describes the nature of each type of vulnerability.



Buffer Overflows

    A buffer overflow occurs when an application attempts to write data past the end (or, occasionally, past the beginning) of a buffer.

          occasional |əˈkeɪʒənl| adjective 偶尔的

          occasionally |əˈkeɪʒənəli| adverb 偶尔

    Buffer overflows can cause applications to crash, can compromise data, and can provide an attack vector for further privilege escalation to compromise the system on which the application is running.

          vector |ˈvektə(r)| n 矢量、向量、航线

          escalation |ˌeskəˈleɪʃn| noun 上涨、加剧、恶化

    Books on software security invariably mention buffer overflows as a major source of vulnerabilities. Exact numbers are hard to come by, but as an indication, approximately 20% of the published exploits reported by the United States Computer Emergency Readiness Team (US-CERT) for 2004 involved buffer overflows.

          invariably |ɪnˈveərɪəbli| adverb 一贯地

          mention |ˈmenʃn| transitive verb 提到 

          approximately |əˈprɒksɪmətli| adverb 大约

          emergency |ɪˈmɜːdʒənsi| noun Uncountable and countable 紧急情况

          readiness |ˈredɪnɪs| noun Uncountable 准备就绪、乐意、敏捷


    Any application or system software that takes input from the user, from a file, or from the network has to store that input, at least temporarily(|ˈtempərəli, American -pərerɪli| 临时). Except in special cases(除了少数特殊情况), most application memory is stored in one of two places:

  • stack—A part of an application’s address space that stores data that is specific to a single call to a particular function, method, block, or other equivalent construct.
  • heap—General purpose storage for an application. Data stored in the heap remains(v 逗留、遗留) available as long as the application is running (or until the application explicitly(|ɪkˈsplɪsɪtli| adv 明确地、坦率地、生) tells the operating system that it no longer needs that data).Class instances, data allocated with malloc, core foundation objects, and most other application data resides(|rɪˈzaɪd| v 居住、属于) on the heap. (Note, however, that the local variables that actually point to the data are stored in the stack.)

    Buffer overflow attacks generally occur by compromising either the stack, the heap, or both. For more information, read Avoiding Buffer Overflows and Underflows



Unvalidated Input

    As a general rule, you should check all input received by your program to make sure that the data is reasonable.

For example, a graphics file can reasonably contain an image that is 200 by 300 pixels, but cannot reasonably contain an image that is 200 by -1 pixels. Nothing prevents a file from claiming(claim |kleɪm| v 声称、要求) to contain such an image, however (apart from(除了) convention(|kənˈvenʃn| n 大会、俗、) and common sense). A naive program attempting to read such a file would attempt to allocate a buffer of an incorrect size, leading to(导致) the potential for a heap overflow attack or other problem. For this reason, you must check your input data carefully. This process is commonly known as input validation or sanity(|ˈsænəti| n 精神正常、通情) checking.

    Any input received by your program from an untrusted source is a potential target for attack. (In this context, an ordinary(|ˈɔːdənri, American ˈɔːrdəneri| adj 普通的、一般的、平庸的) user is an untrusted source.) Examples of input from an untrusted source include (but are not restricted(restrict |rɪˈstrɪkt| v 限制、控制) to):

  • text input fields
  • commands passed through a URL used to launch the program
  • audio, video, or graphics files provided by users or other processes and read by the program
  • command line input(命令行输入)
  • any data read from an untrusted server over a network
  • any untrusted data read from a trusted server over a network (user-submitted HTML or photos on a bulletin board, for example)

    Hackers look at every source of input to the program and attempt to pass in malformed(|ˌmælˈfɔːmd| 畸形的) data of every type they can imagine. If the program crashes or otherwise misbehaves(行为不端、发生故障), the hacker then tries to find a way to exploit the problem. Unvalidated-input exploits have been used to take control of operating systems, steal data, corrupt users’ disks, and more. One such exploit was even used to “jail(监狱) break(越狱)” iPhones.

    Validating Input and Interprocess Communication describes common types of input-validation vulnerabilities and what to do about them.


Race Conditions(竞态条件、竞争条件)

    A race condition exists when changes to the order of two or more events can cause a change in behavior. If the correct order of execution is required for the proper(|ˈprɒpə(r)| adj 合适的、适当的、正确的) functioning of the program, this is a bug. If an attacker can take advantage of the situation to insert malicious code, change a filename, or otherwise interfere(|ˌɪntəˈfɪə(r)| v 插手、妨碍、干涉) with the normal operation of the program, the race condition is a security vulnerability. Attackers can sometimes take advantage of small time gaps(gap |gæp| n 空隙、) in the processing of code to interfere with the sequence(|ˈsiːkwəns| n 一系列、顺序) of operations, which they then exploit.

    For more information about race conditions and how to prevent them, read Race Conditions and Secure File Operations.


Interprocess Communication

    Separate(|ˈsepərət| adj 分开的) processes(进程)—either within a single program(程序) or in two different programs—sometimes have to share information. Common methods include using shared memory or using some messaging protocol, such as Sockets, provided by the operating system. These messaging protocols used for interprocess communication are often vulnerable to attack; thus, when writing an application, you must always assume that the process at the other end of your communication channel could be hostile(|ˈhɒstaɪl, American ˈhɒstl| adj 不友善的、反).

    For more information on how to perform secure interprocess communication, read Validating Input and Interprocess Communication.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值