Search for sensitive files

1. Goal

Detect whether sensitive files exist in your website path:

  • log file

  • environment variables file

  • backup file

2. Description

  • sensitive_files.txtReads a regular expression from a file and searches for matching files within the specified document root directory. This gives you more flexibility in checking sensitive files.

  • sensitive_files.txtYou can increase detection by adding more regular expressions to the file.

3. Code

vi check_sensitive_files.sh

#!/bin/bash

# ์‚ฌ์šฉ๋ฒ• ์•ˆ๋‚ด ํ•จ์ˆ˜
usage() {
    echo "Usage: $0 <DOCUMENT_ROOT>"
    exit 1
}

# ๋ช…๋ น์ค„ ์ธ์ˆ˜ ํ™•์ธ
if [ "$#" -ne 1 ]; then
    usage
fi

# ์›น ์„œ๋ฒ„์˜ ๋ฌธ์„œ ๋ฃจํŠธ ๋””๋ ‰ํ† ๋ฆฌ
DOCUMENT_ROOT="$1"

# ๋ฏผ๊ฐํ•œ ํŒŒ์ผ ๋ชฉ๋ก ํŒŒ์ผ
SENSITIVE_FILES_LIST="sensitive_files.txt"

# ๋ฏผ๊ฐํ•œ ํŒŒ์ผ ๋ชฉ๋ก์„ ์ฝ์–ด๋“ค์ด๊ธฐ
if [ ! -f "$SENSITIVE_FILES_LIST" ]; then
    echo "Error: Sensitive files list file not found: $SENSITIVE_FILES_LIST"
    exit 1
fi

# ํ•จ์ˆ˜: ํŒŒ์ผ ์ ‘๊ทผ ๊ฐ€๋Šฅ ์—ฌ๋ถ€ ํ™•์ธ
check_file() {
    local file_pattern="$1"
    local matched_files=($(find "$DOCUMENT_ROOT" -type f -regex "$file_pattern"))
    
    if [ ${#matched_files[@]} -gt 0 ]; then
        for file in "${matched_files[@]}"; do
            echo "[๋…ธ์ถœ๋จ] ๋ฏผ๊ฐํ•œ ํŒŒ์ผ ๋ฐœ๊ฒฌ: $file"
        done
    else
        echo "[์•ˆ์ „ํ•จ] ๋ฏผ๊ฐํ•œ ํŒŒ์ผ ์—†์Œ: $file_pattern"
    fi
}

echo "๋ฏผ๊ฐํ•œ ํŒŒ์ผ ์ ‘๊ทผ ์—ฌ๋ถ€ ํ™•์ธ ์ค‘..."

# ๋ฏผ๊ฐํ•œ ํŒŒ์ผ ๋ชฉ๋ก์„ ์ฝ์–ด์„œ ํ•จ์ˆ˜ ํ˜ธ์ถœ
while IFS= read -r file_pattern; do
    check_file "$file_pattern"
done < "$SENSITIVE_FILES_LIST"

Log file detection

Because log files record application and server activity, they may contain sensitive information:

Environmental variable exposure detection

Environment variables files can contain sensitive information, such as database passwords and API keys:

Backup file detection

Backup files may contain snapshots of entire databases or file systems, which poses a significant risk if exposed:

DEBUG INFO EXPOSURE file detection

Files used for debugging purposes can expose internal system configuration information or environmental settings, which can pose a significant security risk if exposed to the outside world:

vi sensitive_files.txt

4. Run

  • When running the script, pass the web server's document root directory as an argument:

Last updated