界: Code Quality

代码质量不佳会导致不可预测的行为。对于用户来说,通常表现为可用性差。对于攻击者来说,提供了以意外方式对系统施加压力的机会。

Encoding Confusion: BiDi Control Characters

Abstract
源代码中的双向控制字符会导致木马源攻击。
Explanation
包含 Unicode 双向覆盖控制字符的源代码可能是内部威胁攻击的标志。可以通过 C、C++、C#、Go、Java、JavaScript、Python 和 Rust 等编程语言的供应链来利用这种攻击。Nicholas Boucher 和 Ross Anderson 已经发布了多种变体攻击,包括以下几种:Early Return、Commenting-Out 和 Stretched String。
示例 1:以下代码展示了存在于 C 源代码文件中的一种控制字符,该字符会导致 Early Return 攻击:

#include <stdio.h>

int main() {
/* Nothing to see here; newline RLI /*/ return 0 ;
printf("Do we get here?\n");
return 0;
}

Example 1 中,从右到左隔离 (RLI) Unicode 双向控制字符会导致代码如下所示:

#include <stdio.h>

int main() {
/* Nothing to see here; newline; return 0 /*/
printf("Do we get here?\n");
return 0;
}

需要特别注意的是,在易受攻击的编辑器/查看器中执行代码审查的开发人员将看不到易受攻击的编译器将会处理的内容。具体来说是修改程序流的 Early Return 语句。
References
[1] Nicholas Boucher, and R. Anderson Trojan Source: Invisible Vulnerabilities
[2] Standards Mapping - Common Weakness Enumeration CWE ID 451
[3] Standards Mapping - OWASP Top 10 2017 A1 Injection
[4] Standards Mapping - OWASP Top 10 2021 A03 Injection
[5] Standards Mapping - Smart Contract Weakness Classification SWC-130
desc.regex.universal.encoding_confusion_bidi_control_characters