계: Input Validation and Representation

입력 검증 및 표현 문제는 메타 문자, 대체 인코딩 및 숫자 표현 때문에 발생합니다. 보안 문제는 입력을 신뢰하기 때문에 발생합니다. 문제로는 "Buffer Overflows", "Cross-Site Scripting" 공격, "SQL Injection", 그 외 여러 가지가 있습니다.

Object Injection

Abstract
신뢰할 수 없는 데이터 병렬화는 임의 PHP 개체의 삽입을 허용하여 프로그램이 공격자 대신 악성 명령을 실행하도록 야기할 수 있습니다.
Explanation
Object injection 취약점은 unserialize() 함수로 전달되기 전에 신뢰할 수 없는 데이터가 올바르게 정화되지 않는 경우 발생합니다. 공격자는 취약한 unserialize() 호출에 특히 수동으로 직렬화한 문자열을 전달할 수 있어 응용 프로그램 영역에서 임의 PHP object injection을 야기합니다. 이 취약점의 심각도는 응용 프로그램 영역에서 사용 가능한 클래스에 따라 달라집니다. __wakeup 또는 __destruct 같은 PHP 매직 메서드를 구현하는 클래스는 이러한 메서드 내에서 코드를 수행할 수 있으므로 공격자가 관심을 갖기 쉽습니다.

예제 1: 다음 코드는 __destruct() 매직 메서드를 구현하고 클래스 속성으로 정의된 시스템 명령을 실행하는 PHP 클래스를 보여줍니다. 또한 사용자 공급 데이터가 포함된 unserialize()에 대한 불안정한 호출도 있습니다.


...
class SomeAvailableClass {
public $command=null;
public function __destruct() {
system($this->command);
}
}
...
$user = unserialize($_GET['user']);
...
Example 1에서 응용 프로그램은 직렬화된 User 개체를 예상하지만 공격자는 command 속성을 위해 사전 정의된 값으로 SomeAvailableClass의 직렬화된 버전을 실제로 제공할 수 있습니다.


GET REQUEST: http://server/page.php?user=O:18:"SomeAvailableClass":1:{s:7:"command";s:8:"uname -a";}


소멸자 메서드는 $user 개체에 대한 다른 참조가 없을 때 즉시 호출되며 공격자가 제공한 명령을 실행합니다.

