Exploit database

GH-46257de2e742a6c34b27a22887e5921b

nxgn-kd01/smartermail-cve-scanner

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2025-52691

6 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files6
nxgn-kd01/smartermail-cve-scannerRevision 333bb3514f60

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

scan.sh

Shell · 12,857 bytes
#!/usr/bin/env bash

###############################################################################
# CVE-2025-52691 Scanner (SmarterMail RCE)
# Detects vulnerable SmarterMail installations
#
# Requirements: bash, curl
# CVSS: 10.0 (CRITICAL)
###############################################################################

set -euo pipefail

# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
BOLD='\033[1m'
DIM='\033[2m'
RESET='\033[0m'

# Configuration
CVE_ID="CVE-2025-52691"
CVE_NAME="SmarterMail RCE"
CVSS_SCORE="10.0"
SEVERITY="CRITICAL"

# Vulnerability data
VULNERABLE_BUILD_MAX=9406
PATCHED_BUILD_MIN=9413
RECOMMENDED_BUILD=9483

# Global variables
TARGET=""
JSON_OUTPUT=false
VERBOSE=false
CI_MODE=false
TIMEOUT=10
USER_AGENT="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"

# Results
DETECTED_VERSION=""
DETECTED_BUILD=""
IS_VULNERABLE=false
SCAN_SUCCESS=false

###############################################################################
# Helper Functions
###############################################################################

print_help() {
    cat << EOF

${BOLD}CVE-2025-52691 Scanner${RESET}
Detects vulnerable SmarterMail installations (Arbitrary File Upload → RCE)

${BOLD}Usage:${RESET}
  ./scan.sh <target> [options]

${BOLD}Arguments:${RESET}
  target              URL or IP address of SmarterMail server
                      Examples: https://mail.example.com
                                192.168.1.100
                                mail.example.com:9998

${BOLD}Options:${RESET}
  -v, --verbose      Show detailed output
  --json             Output results as JSON
  --ci               Exit with code 1 if vulnerable (for CI/CD)
  -t, --timeout      Connection timeout in seconds (default: 10)
  -h, --help         Show this help message

${BOLD}Examples:${RESET}
  ./scan.sh https://mail.example.com
  ./scan.sh 192.168.1.100:9998 --verbose
  ./scan.sh mail.example.com --json
  ./scan.sh https://mail.company.com --ci

${BOLD}Exit Codes:${RESET}
  0 - Not vulnerable or scan completed
  1 - Vulnerable (with --ci flag)
  2 - Scan error

${BOLD}Vulnerability Details:${RESET}
  CVE-2025-52691 allows unauthenticated attackers to upload arbitrary
  files to any location on the mail server, enabling remote code execution.

  Affected: Build 9406 and earlier
  Patched:  Build 9413+ (recommended: 9483+)

EOF
}

log_verbose() {
    if [[ "$VERBOSE" == true ]]; then
        echo -e "${DIM}[DEBUG] $1${RESET}"
    fi
}

log_info() {
    echo -e "${BLUE}[INFO]${RESET} $1"
}

log_warning() {
    echo -e "${YELLOW}[WARN]${RESET} $1"
}

log_error() {
    echo -e "${RED}[ERROR]${RESET} $1"
}

log_success() {
    echo -e "${GREEN}[OK]${RESET} $1"
}

