0% found this document useful (0 votes)
12 views3 pages

HLB2025 Investigation Bash Script

The document is a Bash script designed for investigating potential security compromises on a web server. It analyzes Apache logs for suspicious activity, identifies compromise details, and gathers system information, ultimately compiling a report with findings. The script includes functionality to create temporary directories, extract relevant data, and generate a formatted output file with investigation results.

Uploaded by

wopetiw397
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

HLB2025 Investigation Bash Script

The document is a Bash script designed for investigating potential security compromises on a web server. It analyzes Apache logs for suspicious activity, identifies compromise details, and gathers system information, ultimately compiling a report with findings. The script includes functionality to create temporary directories, extract relevant data, and generate a formatted output file with investigation results.

Uploaded by

wopetiw397
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

$ cat help.

sh
#!/bin/bash

# HLB2025 Investigation Script


# Targets: [Link]

# Configuration
TARGET_URL="[Link]
LOG_DIR="/var/log/apache2/"
WEB_ROOT="/var/www/html/"
TEMP_DIR="/tmp/hlb_investigation_$(date +%s)"
OUTPUT_FILE="hlb_investigation_$(date +%Y%m%d).txt"
ATTACKER_IP="[Link]"

# Create temporary working directory


mkdir -p "$TEMP_DIR"

# Function to search for suspicious activity in logs


analyze_logs() {
echo "[*] Analyzing system logs..."

# Process Apache logs


for log_file in ${LOG_DIR}{access,error,other_vhosts_access}.log*; do
echo "[+] Processing $log_file"

# Extract requests from attacker IP


zgrep "$ATTACKER_IP" "$log_file" > "$TEMP_DIR/attacker_requests.txt"

# Extract suspicious patterns (XSS, LFI, RFI, code execution)


zgrep -E "(\.\./|%00|eval\(|base64_decode|system\(|passthru\(|shell_exec\(|
<\?php|<\?=|<\? |\\x[0-9a-f]{2})" "$log_file" >>
"$TEMP_DIR/suspicious_requests.txt"

# Extract POST requests to PHP files


zgrep "POST .*\.php" "$log_file" >> "$TEMP_DIR/post_requests.txt"

# Extract parameter patterns from GET requests


zgrep -oP 'GET.*?\K\?(.*?) ' "$log_file" | tr '&' '\n' | cut -d' ' -f1 |
sort -u >> "$TEMP_DIR/all_parameters.txt"
done

# Process suspicious requests


awk '{print $4}' "$TEMP_DIR/suspicious_requests.txt" | sort -u >
"$TEMP_DIR/suspicious_timestamps.txt"
awk -F'[?&]' '{for(i=2;i<=NF;i++) print $i}'
"$TEMP_DIR/suspicious_requests.txt" | cut -d' ' -f1 | sort -u >
"$TEMP_DIR/suspicious_parameters.txt"
awk '{print $7}' "$TEMP_DIR/suspicious_requests.txt" | sort -u >
"$TEMP_DIR/suspicious_endpoints.txt"

# Check for recent file modifications in web root


echo "[*] Checking for recent file modifications..."
find "$WEB_ROOT" -type f -mtime -7 -exec ls -la {} \; >
"$TEMP_DIR/recent_modified_files.txt"
}

# Function to identify the exact compromise details