공격자는 취약한 unserialize()가 "속성 지향 프로그래밍"이라는 기술을 사용하여 호출된 경우 선언된 다른 클래스를 연결할 수 있습니다. "속성 지향 프로그래밍"은 BlackHat 2010 컨퍼런스에서 Stefan Esser가 소개한 기술입니다. 이 기술을 통해 공격자는 고유한 페이로드를 만들도록 기존의 코드를 재사용할 수 있습니다.
References
[1] Johannes Dahse, Nikolai Krein, and Thorsten Holz Code Reuse Attacks in PHP: Automated POP Chain Generation
[2] Stefan Esser Utilizing Code Reuse/ROP in PHP Application Exploits
[3] Standards Mapping - CIS Azure Kubernetes Service Benchmark 3.0
[4] Standards Mapping - CIS Microsoft Azure Foundations Benchmark complete
[5] Standards Mapping - CIS Amazon Elastic Kubernetes Service Benchmark 4.0
[6] Standards Mapping - CIS Amazon Web Services Foundations Benchmark 4
[7] Standards Mapping - CIS Google Kubernetes Engine Benchmark integrity
[8] Standards Mapping - CIS Kubernetes Benchmark complete
[9] Standards Mapping - Common Weakness Enumeration CWE ID 502
[10] Standards Mapping - Common Weakness Enumeration Top 25 2019 [23] CWE ID 502
[11] Standards Mapping - Common Weakness Enumeration Top 25 2020 [21] CWE ID 502
[12] Standards Mapping - Common Weakness Enumeration Top 25 2021 [13] CWE ID 502
[13] Standards Mapping - Common Weakness Enumeration Top 25 2022 [12] CWE ID 502
[14] Standards Mapping - Common Weakness Enumeration Top 25 2023 [15] CWE ID 502
[15] Standards Mapping - DISA Control Correlation Identifier Version 2 CCI-002754
[16] Standards Mapping - General Data Protection Regulation (GDPR) Indirect Access to Sensitive Data
[17] Standards Mapping - NIST Special Publication 800-53 Revision 4 SI-10 Information Input Validation (P1)
[18] Standards Mapping - NIST Special Publication 800-53 Revision 5 SI-10 Information Input Validation
[19] Standards Mapping - OWASP Top 10 2004 A6 Injection Flaws
[20] Standards Mapping - OWASP Top 10 2007 A2 Injection Flaws
[21] Standards Mapping - OWASP Top 10 2010 A1 Injection
[22] Standards Mapping - OWASP Top 10 2013 A1 Injection
[23] Standards Mapping - OWASP Top 10 2017 A8 Insecure Deserialization
[24] Standards Mapping - OWASP Top 10 2021 A08 Software and Data Integrity Failures
[25] Standards Mapping - OWASP Application Security Verification Standard 4.0 1.5.2 Input and Output Architectural Requirements (L2 L3), 5.5.1 Deserialization Prevention Requirements (L1 L2 L3), 5.5.3 Deserialization Prevention Requirements (L1 L2 L3)
[26] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 Requirement 6.5.6
[27] Standards Mapping - Payment Card Industry Data Security Standard Version 1.2 Requirement 6.3.1.1, Requirement 6.5.2
[28] Standards Mapping - Payment Card Industry Data Security Standard Version 2.0 Requirement 6.5.1
[29] Standards Mapping - Payment Card Industry Data Security Standard Version 3.0 Requirement 6.5.1
[30] Standards Mapping - Payment Card Industry Data Security Standard Version 3.1 Requirement 6.5.1
[31] Standards Mapping - Payment Card Industry Data Security Standard Version 3.2 Requirement 6.5.1
[32] Standards Mapping - Payment Card Industry Data Security Standard Version 3.2.1 Requirement 6.5.1
[33] Standards Mapping - Payment Card Industry Data Security Standard Version 4.0 Requirement 6.2.4
[34] Standards Mapping - Payment Card Industry Software Security Framework 1.0 Control Objective 4.2 - Critical Asset Protection
[35] Standards Mapping - Payment Card Industry Software Security Framework 1.1 Control Objective 4.2 - Critical Asset Protection, Control Objective B.3.1 - Terminal Software Attack Mitigation, Control Objective B.3.1.1 - Terminal Software Attack Mitigation
[36] Standards Mapping - Payment Card Industry Software Security Framework 1.2 Control Objective 4.2 - Critical Asset Protection, Control Objective B.3.1 - Terminal Software Attack Mitigation, Control Objective B.3.1.1 - Terminal Software Attack Mitigation, Control Objective C.3.5 - Web Software Attack Mitigation
[37] Standards Mapping - Security Technical Implementation Guide Version 3.1 APP3510 CAT I, APP3570 CAT I
[38] Standards Mapping - Security Technical Implementation Guide Version 3.4 APP3510 CAT I, APP3570 CAT I
[39] Standards Mapping - Security Technical Implementation Guide Version 3.5 APP3510 CAT I, APP3570 CAT I
[40] Standards Mapping - Security Technical Implementation Guide Version 3.6 APP3510 CAT I, APP3570 CAT I
[41] Standards Mapping - Security Technical Implementation Guide Version 3.7 APP3510 CAT I, APP3570 CAT I
[42] Standards Mapping - Security Technical Implementation Guide Version 3.9 APP3510 CAT I, APP3570 CAT I
[43] Standards Mapping - Security Technical Implementation Guide Version 3.10 APP3510 CAT I, APP3570 CAT I
[44] Standards Mapping - Security Technical Implementation Guide Version 4.1 APSC-DV-002560 CAT I
[45] Standards Mapping - Security Technical Implementation Guide Version 4.2 APSC-DV-002560 CAT I
[46] Standards Mapping - Security Technical Implementation Guide Version 4.3 APSC-DV-002560 CAT I
[47] Standards Mapping - Security Technical Implementation Guide Version 4.4 APSC-DV-002560 CAT I
[48] Standards Mapping - Security Technical Implementation Guide Version 4.5 APSC-DV-002560 CAT I
[49] Standards Mapping - Security Technical Implementation Guide Version 4.6 APSC-DV-002560 CAT I
[50] Standards Mapping - Security Technical Implementation Guide Version 4.7 APSC-DV-002560 CAT I
[51] Standards Mapping - Security Technical Implementation Guide Version 4.8 APSC-DV-002560 CAT I
[52] Standards Mapping - Security Technical Implementation Guide Version 4.9 APSC-DV-002560 CAT I
[53] Standards Mapping - Security Technical Implementation Guide Version 4.10 APSC-DV-002560 CAT I
[54] Standards Mapping - Security Technical Implementation Guide Version 4.11 APSC-DV-002560 CAT I
[55] Standards Mapping - Security Technical Implementation Guide Version 5.1 APSC-DV-002560 CAT I
[56] Standards Mapping - Security Technical Implementation Guide Version 5.2 APSC-DV-002560 CAT I
[57] Standards Mapping - Security Technical Implementation Guide Version 5.3 APSC-DV-002530 CAT II, APSC-DV-002560 CAT I
[58] Standards Mapping - Web Application Security Consortium Version 2.00 Improper Input Handling (WASC-20)
desc.dataflow.php.object_injection
Abstract
신뢰할 수 없는 데이터를 역직렬화하면 임의 Ruby 개체의 삽입을 허용하여 프로그램이 공격자 대신 악성 명령을 실행하도록 야기할 수 있습니다.
Explanation
Object injection 취약점은 YAML.load() 같은 데이터를 역직렬화하는 함수로 전달되기 전에 신뢰할 수 없는 데이터가 올바르게 정화되지 않는 경우에 발생합니다. 공격자가 특수하게 만들어진 직렬화된 문자열을 취약한 YAML.load() 호출에 전달하면 역직렬화 시 클래스가 응용 프로그램으로 로드되는 경우 임의의 Ruby 개체가 프로그램에 주입됩니다. 이렇게 되면 cross-site scripting 취약점을 찾기 위한 검증 로직을 우회하는 등의 다양한 공격 기회에 무방비 상태로 노출될 수 있으며, 하드코드된 값처럼 보이는 값을 통한 SQL Injection 공격이나 심지어 전체 코드 실행까지 발생할 수 있습니다.

