Exploit databaseDownload repository ZIP
GH-f418e82f839bd952f611febd853da2f3
gkdgkd123/cve-2026-29145-everything
Sources for CVE-2026-29145
3 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars.
Repository files16
gkdgkd123/cve-2026-29145-everythingRevision 07dd97c0265e
- pcaps/
- rules/
- tomcat/
- .gitignore
- README.md
- REPRODUCTION.md
- capture_exploit.sh
- cleanup.ps1
- cleanup.sh
- docker-compose.yml
- poc_exploit.py
- requirements.txt
- run_test.sh
- setup_certs.ps1
- setup_certs.sh
- simple_proxy_fail.py
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
setup_certs.sh
Shell · 16,797 bytes#!/bin/bash
################################################################################
# CVE-2026-29145 Certificate Generation Script
################################################################################
#
# Purpose:
# This script generates the complete Public Key Infrastructure (PKI) chain
# required for testing the CVE-2026-29145 vulnerability in Apache Tomcat.
#
# What It Does:
# 1. Validates system requirements (OpenSSL installation)
# 2. Creates a self-signed Root CA (Certificate Authority)
# 3. Generates server certificate for Tomcat SSL/TLS
# 4. Generates client certificate with OCSP extension
# 5. Verifies all certificates were created successfully
#
# Generated Files:
# - ca-key.pem: Root CA private key (4096-bit RSA)
# - ca-chain.pem: Root CA self-signed certificate (365-day validity)
# - server-key.pem: Server private key (2048-bit RSA)
# - server-cert.pem: Server certificate signed by CA (365-day validity)
# - client-key.pem: Client private key (2048-bit RSA)
# - client-cert.pem: Client certificate with OCSP extension (365-day validity)
#
# Temporary Files (Removed After Generation):
# - server.csr: Server certificate signing request
# - client.csr: Client certificate signing request
# - ocsp.ext: OCSP extension configuration
#
# OCSP Configuration:
# The client certificate includes an OCSP extension pointing to:
# http://localhost:8888
#
# This is the URL of the mock OCSP responder (simple_proxy_fail.py) which
# simulates a failing OCSP service, triggering the vulnerability test.
#
# Error Handling:
# - Exits on first error (set -e)
# - Validates each certificate generation step
# - Provides detailed error messages with remediation steps
#
# Usage:
# chmod +x setup_certs.sh
# ./setup_certs.sh
#
# Environment Variables:
# OCSP_URL: Override default OCSP responder URL (default: http://localhost:8888)
# Example: OCSP_URL=http://ocsp-responder:8888 ./setup_certs.sh
#
# Requirements:
# - OpenSSL (available on Linux, macOS, Windows WSL)
# - Bash shell
# - write permissions in current directory
#
# Security Notes:
# - Self-signed certificate (not trusted by browsers)
# - For testing purposes only
# - Do NOT use in production environments
# - Private keys stored in plain text (not encrypted)
#
# Author: Security Testing Team
# CVE: CVE-2026-29145
# CVSS Score: 9.1 (Critical)
#
################################################################################
# Exit immediately if any command exits with non-zero status
# This prevents partial certificate generation and cascade failures
set -e
################################################################################
# Color Codes for Terminal Output
################################################################################
# Makes it easy to distinguish between info, warning, and error messages
RED='\033[0;31m' # Red for errors
GREEN='\033[0;32m' # Green for info
YELLOW='\033[1;33m' # Yellow for warnings
NC='\033[0m' # No Color (reset)
################################################################################
# Logging Helper Functions
################################################################################
# These functions provide consistent, colored output for user feedback
log_info() {
#
# Log an informational message in green.
# Used for successful operations and progress updates.
#
echo -e "${GREEN}[INFO]${NC} $1"
}
log_warn() {
#
# Log a warning message in yellow.
# Used for non-critical issues that don't stop execution.
#
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
#
# Log an error message in red.
# Used for failures that stop execution.
#
echo -e "${RED}[ERROR]${NC} $1"
}
################################################################################
# Prerequisite Validation
################################################################################
check_requirements() {
#
# Verify that all required tools are installed and available.
#
# Checks:
# - OpenSSL: Required for all cryptographic operations
#
# Behavior:
# - Exits with error code 1 if requirements not met
# - Displays OpenSSL version if available
#
log_info "Checking for required tools..."
# Check if openssl command is available in system PATH
if ! command -v openssl &> /dev/null; then
log_error "OpenSSL is not installed"
log_error "Install OpenSSL:"
log_error " Ubuntu/Debian: sudo apt-get install openssl"
log_error " macOS: brew install openssl"
log_error " CentOS/RHEL: sudo yum install openssl"
exit 1
fi
# Display installed OpenSSL version for reference
log_info "OpenSSL found: $(openssl version)"
}
################################################################################
# Directory Setup
################################################################################
setup_directory() {
#
# Create the certificate directory and handle existing certificates.
#
# Behavior:
# - Creates ./certs directory if it doesn't exist
# - Warns if directory already exists
# - Offers to remove existing certificates
# - Preserves existing certificates if user chooses
#
# Directory Structure:
# ./certs/
# ├── ca-key.pem
# ├── ca-chain.pem
# ├── server-key.pem
# ├── server-cert.pem
# ├── client-key.pem
# └── client-cert.pem
#
if [ -d "certs" ]; then
# Certs directory already exists
log_warn "Certificate directory already exists"
read -p "Remove existing certificates? (y/n) " -n 1 -r
echo
# If user answered 'y' or 'Y', remove existing certificates
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm -rf certs
log_info "Removed existing certificates"
else
# User chose to keep existing certificates
log_warn "Using existing certificates"
exit 0
fi
fi
# Create fresh certs directory
mkdir -p certs
log_info "Created certs directory"
}
################################################################################
# Root Certificate Authority (CA) Generation
################################################################################
create_root_ca() {
#
# Generate self-signed Root Certificate Authority (CA).
#
# This is the top-level trusted certificate that signs all other certificates
# in the PKI chain. It's self-signed because there's no higher authority.
#
# Steps:
# 1. Generate 4096-bit RSA private key (ca-key.pem)
# 2. Create self-signed X.509 certificate (ca-chain.pem)
#
# Certificate Details:
# - Common Name (CN): Test-Root-CA
# - Key Size: 4096 bits (RSA)
# - Validity: 365 days
# - Self-Signed: Yes
#
# Files Created:
# - certs/ca-key.pem: Private key (keep secure, never share)
# - certs/ca-chain.pem: Self-signed certificate (can be shared)
#
# Error Handling:
# - Captures stderr to display error details
# - Exits with error code 1 on failure
#
log_info "Creating Root CA..."
# Step 1: Generate 4096-bit RSA private key
# -out: Output file for private key
# 4096: Key size in bits (larger = more secure, slower)
local output
output=$(openssl genrsa -out certs/ca-key.pem 4096 2>&1)
if [ $? -eq 0 ]; then
log_info "Generated CA private key"
else
log_error "Failed to generate CA private key:"
echo "$output"
exit 1
fi
# Step 2: Create self-signed X.509 certificate from private key
# -new: Create new certificate request
# -x509: Output self-signed certificate instead of request
# -days: Certificate validity period in days
# -key: Private key file to use for signing
# -out: Output file for certificate
# -subj: Certificate subject (avoid interactive prompts)
# CA needs keyUsage for modern OpenSSL/Python clients (keyCertSign, cRLSign)
cat > certs/ca.cnf <<'EOF'
[req]
distinguished_name = req_dn
x509_extensions = v3_ca
prompt = no
[req_dn]
CN = Test-Root-CA
[v3_ca]
basicConstraints = critical, CA:true
keyUsage = critical, keyCertSign, cRLSign
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
EOF
output=$(openssl req -new -x509 -days 365 -key certs/ca-key.pem \
-out certs/ca-chain.pem -config certs/ca.cnf 2>&1)
if [ $? -eq 0 ]; then
log_info "Generated CA certificate"
else
log_error "Failed to generate CA certificate:"
echo "$output"
exit 1
fi
}
################################################################################
# Server Certificate Generation
################################################################################
create_server_cert() {
# Generate server certificate for Tomcat SSL/TLS.
#
# This certificate is used by Tomcat to present to clients during SSL handshake.
# It's signed by the Root CA to establish the chain of trust.
#
# Steps:
# 1. Generate 2048-bit RSA private key (server-key.pem)
# 2. Create certificate signing request (server.csr)
# 3. Sign request with CA to create certificate (server-cert.pem)
log_info "Creating Server Certificate..."
# Step 1: Generate 2048-bit RSA private key for server
# Smaller key size (2048) is typical for servers; sufficient security level
local output
output=$(openssl genrsa -out certs/server-key.pem 2048 2>&1)
if [ $? -eq 0 ]; then
log_info "Generated server private key"
else
log_error "Failed to generate server private key:"
echo "$output"
exit 1
fi
# Step 2: Create certificate signing request (CSR)
# A CSR contains certificate details and public key
# It's sent to CA for signing
cat > certs/server.cnf <<'EOF'
[req]
distinguished_name = req_dn
prompt = no
[req_dn]
CN = localhost
[v3_server]
basicConstraints = CA:false
keyUsage = digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth
subjectAltName = DNS:localhost,IP:127.0.0.1
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer
EOF
output=$(openssl req -new -key certs/server-key.pem -out certs/server.csr \
-config certs/server.cnf 2>&1)
if [ $? -eq 0 ]; then
log_info "Generated server certificate request"
else
log_error "Failed to generate server certificate request:"
echo "$output"
exit 1
fi
# Step 3: Sign CSR with Root CA to create server certificate
output=$(openssl x509 -req -in certs/server.csr -CA certs/ca-chain.pem \
-CAkey certs/ca-key.pem -CAcreateserial -out certs/server-cert.pem \
-days 365 -extfile certs/server.cnf -extensions v3_server 2>&1)
if [ $? -eq 0 ]; then
log_info "Generated server certificate"
else
log_error "Failed to generate server certificate:"
echo "$output"
exit 1
fi
}
################################################################################
# Client Certificate with OCSP Extension Generation
################################################################################
create_client_cert() {
# Generate client certificate with OCSP extension.
#
# This certificate is used by the test script to authenticate to Tomcat
# using mutual TLS (CLIENT_CERT authentication). It includes an OCSP
# extension that points to the mock OCSP responder.
#
# Steps:
# 1. Create OCSP extension configuration file
# 2. Generate 2048-bit RSA private key (client-key.pem)
# 3. Create certificate signing request (client.csr)
# 4. Sign request with CA, adding OCSP extension
log_info "Creating Client Certificate with OCSP Extension..."
# Step 1: Create OCSP extension configuration file
# This file specifies the OCSP responder URL
# Format: Authority Info Access extension with OCSP method
# Can be overridden with OCSP_URL environment variable
OCSP_URL="${OCSP_URL:-http://ocsp-responder:8888}"
cat > certs/ocsp.ext <<EOF
basicConstraints = CA:false
keyUsage = digitalSignature
extendedKeyUsage = clientAuth
authorityInfoAccess = OCSP;URI:${OCSP_URL}
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer
EOF
log_info "Created OCSP extension configuration"
log_info "OCSP Responder URL: ${OCSP_URL}"
# Step 2: Generate 2048-bit RSA private key for client
local output
output=$(openssl genrsa -out certs/client-key.pem 2048 2>&1)
if [ $? -eq 0 ]; then
log_info "Generated client private key"
else
log_error "Failed to generate client private key:"
echo "$output"
exit 1
fi
# Step 3: Create certificate signing request
output=$(openssl req -new -key certs/client-key.pem -out certs/client.csr \
-subj "/CN=TestClient" 2>&1)
if [ $? -eq 0 ]; then
log_info "Generated client certificate request"
else
log_error "Failed to generate client certificate request:"
echo "$output"
exit 1
fi
# Step 4: Sign CSR with Root CA, adding OCSP extension
output=$(openssl x509 -req -in certs/client.csr -CA certs/ca-chain.pem \
-CAkey certs/ca-key.pem -CAcreateserial -out certs/client-cert.pem \
-days 365 -extfile certs/ocsp.ext 2>&1)
if [ $? -eq 0 ]; then
log_info "Generated client certificate with OCSP extension"
else
log_error "Failed to generate client certificate:"
echo "$output"
exit 1
fi
}
################################################################################
# Temporary File Cleanup
################################################################################
cleanup_temp_files() {
# Remove temporary files created during certificate generation.
#
# These files (CSRs, extension configs, etc.) are not needed after
# the final certificates are created.
log_info "Cleaning up temporary files..."
# Remove all temporary certificate files
# Using rm -f to silently ignore if files don't exist
rm -f certs/server.csr certs/client.csr certs/ocsp.ext certs/ca-chain.pem.srl certs/ca.cnf certs/server.cnf
log_info "Removed temporary files"
}
################################################################################
# Certificate Verification
################################################################################
verify_certificates() {
# Verify that all required certificate files were created successfully.
#
# This final check ensures the certificate generation process completed
# without errors and all final artifact files are in place.
# It will exit with an error if any file is missing, which would
# indicate a failure in a previous step.
log_info "Verifying generated certificates..."
# Array of required certificate files
required_files=("ca-chain.pem" "ca-key.pem" "server-cert.pem" "server-key.pem" "client-cert.pem" "client-key.pem")
# Array to collect missing files
missing_files=()
# Check each required file
for file in "${required_files[@]}"; do
if [ ! -f "certs/$file" ]; then
# File not found, add to missing list
missing_files+=("$file")
fi
done
# Report results
if [ ${#missing_files[@]} -gt 0 ]; then
# Some files are missing - this shouldn't happen if previous steps worked
log_error "Missing certificate files: ${missing_files[*]}"
exit 1
fi
# All files present
log_info "All certificate files generated successfully"
}
################################################################################
# Main Execution
################################################################################
main() {
# Main entry point for the certificate generation script.
#
# Executes each step in order to create the full PKI needed for the test.
# The script will exit immediately if any step fails.
log_info "Starting certificate generation for CVE-2026-29145 testing environment"
# Execute each setup step in order
check_requirements
setup_directory
create_root_ca
create_server_cert
create_client_cert
cleanup_temp_files
verify_certificates
# Completion messages
log_info "Certificate setup completed successfully!"
log_info "Ready to start the testing environment with: docker-compose up -d"
}
# Execute main function
main