Inclusion asks the interpreter to bring another file into the current execution. If the user chooses the file, the user chooses part of the program.
The application builds an include path from a page or template parameter. Traversal escapes the pages directory, and wrappers or logs can turn a local file into readable data.
A page name feels like navigation. The interpreter sees an include. The attacker speaks to the interpreter.
What is actually at stake?
Before touching a payload, map the assets, the actors and the boundary that is supposed to protect them. A finding only becomes a vulnerability when you can connect the failed boundary to a real asset.
Assets
- Application source and configuration
- Log files containing secrets
- Uploaded files and session data
- Server-side code execution
Actors
- User who controls a template, language or page parameter
- Attacker with an upload feature
- Malicious content in a log or cache
Trust boundaries
- Request parameter to include path
- Include root to filesystem
- Uploaded content to executed code
- Log file to code path
Abuse cases
- Include ../../secret/flag.txt
- Use php://filter to read source
- Include a log file containing a crafted payload
- Include an uploaded image with embedded PHP
- Escalate disclosure to remote code execution
Follow the decision, not the payload
Every family has a moment where trusted data becomes an authorization, parsing or state decision. Learn to point at that moment in the request path.
- 01
Accept
A route chooses a template, language file, page or module by name.
- 02
Resolve
The runtime joins the name with a base path and resolves traversal, wrappers or stream filters.
- 03
Include
The file is read as code or data and executed in the current process.
- 04
Execute
Any code in the included file runs with application privileges; even a non-PHP file may disclose source.
- 05
Persist
Logs, uploads and cache files can become a delivery path when the include primitive is available.
phpMyAdmin local file inclusion, CVE-2018-12613
CVE-2018-12613, public advisoryphpMyAdmin 4.8.0 and 4.8.1 allowed an attacker to include local files through a crafted target parameter, affecting installations reachable by an authenticated user.
Researchers bypassed the intended whitelist with encoded query separators and traversal, then used the include to read files and, in some configurations, execute code.
The flaw could expose configuration and session data and could lead to code execution when combined with a writable file such as a log.
The include target was derived from user input and the validation did not account for encoded separators and path resolution.
Map user choices to fixed include paths, never pass raw input to include, disable dangerous wrappers, and keep writable files out of executable paths.
Read it as a chain: discovery → failed decision → impact → fix. Then ask which link would have broken earliest.
A repeatable testing sequence
- Find page, view, template, language, module and help parameters.
- Try `../`, encoded traversal and absolute paths.
- Observe whether an extension is appended and whether wrappers are accepted.
- Target the secret file or a file that contains the flag.
Where smart people get fooled
- An appended `.php` extension can sometimes be bypassed.
- Only local files can still be a full confidentiality breach.
- A blocked dot-dot string is not canonical path validation.
What would the logs show?
A control is stronger when someone can see it fail. These signals are starting points for a detection rule, not a complete SIEM use case.
- Parameters containing ../, php://, file://, data:// or expect://
- Include errors that reveal filesystem paths
- Requests for log, session or upload files through a page parameter
- A page parameter that accepts arbitrary names rather than a fixed key
- Code execution from a file inside an upload or log directory
index=web sourcetype=app_logs | eval lfi=if(match(uri,"(?i)(php://|file://|data://|expect://|\.\./|%2e%2e)"),1,0) | where lfi=1 | stats count values(uri) by clientip, status | where status=200Fix the decision, then prove it stays fixed
- Map page IDs to an allowlist of files instead of accepting paths.
- Canonicalize and verify the resolved path inside the include root.
- Disable dangerous wrappers and run with least privilege.
$page = $_GET['page'];
include __DIR__ . '/pages/' . $page . '.php';$pages = [
'home' => __DIR__ . '/pages/home.php',
'billing' => __DIR__ . '/pages/billing.php',
];
$key = $_GET['page'] ?? 'home';
if (!array_key_exists($key, $pages)) { http_response_code(404); exit; }
include $pages[$key];Use a fixed map from a public key to a server path. Do not sanitize a user path and hope it is safe. Disable remote includes and keep uploads outside executable roots.
Regression tests a reviewer would ask for
Traversal include
GivenA page parameter selects a template
WhenThe value is ../../secret/flag.txt
ThenThe request is rejected and no file is included
Wrapper
GivenThe runtime supports stream wrappers
WhenThe value uses php://filter or data://
ThenOnly a fixed key map is accepted and wrappers never reach the include
Log poisoning
GivenLogs are writable and the include primitive exists
WhenA crafted value is written to a log and included
ThenThe include path cannot reach log files
Uploaded file
GivenA user uploads a file with executable content
WhenThe file is requested or included
ThenThe upload directory is non-executable and the file is served as inert data
What this finding is not
Strong testers kill their own findings before someone else does. These are the shortcuts that turn a real bug into a weak report — or a false alarm into a wasted escalation.
- The page shows the filename but not its content: inclusion may be blocked while reflection remains.
- A traversal payload returns an error: try wrappers, encoded separators and alternate parameters.
- Only .php files are allowed: test null bytes on old runtimes, path truncation and wrapper syntax.
- The included file is static: confirm whether it is parsed as code or only read.
Terms you should be able to use precisely
- LFI
- Local file inclusion: a user-influenced path causes the server to include a local file.
- RFI
- Remote file inclusion: the include path points to an attacker-controlled remote resource.
- Stream wrapper
- A runtime protocol such as php://filter that changes how a file is read.
- Log poisoning
- Writing executable content into a log that is later included by a vulnerable page.
- Include map
- A fixed table mapping public keys to trusted server paths.
- Non-executable upload root
- A directory configured so uploaded files are served as data, never executed.
Answer these without reciting a payload
How does LFI become RCE?
The attacker finds a writable file they can influence, such as a log, session file or upload, then includes it so the runtime executes the embedded code.
Why is a fixed include map better than blacklisting ../?
A map has no user-controlled path to traverse. Blacklists miss encodings, wrappers and platform-specific separators.
What is the difference between LFI and path traversal?
Path traversal is the path escape primitive. LFI is the dangerous sink that includes or executes the resolved file.
Can you separate the mechanism from the payload?
Four questions, graded on the server. Answers and explanations are released only after you submit, and signed-in learners keep a best score.
LFI ليست مجرد قراءة ملف؛ هي أن يقرر الخادم تضمين ملف اختاره المستخدم وتنفيذه بصلاحياته.
الحل ليس حجب ../ فقط، بل خريطة ثابتة من مفتاح عام إلى مسار موثوق. عطّل التضمين البعيد والـwrappers الخطرة، واجعل مجلد الرفع غير قابل للتنفيذ. وتذكّر أن السجلات والجلسات والملفات المرفوعة قد تصبح هي نفسها وسيلة تنفيذ إذا استطاع المهاجم الكتابة فيها.
What file did the server actually open after normalization?