identify_compromise() {
echo "[*] Identifying compromise details..."
# Q1: Find the exact timestamp of compromise (Unix timestamp)
COMPROMISE_LINE=$(grep -m 1 "[Link].*200" "$TEMP_DIR/attacker_requests.txt")
if [ -n "$COMPROMISE_LINE" ]; then
LOG_DATE=$(echo "$COMPROMISE_LINE" | awk -F'[][]' '{print $2}')
COMPROMISE_TIMESTAMP=$(date -d "$(echo "$LOG_DATE" | sed 's/:\([0-9]\{2\}\)
$/ \1/')" "+%s" 2>/dev/null)
echo "[+] Q1 - Compromise timestamp (Unix): $COMPROMISE_TIMESTAMP"
else
echo "[-] Could not identify exact compromise timestamp"
COMPROMISE_TIMESTAMP="UNKNOWN"
fi

# Q2: Parameter used in URL to trigger exploit


EXPLOIT_PARAM=$(grep -m 1 "[Link]?" "$TEMP_DIR/suspicious_requests.txt" |
grep -oP '\?.*?=' | cut -d'?' -f2 | cut -d'=' -f1 | head -1)
if [ -n "$EXPLOIT_PARAM" ]; then
echo "[+] Q2 - Exploit parameter: $EXPLOIT_PARAM"
else
echo "[-] Could not identify exploit parameter"
EXPLOIT_PARAM="UNKNOWN"
fi

# Q3: Compromised endpoint


COMPROMISED_ENDPOINT=$(grep -m 1 "[Link]" "$TEMP_DIR/suspicious_requests.txt"
| awk '{print $7}' | cut -d'?' -f1)
if [ -n "$COMPROMISED_ENDPOINT" ]; then
echo "[+] Q3 - Compromised endpoint: $COMPROMISED_ENDPOINT"
else
echo "[-] Could not identify compromised endpoint"
COMPROMISED_ENDPOINT="UNKNOWN"
fi

# Generate flag format


echo "[+] Flag: HLB2025-${COMPROMISE_TIMESTAMP}-${EXPLOIT_PARAM}-$
{COMPROMISED_ENDPOINT}"
}

# Function to gather system information


gather_system_info() {
echo "[*] Gathering system information..."
uname -a > "$TEMP_DIR/system_info.txt"
env >> "$TEMP_DIR/system_info.txt"
ps aux >> "$TEMP_DIR/running_processes.txt"
netstat -tulnp >> "$TEMP_DIR/network_connections.txt"
crontab -l >> "$TEMP_DIR/cron_jobs.txt" 2>/dev/null
}

# Main execution
echo "[*] Starting HLB2025 investigation..."
analyze_logs
gather_system_info
identify_compromise

# Compile results
{
echo "HLB2025 Investigation Report"
echo "==========================="
echo "Date: $(date)"
echo "Target: $TARGET_URL"
echo ""
echo "Compromise Details:"
echo "------------------"
echo "Q1 - Timestamp (Unix): $COMPROMISE_TIMESTAMP"
echo "Q2 - Exploit Parameter: $EXPLOIT_PARAM"
echo "Q3 - Compromised Endpoint: $COMPROMISED_ENDPOINT"
echo ""
echo "Flag Format: HLB2025-${COMPROMISE_TIMESTAMP}-${EXPLOIT_PARAM}-$
{COMPROMISED_ENDPOINT}"
echo ""
echo "Suspicious Activity Summary:"
echo "---------------------------"
cat "$TEMP_DIR/attacker_requests.txt"
echo ""
echo "Recent Modified Files:"
echo "---------------------"
cat "$TEMP_DIR/recent_modified_files.txt"
} > "$OUTPUT_FILE"

echo "[*] Investigation complete. Results saved to $OUTPUT_FILE"


echo "[*] Temporary files stored in $TEMP_DIR (consider cleaning up)

Common questions

Powered by AI

The script ensures the isolation and secure processing of data during the investigation by creating a temporary directory under '/tmp/hlb_investigation_<timestamp>' for storing outputs. This minimizes the risk of data being inadvertently altered or accessed by unauthorized users, as the working files and results are kept separate from regular system operations until deletion or final consolidation .

The 'analyze_logs()' function contributes to identifying suspicious activities by processing Apache log files to extract data relevant to security. It searches logs for requests from a specified attacker IP, extracts potential exploit patterns such as directory traversal and code execution attempts, isolates POST requests to PHP files, and identifies parameters used in potential attacks. This information is then organized into separate files for further analysis to support the detection of suspicious activities .

The 'gather_system_info()' function collects system information such as kernel version and architecture ('uname -a'), environmental variables, running processes, active network connections, and scheduled cron jobs. This information is crucial as it provides insights into the system configuration, potential misconfigurations, vulnerabilities, and unauthorized processes or network connections that could indicate compromised systems .

The script searches for significant patterns in Apache logs that are common indicators of security threats including directory traversal ('../'), null byte attacks ('%00'), and PHP code execution patterns like eval() and system(). It also looks for base64 encoded inputs, potentially malicious PHP open or echo tags, and hexadecimal encoding indicative of shell commands. These patterns help identify activities that may suggest attempts to exploit vulnerabilities on the server .

If the attacker IP identified by the script is dynamic or spoofed, there are significant implications for the accuracy of the investigation. Dynamic IPs can change frequently, making it difficult to track ongoing threats or correlate events. Spoofed IPs can mislead investigators, attributing attacks to incorrect sources, and may omit real sources of malicious activity from analysis. These factors complicate efforts to mitigate threats and can result in focusing responses on irrelevant targets .

The 'identify_compromise()' function determines the timestamp of the observed compromise by identifying log entries related to 'team.php' requests that returned a 200 status code. It extracts the timestamp from the first matching log entry, converts it into Unix timestamp format for consistency in reporting. Potential shortcomings include failing to find the compromise if 'team.php' does not explicitly appear in the logs, or timestamps might be inaccurate if logs were modified .

The script identifies recent modifications in the web root directory by using the 'find' command to list files modified in the last 7 days. This is significant because unauthorized modifications within this directory might indicate successful exploitation attempts, where an attacker uploads malicious payloads or alters web content to compromise or further infiltrate the server .

The definition of the 'COMPROMISED_ENDPOINT' is limited to endpoints explicitly logged in the suspicious requests file, specifically those involving 'team.php'. If an attacker uses an endpoint that doesn't match this pattern or obfuscates their requests sufficiently to avoid detection, the script might not accurately identify the true endpoint of compromise. This limitation could lead to incomplete conclusions regarding the scope and nature of the compromise .

The primary goal of the 'HLB2025 Investigation Script' is to investigate potential security breaches targeting a web server at the URL 'http://217.182.69.60:3600/'. It achieves this through several steps: analyzing system logs for suspicious activity, identifying the compromise details including timestamps and exploited parameters, gathering system information, and compiling a detailed investigation report. The script searches for activity from a specific attacker IP and common exploit patterns, checks for recent file modifications, and creates a report outlining its findings .

Improving the accuracy and depth of the conclusions reached by the script could involve several strategies: integrating additional detection mechanisms such as anomaly-based intrusion detection systems for broader monitoring, enhancing log analysis to cover more diverse log sources or deeper log histories, implementing machine learning for pattern recognition in log activity, and correlating network data with logs to identify compromised communication channels. Additionally, involving threat intelligence to understand known attacker tactics can help refine parameters and improve threat identification specificity .

You might also like