注入进阶:从布尔盲注到堆叠注入的全场景突破

SQL 注入作为 CTF Web 题型中的 “常青树”,其核心在于利用数据库查询语句的构造漏洞,通过精心设计的 Payload 获取或篡改数据。上一篇我们探讨了信息泄露的挖掘技巧,而 SQL 注入往往是在信息泄露的基础上进一步突破的关键手段。本文将从基础注入类型讲起,深入分析不同数据库的特性差异,详解 WAF 绕过技巧,并结合 CTF 真题演示完整解题流程,附实用脚本与 Payload 案例。

SQL 注入的本质是 “用户输入被当作 SQL 语句执行”,根据回显方式和利用场景,可分为以下几类,从易到难覆盖绝大多数 CTF 场景:

原理:通过UNION SELECT语句拼接额外查询,从数据库中读取数据,适用于有明确回显的场景(如查询结果直接显示在页面上)。

核心步骤:

plaintext

实战技巧:若回显位被 HTML 实体编码(如<被转义为&lt;),可通过hex()或concat_ws()函数将结果转为十六进制或拼接字符串,避免显示异常。

当注入点无直接回显(页面仅返回 “正常 / 错误” 或无变化)时,需通过布尔判断或时间延迟推导数据,这类注入的核心是 “逐字符爆破”。

利用SUBSTRING()、ASCII()等函数判断字符是否匹配,通过页面 “显示正常” 或 “显示错误” 的状态差异推导数据。

核心 Payload 结构:

当布尔盲注无页面状态差异时(如无论输入什么都返回相同内容),可利用SLEEP()等函数通过 “延迟响应” 判断条件是否成立。

核心 Payload 结构:

手动爆破效率极低,需编写脚本自动化逐字符猜解。以下是布尔盲注脚本示例(以 MySQL 为例):

优化技巧:

当数据库开启错误提示时,可通过特殊函数触发报错,直接在错误信息中显示数据,这类注入效率远高于盲注。

PostgreSQL 可通过pg_sleep()、raise_exception等函数报错:

部分数据库(如 MySQL)支持;分隔多条语句,堆叠注入可在查询后追加INSERT、UPDATE甚至系统命令,危害极大。

核心 Payload 示例:

限制:并非所有数据库都支持堆叠注入(如 SQL Server 部分版本支持,Oracle 不支持),且需注入点位于SQL语句末尾(如id=1'后的注入可追加语句,而id=1 and '1'='1中间的注入则无法堆叠)。

不同数据库的语法和函数存在差异,CTF 中需根据题目环境调整 Payload,以下是常见数据库的核心区别:

实战技巧:若无法确定数据库类型,可通过VERSION()(MySQL)、VERSION()(PostgreSQL)、sqlite_version()(SQLite)函数判断,或根据报错信息中的关键词(如MySQL server version、PostgreSQL syntax)识别。

Web 应用防火墙(WAF)常通过过滤select、union等关键词拦截注入,绕过的核心是 “混淆关键词” 或 “利用解析差异”。

题目场景:访问?id=1返回正常页面,?id=1'返回错误页面,无其他回显,推测为布尔盲注。

解题步骤:

核心脚本片段(爆破 flag 字段):

题目场景:输入1'报错,输入1' or 1=1#返回所有数据,推测存在堆叠注入。

解题步骤:

SQL 注入的核心在于 “理解数据库语法” 与 “灵活构造 Payload”,从基础的联合查询到复杂的盲注脚本,再到 WAF 绕过技巧,每一步都需要结合题目场景灵活调整。在 CTF 中,建议优先判断注入类型(有回显 / 无回显),再选择最高效的利用方式(如报错注入优先于盲注),同时注意数据库特性差异和 WAF 过滤规则。

掌握 SQL 注入不仅能在 CTF 中快速拿分,更能帮助理解 Web 安全的核心 ——“用户输入不可信”。下一篇将聚焦 “逆向工程中的字符串与算法破解”,敬请期待!

312 阅读

44 阅读

13594 阅读

13444 阅读

12989 阅读

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。 2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

