Author: @keltecc
The service is a simple key-value storage.
Users can REGISTER and PUT some information to storage, also they can GET the information back.
In order to store protected information, users can choose ENCRYPTED option, then the information will be stored as encrypted data inside the storage.
TLDR:
- Read a hidden
.hashfile that contains a SHA-256 hash of user's password - OpenSSL is running with
-iter 16option, which is using PBKDF2 function internal - Exploit a well-known property of PBKDF2 which is described in Wikipedia article (
HMAC collisions) - Decrypt the
flagcontent using a password hash from.hashfile (we don't really need the actual password)
Exploit: vuln1_pbkdf2.py
FIX:
Hide the .hash file somehow (rename/move/etc).
TLDR:
- The service doesn't quote arguments of commands (for example:
openssl ${CipherAlgorithm} -e -iter 16 -k ${key} -iv ${iv}) - So we can control arguments of most commands, it may lead to vulnerability
ddcommand is interesting: we can setof=/proc/self/memand overwrite the process memory!- Also we can set
seek=0x7ffc00000000to jump somewhere near the stack (this is a lower bound address) - So now we need to leak actual stack pointer, we will find a PID of running
ddand read/proc/PID/stat - The we will read
/proc/PID/mapsand leak the libc mapping - We need to make another seek from
0x7ffc00000000to real stack address - So we will also set a
conv=sparseargument toddand it will perform seek instead of writing\x00bytes (wow!) - When we have reached the
retof some function, just write a ROP chain and executesystem - In order to make
ddrun infinitely, we will setif=/proc/self/fd/255(this is a special FD used by Bash)
More detailed description could be found in exploit: vuln2_rce.py
FIX:
Wrap commands' arguments with quotes, for example: openssl "${CipherAlgorithm}" -e -iter 16 -k "${key}" -iv "${iv}"