You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SECRET_SALT is too easily guessable, leads to security issues #599
Describe the bug
The SECRET_SALT value used for escaping and replacing content only allows for 1000000 values, which is trivial to bruteforce. It's bytes(randint(0, 1000000)) in the code and I'm not sure if it's working as intended (currently it only creates null bytes of n length).
To Reproduce
Generate a list of all possible values:
data = ''
def _hash_text(s: str, SECRET_SALT_I) -> str:
return 'md5-' + sha256((b"\x00"*SECRET_SALT_I) + s.encode("utf-8")).hexdigest()[32:]
for i in range(1000000):
data += str(i) + ":" + _hash_text("!", i) + "\n"
Process the data value with markdown2 somehow.
Find the line with ! in the result.
Use that numeric value with the _hash_text function to achieve arbitrary injection.
Expected behavior
SECRET_SALT is unpredictable enough
Debug info
Version of library being used: 2.5.0
Any extras being used: None
Additional context
I found this during a CTF :P.
SECRET_SALT should probably be changed to secrets.randbits(256) or something similar. It'd also make the performance of the library better as sha256ing 1000000 null bytes is a noticable performance hit.
Reacted by witer33, Salvatore Abello, Sijisu, Lorenzo Corrias, Avamander and Valeryum999
Thanks! We use that hash to omit certain chunks of text from further processing. I can't think of a specific security issue that might come about, but this is probably worth it just for a minor performance bump and simplification.
If you'd like to try it yourself I suggest editing the 1000000 both in the demo and the library to a smaller number so that it runs faster - but even the 1000000 is fast enough for real world attacks (I did that for the CTF I was playing).
We're putting our payload in the code tags to turn it into a hash, and then we try to guess that hash by iterating through all the possible salts. We can then use it to force characters such as quotes into other parts of the rendered markdown, which in this case turns the image src tag into XSS.
The output will have something like this nested between everything:
In the real world it'd be possible to improve the attack depending on the specific application and its implementation details, but this works well enough for a quick demo :).
One more thing, @nicholasserra, would it be okay for me to look into getting a CVE assigned for this vuln? I've been wondering what that process looks like and I thought this would be a nice opportunity for me to try it out first-hand.
Activity
nicholasserra commentedon Sep 23, 2024
Thanks! We use that hash to omit certain chunks of text from further processing. I can't think of a specific security issue that might come about, but this is probably worth it just for a minor performance bump and simplification.
rebane2001 commentedon Sep 23, 2024
Happy to share a demo of the vulnerability once a release is out and users affected can update :)
nicholasserra commentedon Oct 9, 2024
Just pushed a release, would love a demo, thanks!
rebane2001 commentedon Oct 9, 2024
Here's a basic demo :)
If you'd like to try it yourself I suggest editing the
1000000both in the demo and the library to a smaller number so that it runs faster - but even the 1000000 is fast enough for real world attacks (I did that for the CTF I was playing).We're putting our payload in the code tags to turn it into a hash, and then we try to guess that hash by iterating through all the possible salts. We can then use it to force characters such as quotes into other parts of the rendered markdown, which in this case turns the image src tag into XSS.
The output will have something like this nested between everything:
In the real world it'd be possible to improve the attack depending on the specific application and its implementation details, but this works well enough for a quick demo :).
One more thing, @nicholasserra, would it be okay for me to look into getting a CVE assigned for this vuln? I've been wondering what that process looks like and I thought this would be a nice opportunity for me to try it out first-hand.
nicholasserra commentedon Oct 9, 2024
Ah, got it. Nice catch, this one took me a second to understand the external user input attack vector here. Thanks!
CVE sounds fine, go for it