예제 1: 다음 코드에서는 해당 속성을 사용하여 SQL 쿼리를 생성한 다음 데이터베이스에 대해 쿼리하는 Ruby 클래스를 보여 줍니다. 또한 사용자 공급 데이터가 포함된 YAML.load()에 대한 불안정한 호출도 있습니다.


...
class Transaction
attr_accessor :id
def initialize(num=nil)
@id = num.is_a?(Numeric) ? num : nil
end

def print_details
unless @id.nil?
print $conn.query("SELECT * FROM transactions WHERE id=#{@id}")
end
end
end

...
user = YAML.load(params[:user]);
user.print_details
...
Example 1에서 응용 프로그램은 print_details라는 함수가 포함되기도 하는 직렬화된 User 개체가 필요할 수 있지만 공격자는 실제로 해당 @id 속성 값이 미리 정의된 직렬화된 버전의 Transaction 개체를 제공할 수 있습니다. 따라서 다음과 같은 요청은 @id가 숫자 값인지 여부를 확인하려는 검증 검사를 우회하도록 허용할 수 있습니다.


GET REQUEST: http://server/page?user=!ruby%2Fobject%3ATransaction%0Aid%3A4%20or%205%3D5%0A


이 요청의 디코딩된 버전을 확인하면 user 매개 변수에 !ruby/object:Transaction\nid:4 or 5=5\n가 할당되어 있음을 알 수 있습니다.
이제 사용자 매개 변수를 역직렬화하면 @id"4 or 5=5"로 설정된 Transaction 유형의 개체가 생성됩니다. 개발자는 User#print_details()를 호출하려고 하지만 이제 Transaction#print_details()를 호출하게 되며, Ruby의 문자열 보간은 SELECT * FROM transactions WHERE id=4 or 5=5 쿼리를 실행하도록 SQL 쿼리가 변경된다는 것을 의미하게 됩니다. 별도의 절이 추가되었기 때문에 쿼리는 true로 평가되며 transactions 테이블 내에서 개발자가 의도했던 단일 행 대신 모든 행을 반환하게 됩니다.

