SQLi Labs Lesson1

来源:互联网 发布:java定义数组并赋值 编辑:程序博客网 时间:2024/06/05 20:41

SQLI-LABS is a platform to learn SQLI

Following labs are covered for GET and POST scenarios:

1. Error Based Injections (Union Select)
    1. String
    2. Intiger
2. Error Based Injections (Double Injection Based)

3. BLIND Injections:
    1.Boolian Based
    2.Time Based
4. Update Query Injection.
5. Insert Query Injections.
6. Header Injections.
    1.Referer based.
    2.UserAgent based.
    3.Cookie based.
7. Second Order Injections
8. Bypassing WAF
    1. Bypassing Blacklist filters
        Stripping comments
        Stripping OR & AND
        Stripping SPACES and COMMENTS
        Stripping UNION & SELECT
    2. Impidence mismatch
9. Bypass addslashes()
10. Bypassing mysql_real_escape_string. (under special conditions)
11. Stacked SQL injections.

12. Secondary channel extraction


GitHub下载地址:https://github.com/Audi-1/sqli-labs


Lesson-1 Get Error Based Single quotes

中文就是:Get类型 有错误回显 单引号型注入


进入到lesson-1的界面,提示输入以id作为参数的数值




?id=1的结果如图所示



 在1后面加单引号测试,即?id=1'

发现此处单引号没有进行过滤等处理,查看源代码:

$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";$result=mysql_query($sql);$row = mysql_fetch_array($result);


下面开始注入测试

猜测该表的结构

?id=1' union select 1 --+时

(

--+在MySQL中的注释其中两种单行注释 

 1.从‘#’字符从行尾。

 2.从‘-- ’序列到行尾。请注意‘-- ’(双破折号)注释风格要求第2个破折号后面至少跟一个空格符(例如空格、tab、换行符等)。该语法与标准SQL注释语法稍有不同。

)

此时真正执行的SQL语句为:SELECT * FROM users WHERE id='1' union select 1-- ' LIMIT 0,1

后面的 'limit 0,1被注释掉。

此时,错误信息为:

这是因为使用union的两个SQL语句产生的记录的表结构不一致. 必须是结构完全一致的记录集合才可以使用UNION.

说明该表不只有一字段。


?id=1' union select 1,2 --+时

错误信息还是:


?id=1' union select 1,2,3 --+时

当前表(由源代码知也就是users表)有三个字段.

但是由于源代码中,只用了一次fetch_array(),所以只把select * from users where id = '1'的结果作为关联数组,最后echo出来了。

我们可以通过使select * from users where id = '$id' 的结果为空,这样union后面的查询信息就能被echo出来了。

?id=0' union select 1,2,3 --+时


发现select 1,2,3 中的1没有被echo.

在mysql 的命令行中执行查询,第一个字段为用户的id,所以没有被打印。


这样我们就可以通过改变?id=0' union select 1,2,3 --+中union后面的语句来获得我们想要获得的信息。

如:?id=0' union select 1,database(),system_user()--+

返回结果为:


可见当前数据库为security, the system user for the database 为root@localhost

但是用两个字段来显示我们要查询的值。

这个时候就需要这几个很有用的函数:

1. concat(str1,str2,...)——没有分隔符地连接字符串

2. concat_ws(separator,str1,str2,...)——含有分隔符地连接字符串

3. group_concat(str1,str2,...)——连接一个组的所有字符串,并以逗号分隔每一条数据

如:?id=0' union select 1,1,concat_ws(' , ',@@version_compile_os,version(),@@datadir)--+



常用查询函数

1:system_user() 系统用户名
2:user() 用户名
3:current_user 当前用户名
4:session_user()连接数据库的用户名
5:database() 数据库名
6:version() MYSQL数据库版本 @@version
7:load_file() MYSQL读取本地文件的函数
8:@@datadir 读取数据库路径
9:@@basedir MYSQL 安装路径
10:@@version_compile_os 操作系统




0 0
原创粉丝点击