
cve-2021-41773-source-code-analysis — Updated!
脆弱性のあるApache HTTP Server 2.4.49のソースコードと修正済みの2.4.51実装を比較し、CVE-2021-41773(Apache HTTP Serverのパストラバーサル)の根本原因と修正方法を研究するためのPythonベースの静的パッチ解析ツール。
Apache HTTP Server CVE-2021-41773 ソースコード解析
CVE-2021-41773(Apache HTTP Server パストラバーサル) の根本原因と是正を研究するためのPythonベースの静的パッチ解析ツールです。脆弱性のある Apache HTTP Server 2.4.49 のソースコードと、パッチ適用済みの 2.4.51 実装を比較します。
このプロジェクトは、単純なテキストベースの差分比較ではなく、セマンティックなソースコード解析を実行します。対象関数から構造情報を抽出し、両バージョンを比較して、セキュリティ関連の変更を推論し、プロフェッショナルな解析レポートを生成します。
機能
- 静的ソースコード解析
- ブレースマッチングによる関数抽出
- 脆弱性版とパッチ版の構造比較
- セキュリティ機能の検出
- パッチ推論エンジン
- Markdownレポート生成
- JSONレポート生成
- HTMLレポート生成
- Dockerラボの自動セットアップ
- 環境検証ツール
プロジェクト構成
Apache Source Code
│
▼
parser.py
│
▼
extractor.py
│
▼
comparator.py
│
▼
reasoning.py
│
▼
reports.py
プロジェクト構造
cve-2021-41773-source-code-analysis
│
├── docker
│ ├── apache249
│ │ ├── Dockerfile # Builds Apache HTTP Server 2.4.49 container
│ │ └── docker-compose.yml # Starts vulnerable Apache container
│ │
│ └── apache251
│ ├── Dockerfile # Builds Apache HTTP Server 2.4.51 container
│ └── docker-compose.yml # Starts patched Apache container
│
├── labs # Stores downloaded Apache source code
│
├── references
│ └── resources.md # Reference material for CVE research
│
├── scripts
│ ├── patch_analysis
│ │ ├── __init__.py # Initializes the analysis package
│ │ ├── parser.py # Extracts target C functions from Apache source
│ │ ├── extractor.py # Extracts variables, calls, conditions and security capabilities
│ │ ├── comparator.py # Compares vulnerable and patched function structures
│ │ ├── reasoning.py # Performs security reasoning on detected changes
│ │ ├── reports.py # Coordinates report generation
│ │ ├── markdown_report.py # Generates Markdown analysis report
│ │ ├── json_report.py # Generates JSON analysis report
│ │ └── html_report.py # Generates HTML analysis report
│ │
│ ├── analyze_patch.py # Main entry point for patch analysis
│ ├── verify_lab.py # Verifies Docker lab configuration
│ └── debug.py # Displays raw comparison output for debugging
│
├── analysis # Generated analysis reports
│
├── setup.sh # Automatically prepares the complete lab
│
├── LICENSE
└── README.md
必要条件
- Python 3.10+
- Docker
- Docker Compose
- Bash
- Linux(Kali Linuxでテスト済み)
インストール
リポジトリをクローンします
git clone https://github.com/KunalKhandelwal-dev/cve-2021-41773-source-code-analysis.git
プロジェクトに移動します
cd cve-2021-41773-source-code-analysis
セットアップ
自動セットアップスクリプトを実行します。
sudo bash setup.sh
セットアップスクリプトは、以下のタスクを自動的に実行します:
- 必要なツールを確認します
- Dockerのインストールを検証します
- Apache HTTP Server 2.4.49をダウンロードします
- Apache HTTP Server 2.4.51をダウンロードします
- 両方のソースツリーを展開します
- Dockerイメージをビルドします
- Apacheコンテナを起動します
- 解析環境を作成します
出力例
[INFO] Checking required tools...
[SUCCESS] Required tools found.
[INFO] Checking Docker...
[SUCCESS] Docker is running.
[INFO] Downloading Apache HTTP Server 2.4.49...
[SUCCESS] Apache 2.4.49 downloaded.
[INFO] Downloading Apache HTTP Server 2.4.51...
[SUCCESS] Apache 2.4.51 downloaded.
[INFO] Building Docker images...
[SUCCESS] Docker images built.
[INFO] Starting Apache containers...
[SUCCESS] Containers started.
=========================================================
[SUCCESS] Apache CVE Lab Setup Complete
=========================================================
環境の検証
実行:
cd scripts
sudo python3 verify_lab.py
検証成功時の表示
検証ツールが確認する項目:
- Dockerのインストール
- Dockerデーモン
- 実行中のコンテナ
- Apacheのバージョン
- Apacheソースコード
- 対象関数
- HTTPサービス
- GDBの利用可能性
パッチ解析の実行
scriptsディレクトリに移動します。
cd scripts
実行:
sudo python3 analyze_patch.py
出力例
解析出力のサンプル
Apache HTTP Server Patch Analysis Report
Security Findings
[MEDIUM]
Percent decoding introduced or modified
[MEDIUM]
Hexadecimal validation introduced or modified
[HIGH]
Directory traversal handling improved
[HIGH]
Path normalization pipeline updated
[CRITICAL]
Traversal protection strengthened
生成されるレポート
実行が成功すると、以下のレポートが生成されます:
analysis/
├── analysis.md
├── analysis.json
└── analysis.html
解析パイプライン
Load Apache Source
│
▼
Extract Target Function
│
▼
Extract Structural Information
│
▼
Compare Vulnerable vs Patched
│
▼
Security Reasoning
│
▼
Generate Reports
検出されるセキュリティ機能
- パーセントエンコーディング/デコード
- 16進数検証
- ドットセグメント処理
- パス区切り文字の正規化
- URI正規化フラグ
- ディレクトリトラバーサル保護
生成される検出結果
推論エンジンは、以下のようなセキュリティ改善を特定します:
- パーセントデコードの導入
- 16進数検証の導入
- ディレクトリトラバーサル処理の改善
- パス正規化の更新
- トラバーサル保護の強化
教育目的
このプロジェクトは、以下の人々を対象としています:
- セキュリティ研究者
- CVEの根本原因解析を学ぶ学生
- セキュアソフトウェアエンジニアリング
- 静的ソースコード解析
- パッチ差分解析
- 脆弱性研究
ライセンス
このプロジェクトはMITライセンスの下で公開されています。
著者
Kunal Khandelwal
B.Tech(コンピュータサイエンス工学/サイバーセキュリティ)
セキュリティ研究 | アプリケーションセキュリティ | Docker | ソースコード解析