bABE
3 files available
Description
If I'm an hacker, do I also have to be a snake to be a MadrHack?
Solution
The challenge implements a pairing-free CP-ABE scheme, following the one presented in paper 1, and this means that the type of Attribute-Based Encryption uses a Ciphertext policy, where the secret keys are generated over a subset of the attributes of the schema, while data encryption is done using an access tree (i.e. a logical combination of attributes).
The important information here is that the scheme is also pairing-free and as presented by J. Herranz in one of his publications (see paper 2), every scheme that has been implemented without pairing-free elliptic curves is vulnerable to a certain degree.
In our challenge scenario the scheme works with RSA, in fact are used two primes and to generate the RSA modulus and the totient , plus for each attribute of the schema is generated a tuple s.t.
Then is choosen a generator (coprime with ) and are calculated the public parameters:
where
- is the private key pair, which are two random numbers coprime with
During the encryption is calculated a key which is used to encrypt the given plaintext (combination of hashing and xoring), thus being able to retrieve or compute means that we're able to decrypt the ciphertext.
Here is the product of the of the attributes that are not in the encryption policy.
In fact in the decryption function, is used the secret key pair (generated from a subset of attributes) to compute , by exponentating and respectively to and . The decryption works because and are public parameters (included in the ciphertext) and the pair let us re-compute the correct iff are generated from the same set of attributes used to encrypt the plaintext.
The last statements should be always true, but this challenge highlights how is not always the case and why is vulnerable.
In fact, if a plaintext has been encrypted over a set of attributes , for which we can't generate the key pair, but and we're able to generate multiple key pairs such that they cover all attributes in , then we can compute the correct for and decrypt the ciphertext.
Attack
In our challenge and the attacker could generate the key pair for a single attribute a time, while the ciphertext was encrypted using both attributes togheter.
However the attacker can get the key pairs for the single attributes ( and ) recover .
We recall that in the decryption function is computed as follows:
where is the product of the of the attributes that are not in the ciphertext policy. In the challenge it was the case that , because all two attributes where used to encrypt the flag, so .
Because of how the secret pair is created, we have that
and
thus we can compute
Now because we know both primes and and we know that are coprime, we can compute two values such that with the extended Euclidean algorithm and finally we can raise the results previously computed to these two values to retrieve :
Having found the key of the ciphertext we're not able to decrypt the message.
Flag
snakeCTF{p4iring_fr33_4B3_1s_br0k3n}
References
- Expressive CP-ABE Scheme Satisfying Constant-Size Keys and Ciphertexts (2019)
- Attacking Pairing-Free Attribute-Based Encryption Schemes - J. Herranz (2020)
The .pdf
of the papers listed above can be found here PDFs.