공격자는 취약한 YAML.load()가 "속성 지향 프로그래밍"이라는 기술을 사용하여 호출된 경우 선언된 다른 클래스를 연결할 수 있습니다. "속성 지향 프로그래밍"은 BlackHat 2010 컨퍼런스에서 Stefan Esser가 소개한 기술입니다. 이 기술을 통해 공격자는 고유한 페이로드를 만들도록 기존의 코드를 재사용할 수 있습니다.
References
[1] HD Moore Serialization Mischief in Ruby Land (CVE-2013-0156)
[2] Ruby Ruby Security
[3] Standards Mapping - CIS Azure Kubernetes Service Benchmark 3.0
[4] Standards Mapping - CIS Microsoft Azure Foundations Benchmark complete
[5] Standards Mapping - CIS Amazon Elastic Kubernetes Service Benchmark 4.0
[6] Standards Mapping - CIS Amazon Web Services Foundations Benchmark 4
[7] Standards Mapping - CIS Google Kubernetes Engine Benchmark integrity
[8] Standards Mapping - CIS Kubernetes Benchmark complete
[9] Standards Mapping - Common Weakness Enumeration CWE ID 502
[10] Standards Mapping - Common Weakness Enumeration Top 25 2019 [23] CWE ID 502
[11] Standards Mapping - Common Weakness Enumeration Top 25 2020 [21] CWE ID 502
[12] Standards Mapping - Common Weakness Enumeration Top 25 2021 [13] CWE ID 502
[13] Standards Mapping - Common Weakness Enumeration Top 25 2022 [12] CWE ID 502
[14] Standards Mapping - Common Weakness Enumeration Top 25 2023 [15] CWE ID 502
[15] Standards Mapping - DISA Control Correlation Identifier Version 2 CCI-002754
[16] Standards Mapping - General Data Protection Regulation (GDPR) Indirect Access to Sensitive Data
[17] Standards Mapping - NIST Special Publication 800-53 Revision 4 SI-10 Information Input Validation (P1)
[18] Standards Mapping - NIST Special Publication 800-53 Revision 5 SI-10 Information Input Validation
[19] Standards Mapping - OWASP Top 10 2004 A6 Injection Flaws
[20] Standards Mapping - OWASP Top 10 2007 A2 Injection Flaws
[21] Standards Mapping - OWASP Top 10 2010 A1 Injection
[22] Standards Mapping - OWASP Top 10 2013 A1 Injection
[23] Standards Mapping - OWASP Top 10 2017 A8 Insecure Deserialization
[24] Standards Mapping - OWASP Top 10 2021 A08 Software and Data Integrity Failures
[25] Standards Mapping - OWASP Application Security Verification Standard 4.0 1.5.2 Input and Output Architectural Requirements (L2 L3), 5.5.1 Deserialization Prevention Requirements (L1 L2 L3), 5.5.3 Deserialization Prevention Requirements (L1 L2 L3)
[26] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 Requirement 6.5.6
[27] Standards Mapping - Payment Card Industry Data Security Standard Version 1.2 Requirement 6.3.1.1, Requirement 6.5.2
[28] Standards Mapping - Payment Card Industry Data Security Standard Version 2.0 Requirement 6.5.1
[29] Standards Mapping - Payment Card Industry Data Security Standard Version 3.0 Requirement 6.5.1
[30] Standards Mapping - Payment Card Industry Data Security Standard Version 3.1 Requirement 6.5.1
[31] Standards Mapping - Payment Card Industry Data Security Standard Version 3.2 Requirement 6.5.1
[32] Standards Mapping - Payment Card Industry Data Security Standard Version 3.2.1 Requirement 6.5.1
[33] Standards Mapping - Payment Card Industry Data Security Standard Version 4.0 Requirement 6.2.4
[34] Standards Mapping - Payment Card Industry Software Security Framework 1.0 Control Objective 4.2 - Critical Asset Protection
[35] Standards Mapping - Payment Card Industry Software Security Framework 1.1 Control Objective 4.2 - Critical Asset Protection, Control Objective B.3.1 - Terminal Software Attack Mitigation, Control Objective B.3.1.1 - Terminal Software Attack Mitigation
[36] Standards Mapping - Payment Card Industry Software Security Framework 1.2 Control Objective 4.2 - Critical Asset Protection, Control Objective B.3.1 - Terminal Software Attack Mitigation, Control Objective B.3.1.1 - Terminal Software Attack Mitigation, Control Objective C.3.5 - Web Software Attack Mitigation
[37] Standards Mapping - Security Technical Implementation Guide Version 3.1 APP3510 CAT I, APP3570 CAT I
[38] Standards Mapping - Security Technical Implementation Guide Version 3.4 APP3510 CAT I, APP3570 CAT I
[39] Standards Mapping - Security Technical Implementation Guide Version 3.5 APP3510 CAT I, APP3570 CAT I
[40] Standards Mapping - Security Technical Implementation Guide Version 3.6 APP3510 CAT I, APP3570 CAT I
[41] Standards Mapping - Security Technical Implementation Guide Version 3.7 APP3510 CAT I, APP3570 CAT I
[42] Standards Mapping - Security Technical Implementation Guide Version 3.9 APP3510 CAT I, APP3570 CAT I
[43] Standards Mapping - Security Technical Implementation Guide Version 3.10 APP3510 CAT I, APP3570 CAT I
[44] Standards Mapping - Security Technical Implementation Guide Version 4.1 APSC-DV-002560 CAT I
[45] Standards Mapping - Security Technical Implementation Guide Version 4.2 APSC-DV-002560 CAT I
[46] Standards Mapping - Security Technical Implementation Guide Version 4.3 APSC-DV-002560 CAT I
[47] Standards Mapping - Security Technical Implementation Guide Version 4.4 APSC-DV-002560 CAT I
[48] Standards Mapping - Security Technical Implementation Guide Version 4.5 APSC-DV-002560 CAT I
[49] Standards Mapping - Security Technical Implementation Guide Version 4.6 APSC-DV-002560 CAT I
[50] Standards Mapping - Security Technical Implementation Guide Version 4.7 APSC-DV-002560 CAT I
[51] Standards Mapping - Security Technical Implementation Guide Version 4.8 APSC-DV-002560 CAT I
[52] Standards Mapping - Security Technical Implementation Guide Version 4.9 APSC-DV-002560 CAT I
[53] Standards Mapping - Security Technical Implementation Guide Version 4.10 APSC-DV-002560 CAT I
[54] Standards Mapping - Security Technical Implementation Guide Version 4.11 APSC-DV-002560 CAT I
[55] Standards Mapping - Security Technical Implementation Guide Version 5.1 APSC-DV-002560 CAT I
[56] Standards Mapping - Security Technical Implementation Guide Version 5.2 APSC-DV-002560 CAT I
[57] Standards Mapping - Security Technical Implementation Guide Version 5.3 APSC-DV-002530 CAT II, APSC-DV-002560 CAT I
[58] Standards Mapping - Web Application Security Consortium Version 2.00 Improper Input Handling (WASC-20)
desc.dataflow.ruby.object_injection