mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
129 lines
3.7 KiB
Markdown
129 lines
3.7 KiB
Markdown
# JSON, XML & Yaml Hacking & Issues
|
||
|
||
{{#include ../banners/hacktricks-training.md}}
|
||
|
||
## Go JSON Dekoder
|
||
|
||
Die volgende probleme is in die Go JSON opgespoor, alhoewel dit ook in ander tale teenwoordig kan wees. Hierdie probleme is gepubliseer in [**hierdie blogpos**](https://blog.trailofbits.com/2025/06/17/unexpected-security-footguns-in-gos-parsers/).
|
||
|
||
Go se JSON, XML, en YAML parsers het 'n lang pad van inkonsekwenties en onveilige standaardinstellings wat misbruik kan word om **authentisering te omseil**, **privileges te eskaleer**, of **sensitiewe data te ekfiltreer**.
|
||
|
||
### (Un)Marshaling Onverwagte Data
|
||
|
||
Die doel is om strukture te benut wat 'n aanvaller toelaat om sensitiewe velde te lees/schryf (bv. `IsAdmin`, `Password`).
|
||
|
||
- Voorbeeld Struktuur:
|
||
```go
|
||
type User struct {
|
||
Username string `json:"username,omitempty"`
|
||
Password string `json:"password,omitempty"`
|
||
IsAdmin bool `json:"-"`
|
||
}
|
||
```
|
||
- Algemene Kw vulnerabilities
|
||
|
||
1. **Ontbrekende etiket** (geen etiket = veld word steeds standaard verwerk):
|
||
```go
|
||
type User struct {
|
||
Username string
|
||
}
|
||
```
|
||
Payload:
|
||
```json
|
||
{"Username": "admin"}
|
||
```
|
||
2. **Onkorrekte gebruik van `-`**:
|
||
```go
|
||
type User struct {
|
||
IsAdmin bool `json:"-,omitempty"` // ❌ wrong
|
||
}
|
||
```
|
||
Payload:
|
||
```json
|
||
{"-": true}
|
||
```
|
||
✔️ Regte manier om 'n veld te blokkeer van (un)marshaling:
|
||
```go
|
||
type User struct {
|
||
IsAdmin bool `json:"-"`
|
||
}
|
||
```
|
||
### Parser Differentials
|
||
|
||
Die doel is om outorisasie te omseil deur te benut hoe verskillende parsers dieselfde payload verskillend interpreteer soos in:
|
||
- CVE-2017-12635: Apache CouchDB omseiling via duplikaat sleutels
|
||
- 2022: Zoom 0-click RCE via XML parser inkonsekwentheid
|
||
- GitLab 2025 SAML omseiling via XML quirks
|
||
|
||
**1. Duplikaat Velde:**
|
||
Go se `encoding/json` neem die **laaste** veld.
|
||
```go
|
||
json.Unmarshal([]byte(`{"action":"UserAction", "action":"AdminAction"}`), &req)
|
||
fmt.Println(req.Action) // AdminAction
|
||
```
|
||
Ander parsers (bv. Java se Jackson) mag die **eerste** neem.
|
||
|
||
**2. Hooflettergevoeligheid:**
|
||
Go is hooflettergevoelig:
|
||
```go
|
||
json.Unmarshal([]byte(`{"AcTiOn":"AdminAction"}`), &req)
|
||
// matches `Action` field
|
||
```
|
||
Selfs Unicode truuks werk:
|
||
```go
|
||
json.Unmarshal([]byte(`{"aKtionſ": "bypass"}`), &req)
|
||
```
|
||
**3. Kruisdiens-mismatch:**
|
||
Stel jou voor:
|
||
- Proxy geskryf in Go
|
||
- AuthZ diens geskryf in Python
|
||
|
||
Aanvaller stuur:
|
||
```json
|
||
{
|
||
"action": "UserAction",
|
||
"AcTiOn": "AdminAction"
|
||
}
|
||
```
|
||
- Python sien `UserAction`, laat dit toe
|
||
- Go sien `AdminAction`, voer dit uit
|
||
|
||
|
||
### Data Formaat Verwarring (Polyglots)
|
||
|
||
Die doel is om stelsels te exploiteer wat formate meng (JSON/XML/YAML) of wat oopval op parser foute soos:
|
||
- **CVE-2020-16250**: HashiCorp Vault het JSON met 'n XML-parser geparseer nadat STS JSON in plaas van XML teruggestuur het.
|
||
|
||
Aanvaller beheer:
|
||
- Die `Accept: application/json` kop
|
||
- Gedeeltelike beheer van die JSON liggaam
|
||
|
||
Go se XML-parser het dit **tog** geparseer en die ingespoten identiteit vertrou.
|
||
|
||
- Gemaakte las:
|
||
```json
|
||
{
|
||
"action": "Action_1",
|
||
"AcTiOn": "Action_2",
|
||
"ignored": "<?xml version=\"1.0\"?><Action>Action_3</Action>"
|
||
}
|
||
```
|
||
Resultaat:
|
||
- **Go JSON** parser: `Action_2` (nie-sensitief + laaste wen)
|
||
- **YAML** parser: `Action_1` (sensitief)
|
||
- **XML** parser: parseer `"Action_3"` binne die string
|
||
|
||
|
||
### 🔐 Versagtings
|
||
|
||
| Risiko | Regstelling |
|
||
|-----------------------------|---------------------------------------|
|
||
| Onbekende velde | `decoder.DisallowUnknownFields()` |
|
||
| Dubbele velde (JSON) | ❌ Geen regstelling in stdlib |
|
||
| Nie-sensitiewe ooreenkoms | ❌ Geen regstelling in stdlib |
|
||
| XML rommeldata | ❌ Geen regstelling in stdlib |
|
||
| YAML: onbekende sleutels | `yaml.KnownFields(true)` |
|
||
|
||
|
||
{{#include ../banners/hacktricks-training.md}}
|