文章目录
DVWA通关教程(上)传送门
File Upload
文件上传漏洞
程序开发者对访客提交的数据没有进行检验或者过滤不严,那么就会让攻击者的恶意文件上传成功,导致不堪设想的后果
low级别
源码
if( isset( $_POST[ 'Upload' ] ) ) {
// Where are we going to be writing to?
$target_path = DVWA_WEB_PAGE_TO_ROOT . "hackable/uploads/";
$target_path .= basename( $_FILES[ 'uploaded' ][ 'name' ] );
// Can we move the file to the upload folder?
if( !move_uploaded_file( $_FILES[ 'uploaded' ][ 'tmp_name' ], $target_path ) ) {
// No
$html .= '<pre>Your image was not uploaded.</pre>';
}
else {
// Yes!
$html .= "<pre>{
$target_path} succesfully uploaded!</pre>";
}
}
$target_path .= basename(path,suffix)相当于
$target_path = $target_path . basename(path,suffix)
basename(path,suffix)返回path中文件名部分
$_FILES[‘uploaded’][‘name’]获取客户端文件的原名称
所以target_path就是文件上传的路径+文件名
move_uploaded_file(file,newloc)函数将上传的文件移动到新位置。
如果上传的文件不能移动到uploads目录中,则输出不能上传
随便上传了一个php一句话木马,显示上传成功
查看靶机,确实上传成功了
- url输入刚刚上传点,然后手动利用一句话木马getshell
- pass是木马需要传值的参数
- system(str) 是执行cmd命令的函数
可以看到dir命令成功执行,成功显示当前目录结构,只不过是乱码,乱码
后面查了资料,只需要在上传的shell.php加入以下这么一行
一句话木马执行的语句不再乱码!
- 利用中国蚁剑getshell
因为中国蚁剑好像要用post请求getshell,所以我把刚刚上传的shell.php的get请求改为了post请求
然后设置好木马的url和需要提交数据的参数(也就是密码),点击添加
然后靶机所有目录都被看得一清二楚了
中国蚁剑下载传送门
medium级别
源码
if( isset( $_POST[ 'Upload' ] ) ) {
// Where are we going to be writing to?
$target_path = DVWA_WEB_PAGE_TO_ROOT . "hackable/uploads/";
$target_path .= basename( $_FILES[ 'uploaded' ][ 'name' ] );
// File information
$uploaded_name = $_FILES[ 'uploaded' ][ 'name' ];
$uploaded_type = $_FILES[ 'uploaded' ][ 'type' ];
$uploaded_size = $_FILES[ 'uploaded' ][ 'size' ];
// Is it an image?
if( ( $uploaded_type == "image/jpeg" || $uploaded_type == "image/png" ) &&
( $uploaded_size < 100000 ) ) {
// Can we move the file to the upload folder?
if( !move_uploaded_file( $_FILES[ 'uploaded' ][ 'tmp_name' ], $target_path ) ) {
// No
echo '<pre>Your image was not uploaded.</pre>';
}
新增检测条件:文件类型要为image/jpeg或者image/png并且文件大小小于100000B
尝试上传shell1.php
预料之中的失败,然后用bp抓包,尝试修改文件类型content-type:image/jpeg
成功绕过
查看靶机确实上传成功
php文件的内容也没解析成图片形式,可以正常执行
high级别
源码
$target_path = DVWA_WEB_PAGE_TO_ROOT . "hackable/uploads/";
$target_path .= basename( $_FILES[ 'uploaded' ][ 'name' ] );
// File information
$uploaded_name = $_FILES[ 'uploaded' ][ 'name' ];
$uploaded_ext = substr( $uploaded_name, strrpos( $uploaded_name