THE END
0.github.com/Admirepowered/APatch/commit/77bcb51082e99c7a411ddis_mounted $POINT; then + local BLOCK=$(find_block $PART) + mount $FLAG $BLOCK $POINT || return + fi + ui_print "- Mounting $POINT" +} + +# mount_ro_ensure +mount_ro_ensure() { + # We handle ro partitions only ihttps://github.com/Admirepowered/APatch/commit/77bcb51082e99c7a411dd5949c2c5e44e857e8bf.diff
1.JsonSource.AdditionalColumnsProperty(Azure.ResourceManagerDataFactoryPipelineReferenceType DataFactoryPipelineRunEntityInfo DataFactoryPipelineRunInfo DataFactoryPrivateEndpointConnectionCreateOrUpdateContent DataFactoryPrivateEndpointConnectionProperties DataFactoryPrivateEndpointProperties DataFactoryPrivateLinkResource DataFactoryPrivateLinkResourceProperties DataFactoryPublicNhttps://docs.microsoft.com/id-id/dotnet/api/azure.resourcemanager.datafactory.models.jsonsource.additionalcolumns?view=azure-dotnet
2.cvelistv5CVE2019CVE Details for CVE: CVE-2019-16905 Summary OpenSSH 7.7 through 7.9 and 8.x before 8.1, when compiled with an experimental key type, has a pre-authentication integer overflow if a client or server is configured to use a crafted XMSS key. This leads to memory corruption and local code exehttps://cvepremium.circl.lu/cve/CVE-2019-16905
3.mirrors.aliyun.com/CTAN/help/greek/gentle/gentlGi`a n`a xana\-epi\-str'e\-youme st`a {\rm roman}, gr'afoume st`on k'wdika {\tt \\rm}. Gi`a par'adeigma, e>~inai dunat`o n`a >'eqoume t`hn >ak'oloujh >agglik`h pr'otash st`on k'wdik'a mac: {\tt I started with roman type, \\it switched to italic https://mirrors.aliyun.com/CTAN/help/greek/gentle/gentl-gr.tex
4.Rockymyxstep1:curl https://raw.githubusercontent.com/dvershinin/apt-get-centos/master/apt-get.sh -o /usr/local/bin/apt-getstep2:chmod 0755 /usr/local/bin/apt-get 2020-10-13 17:38:29 680 原创 多机多卡技术测试-单节点多DCU(数据传输型)https://me.csdn.net/blink/qq_33562636
5.\inputmacfonthistorians aspire (Grundmann, p. 1; Guen\'{e}e, p. 25,\emph{et passim}).\bigskip The story of William Longsword provides a particularly good example of the conspiracy, supported by ecclesiastical and secular writers alike, to cook an embarassingly raw https://people.bu.edu/bobl/longsword.htm
6.西湖论剑2025Writeup(8,b'\x00'))addr32=lambdas:u32(io.recvuntil(s,drop=True,timeout=1).ljust(4,b'\x00'))addr64=lambdas:u64(io.recvuntil(s,drop=True,timeout=1).ljust(8,b'\x00'))byte=lambdan:str(n).encode()info=lambdas,n:print("\033[31m["+s+" -> "+str(hex(n))+"]\033[0m")sh=https://blog.xmcve.com/2025/01/19/%E8%A5%BF%E6%B9%96%E8%AE%BA%E5%89%91-2025-Writeup/
7.ffmpeg命令参数详解(二)ffmpegsimddct-target type specify target file type ("vcd", "svcd", "dvd", "dv", "dv50" , "pal-vcd", "ntsc-svcd", ) -xerror exit on error Advanced options: -map file:stream[:syncfile:syncstream] set input stream mapping -map_meta_data outfile:infile set meta data information of outfilehttps://m.blog.csdn.net/lbaihao/article/details/52138690
8.西湖论剑初赛Web1/5|r.content_type = "text/plain" local t = io.popen('/readflag') local a = t:read("*all") r:puts(a) if r.method == 'GET' then for k, v in pairs( r:parseargs() ) do r:puts( string.format("%s: %s\n", k, v) ) https://guokeya.github.io/post/qKqMPs-ml/
9.gcc.gnu.orgGitmsgstr "AltiVec-argumentti välitetty funktiolle, jolla ei ole prototyyppiä"#: config/s390/s390.c:16057-#, fuzzymsgid "Entity %qs at %L has a deferred type parameter and requires either the POINTER or ALLOCATABLE attribute"-msgstr ""https://gcc.gnu.org/git?p=gcc.git;a=commitdiff;h=47a665af3bc5bc14bff95f66b3a051a0c8d14fe1
10.InPartialFulfillmentB. t:.Íor::ís, "Tile Ilinship oj= iiad.¡ress in Poie' s Dunc-i-ad, " Phil-ologica'l Quart.erl 1' 51 Í îLJ'nJv ê "A: Í l\(L\n'9J¡nu1vn;aJrç! L972)? 8lg -gl. ¡ L6 The a-ccusat i ons road.e aga-_inst Theoh;,a_l-d are acl-al_:https://mspace.lib.umanitoba.ca/xmlui/bitstream/handle/1993/13283/Sheldon_The_meaning.pdf?sequence=1&isAllowed=y
11.[FFmpeg]ffmpeg命令参数详解(帮助说明)强大所有参数-target type specify target file type ("vcd", "svcd", "dvd", "dv", "dv50" , "pal-vcd", "ntsc-svcd", ) -xerror exit on error Advanced options: -map file:stream[:syncfile:syncstream] set input stream mapping -map_meta_data outfile:infile set meta data information of outfilehttps://www.cuplayer.com/player/playercodejs/2014/0711/1432.html
12.github.com/wikimedia/mediawiki/commit/d35cf1708f3bb730dce5c74", @@ -3145,7 +3145,7 @@ "watchlistedit-raw-titles": "Izenburuak:", "watchlistedit-raw-submit": "Jarraitze-zerrenda eguneratu", "watchlistedit-raw-done": "Zure jarraipen zerrenda berritu da.", - "watchlistedit-https://github.com/wikimedia/mediawiki/commit/d35cf1708f3bb730dce5c74e028754cbafdde9f1.patch
13.2024中国能源网络安全大赛②决赛个人赛wgf42420x000000007db0fc10160R--rwd \Device\HarddiskVolume1\Users\ctf\Desktop\777.png export file=mem.raw vol.py -f $file --profile=Win7SP1x64 dumpfiles -Q0x000000007db0fc10-D ./ flag{2shygsbnajwjji} Done | 代理流量 343 号包发现 frp https://www.cnblogs.com/wgf4242/p/18259556
14.typingfrom typing import TypeVar, Iterable, Tuple, Union S = TypeVar('S') Response = Union[Iterable[S], int] # Return type here is same as Union[Iterable[str], int] def response(query: str) -> Response[str]: T = TypeVar('T', int, float, complex) Vec = Iterable[Tuple[T, T]https://docs.python.org/id/3.8/library/typing.html
15.typingfrom typing import TypeVar, Iterable, Tuple, Union S = TypeVar('S') Response = Union[Iterable[S], int] # Return type here is same as Union[Iterable[str], int] def response(query: str) -> Response[str]: T = TypeVar('T', int, float, complex) Vec = Iterable[Tuple[T, T]https://docs.python.org/id/3.7/library/typing.html
16.26.1.typingfrom typing import TypeVar, Iterable, Tuple, Union S = TypeVar('S') Response = Union[Iterable[S], int] # Return type here is same as Union[Iterable[str], int] def response(query: str) -> Response[str]: T = TypeVar('T', int, float, complex) Vec = Iterable[Tuple[T, T]https://docs.python.org/id/3.6/library/typing.html
17.typingfrom collections.abc import Iterable from typing import TypeVar S = TypeVar('S') Response = Iterable[S] | int # Return type here is same as Iterable[str] | int def response(query: str) -> Response[str]: T = TypeVar('T', int, float, complex) Vec = Iterable[tuple[T, T]]https://docs.python.org/id/3.10/library/typing.html
18.从零开始学JAVA(经典)ystore "url","type" 其中: (1) keystore是保留字,表示keystore条目。 (2) url指kestore的URLng url, Properties info) throws SQLException public sta tic Connection getConnection(String url, Stringo.txt","rw"); //得到文件指针和长度 long flag = 0; lon g len = f.length(); //字符https://www.360doc.cn/document/53954678_1055815343.html
19.奇安信攻防社区union联合查询,用于合并左右两侧select语句的结果,得要求两侧select的列数相同,两侧select列数不同发生error,那注入就失败;因此 union注入必须得先进行order by的判断确定列数,后续才能拼接子查询测试。 所以,站点union注入失败的原因在于order by测试没命中 https://forum.butian.net/share/3708
20.bugku论剑场web解题记录lceFIre这里主要需要绕过第一个正则匹配,同时要令$result为真就能得到flag了\d+匹配多个数字字符s 特殊字符圆点 . 中包含换行符D 如果使用$限制结尾字符,则不匹配结尾换行;(详细可百度正则表达式修饰符)这里的/\d+/sD是用来匹配数字,只需字符串就可以绕过is_numeric() 函数用于检测变量是否为数字或数字字符串。https://www.cnblogs.com/lceFIre/p/11628512.html
21.github.com/wikimedia/mediawiki/commit/364f70d6ec6e546eece49007 @@ "prefs-info": "Коьртахаам", "prefs-i18n": "Кхинпараметраш", "prefs-signature": "Куьг", + "continuând cu vechea parolă.", "passwordreset-emailelement": "Nume de utilizator: \n$1\n\nParolă temporară: \n$2", "passwordresethttps://github.com/wikimedia/mediawiki/commit/364f70d6ec6e546eece4900a2754ac6dab79e995.patch