# Normalize URL
normalize_url() {
    local target=$1

    # Remove trailing slash
    target="${target%/}"

    # Add https:// if no protocol specified
    if [[ ! "$target" =~ ^https?:// ]]; then
        target="https://$target"
    fi

    echo "$target"
}

# Extract build number from version string
extract_build() {
    local version_string=$1

    # Try different patterns
    # Pattern 1: "Build 9406" or "build 9406"
    if [[ "$version_string" =~ [Bb]uild[[:space:]]*([0-9]+) ]]; then
        echo "${BASH_REMATCH[1]}"
        return
    fi

    # Pattern 2: Version like "100.0.9406" (last number is build)
    if [[ "$version_string" =~ ([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
        echo "${BASH_REMATCH[3]}"
        return
    fi

    # Pattern 3: Just a number
    if [[ "$version_string" =~ ([0-9]{4,5}) ]]; then
        echo "${BASH_REMATCH[1]}"
        return
    fi

    echo ""
}

# Check if build is vulnerable
is_build_vulnerable() {
    local build=$1

    if [[ -z "$build" ]]; then
        return 1  # Unknown
    fi

    if [[ "$build" -le "$VULNERABLE_BUILD_MAX" ]]; then
        return 0  # Vulnerable
    fi

    return 1  # Not vulnerable
}

###############################################################################
# Scanning Functions
###############################################################################

# Try to get version from various SmarterMail endpoints
scan_target() {
    local base_url=$1

    log_verbose "Scanning target: $base_url"

    # Common SmarterMail endpoints that might reveal version info
    local endpoints=(
        "/about/checkup"
        "/interface/root"
        "/Main/Login.aspx"
        "/Login.aspx"
        "/"
        "/api/v1/settings/sysadmin/license"
        "/About/Default.aspx"
    )

    for endpoint in "${endpoints[@]}"; do
        local url="${base_url}${endpoint}"
        log_verbose "Trying endpoint: $url"

        local response
        response=$(curl -sS -k -L \
            --connect-timeout "$TIMEOUT" \
            --max-time $((TIMEOUT * 2)) \
            -A "$USER_AGENT" \
            -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" \
            -H "Accept-Language: en-US,en;q=0.5" \
            "$url" 2>/dev/null) || continue

        # Look for SmarterMail indicators
        if [[ "$response" =~ SmarterMail ]] || [[ "$response" =~ smartermail ]] || [[ "$response" =~ SmarterTools ]]; then
            log_verbose "Found SmarterMail indicator at $endpoint"
            SCAN_SUCCESS=true

            # Try to extract version/build
            # Pattern: "SmarterMail 100.0.9406" or similar
            if [[ "$response" =~ SmarterMail[[:space:]]*([0-9]+\.[0-9]+\.[0-9]+) ]]; then
                DETECTED_VERSION="${BASH_REMATCH[1]}"
                DETECTED_BUILD=$(extract_build "$DETECTED_VERSION")
                log_verbose "Detected version: $DETECTED_VERSION (Build: $DETECTED_BUILD)"
            fi

            # Pattern: "Build 9406" standalone
            if [[ -z "$DETECTED_BUILD" ]] && [[ "$response" =~ [Bb]uild[[:space:]]*([0-9]+) ]]; then
                DETECTED_BUILD="${BASH_REMATCH[1]}"
                log_verbose "Detected build: $DETECTED_BUILD"
            fi

            # Pattern: Version in meta tag or JS
            if [[ -z "$DETECTED_BUILD" ]] && [[ "$response" =~ version[\"\':\s]*([0-9]+\.[0-9]+\.[0-9]+) ]]; then
                DETECTED_VERSION="${BASH_REMATCH[1]}"
                DETECTED_BUILD=$(extract_build "$DETECTED_VERSION")
                log_verbose "Detected version from meta: $DETECTED_VERSION"
            fi

            # If we found a build number, check vulnerability
            if [[ -n "$DETECTED_BUILD" ]]; then
                if is_build_vulnerable "$DETECTED_BUILD"; then
                    IS_VULNERABLE=true
                fi
                return 0
            fi
        fi
    done

    # Try to get headers that might reveal version
    local headers
    headers=$(curl -sS -k -I -L \
        --connect-timeout "$TIMEOUT" \
        --max-time $((TIMEOUT * 2)) \
        -A "$USER_AGENT" \
        "$base_url" 2>/dev/null) || true

    if [[ "$headers" =~ SmarterMail ]] || [[ "$headers" =~ X-SM-Version ]]; then
        SCAN_SUCCESS=true
        log_verbose "Found SmarterMail in headers"

        # Check for version header
        if [[ "$headers" =~ X-SM-Version:[[:space:]]*([0-9.]+) ]]; then
            DETECTED_VERSION="${BASH_REMATCH[1]}"
            DETECTED_BUILD=$(extract_build "$DETECTED_VERSION")
        fi
    fi

    return 0
}

###############################################################################
# Output Functions
###############################################################################

print_header() {
    cat << EOF

${CYAN}${BOLD}+============================================================+${RESET}
${CYAN}${BOLD}|${RESET}  ${BOLD}CVE-2025-52691 Scanner (SmarterMail RCE)${RESET}               ${CYAN}|${RESET}
${CYAN}+============================================================+${RESET}

${DIM}Severity:${RESET} ${RED}${BOLD}CRITICAL${RESET} (CVSS 10.0)
${DIM}Type:${RESET} Unauthenticated Arbitrary File Upload -> RCE

EOF
}

print_result() {
    echo -e "${BOLD}Scan Results:${RESET}"
    echo -e "  Target: $TARGET"

    if [[ "$SCAN_SUCCESS" == true ]]; then
        echo -e "  ${GREEN}SmarterMail detected${RESET}"

        if [[ -n "$DETECTED_VERSION" ]]; then
            echo -e "  Version: $DETECTED_VERSION"
        fi

        if [[ -n "$DETECTED_BUILD" ]]; then
            echo -e "  Build: $DETECTED_BUILD"

            if [[ "$IS_VULNERABLE" == true ]]; then
                echo ""
                echo -e "  ${RED}${BOLD}STATUS: VULNERABLE${RESET}"
                echo -e "  ${RED}Build $DETECTED_BUILD is affected by CVE-2025-52691${RESET}"
                echo ""
                echo -e "  ${YELLOW}${BOLD}Remediation:${RESET}"
                echo -e "  ${DIM}\$${RESET} Upgrade to SmarterMail Build $RECOMMENDED_BUILD or later"
                echo -e "  ${DIM}\$${RESET} Download: https://www.smartertools.com/smartermail/downloads"
            else
                echo ""
                echo -e "  ${GREEN}${BOLD}STATUS: NOT VULNERABLE${RESET}"
                echo -e "  ${GREEN}Build $DETECTED_BUILD is patched${RESET}"
            fi
        else
            echo ""
            echo -e "  ${YELLOW}${BOLD}STATUS: UNKNOWN${RESET}"
            echo -e "  ${YELLOW}Could not determine build number${RESET}"
            echo -e "  ${DIM}Manual verification recommended${RESET}"
        fi
    else
        echo ""
        echo -e "  ${YELLOW}${BOLD}STATUS: NOT DETECTED${RESET}"
        echo -e "  ${YELLOW}SmarterMail not detected at this target${RESET}"
        echo -e "  ${DIM}Verify the URL and try again${RESET}"
    fi
    echo ""
}

print_footer() {
    cat << EOF
${DIM}-------------------------------------------------------------${RESET}
${DIM}Affected:${RESET} SmarterMail Build 9406 and earlier
${DIM}Patched:${RESET}  Build 9413+ (recommended: 9483+)

${DIM}References:${RESET}
  - https://www.csa.gov.sg/alerts-and-advisories/alerts/al-2025-124/
  - https://nvd.nist.gov/vuln/detail/CVE-2025-52691
  - https://www.smartertools.com/smartermail/release-notes

EOF
}

output_json() {
    local status="unknown"

    if [[ "$SCAN_SUCCESS" == false ]]; then
        status="not_detected"
    elif [[ -z "$DETECTED_BUILD" ]]; then
        status="unknown"
    elif [[ "$IS_VULNERABLE" == true ]]; then
        status="vulnerable"
    else
        status="patched"
    fi

    cat << EOF
{
  "vulnerability": "$CVE_ID",
  "name": "$CVE_NAME",
  "severity": "$SEVERITY",
  "cvss": $CVSS_SCORE,
  "target": "$TARGET",
  "smartermail_detected": $SCAN_SUCCESS,
  "version": "${DETECTED_VERSION:-null}",
  "build": ${DETECTED_BUILD:-null},
  "status": "$status",
  "vulnerable": $IS_VULNERABLE,
  "vulnerable_max_build": $VULNERABLE_BUILD_MAX,
  "patched_min_build": $PATCHED_BUILD_MIN,
  "recommended_build": $RECOMMENDED_BUILD
}
EOF
}

###############################################################################
# Main
###############################################################################

main() {
    # Parse arguments
    while [[ $# -gt 0 ]]; do
        case $1 in
            -h|--help)
                print_help
                exit 0
                ;;
            -v|--verbose)
                VERBOSE=true
                shift
                ;;
            --json)
                JSON_OUTPUT=true
                shift
                ;;
            --ci)
                CI_MODE=true
                shift
                ;;
            -t|--timeout)
                TIMEOUT="$2"
                shift 2
                ;;
            -*)
                log_error "Unknown option: $1"
                print_help
                exit 2
                ;;
            *)
                TARGET="$1"
                shift
                ;;
        esac
    done

    # Validate target
    if [[ -z "$TARGET" ]]; then
        if [[ "$JSON_OUTPUT" == true ]]; then
            echo '{"error": "No target specified"}'
        else
            log_error "No target specified"
            print_help
        fi
        exit 2
    fi

    # Check requirements
    if ! command -v curl &> /dev/null; then
        if [[ "$JSON_OUTPUT" == true ]]; then
            echo '{"error": "curl is required but not installed"}'
        else
            log_error "curl is required but not installed"
        fi
        exit 2
    fi

    # Normalize and scan
    TARGET=$(normalize_url "$TARGET")

    if [[ "$JSON_OUTPUT" != true ]]; then
        print_header
        log_info "Scanning target: $TARGET"
        echo ""
    fi

    scan_target "$TARGET"

    # Output results
    if [[ "$JSON_OUTPUT" == true ]]; then
        output_json
    else
        print_result
        print_footer
    fi

    # Exit code for CI/CD
    if [[ "$CI_MODE" == true ]] && [[ "$IS_VULNERABLE" == true ]]; then
        exit 1
    fi
}

# Run main
main "$@"