Databases β relational or not β are a fundamental component of modern software systems. They often store sensitive data like personal information, salaries, or medical records.
To protect against malicious administrators or attackers who gain access to a database server, one common countermeasure is data encryption. However, even encrypted databases may leak information through indirect channels. One of the most common leakages is order leakage, where the encrypted values preserve the same order as the plaintexts.
In this project, we demonstrate a statistical attack that exploits this order leakage to approximate the original data β specifically, employee salaries.
β οΈ Disclaimer: This project is for educational and research purposes only.
We simulate a realistic dataset of 100 random salaries using a normal distribution centered around 2500β¬/month.
We simulate order-preserving encryption by:
- Sorting the salaries
- Applying a SHA-256 hash on each one
Note: This is not real encryption but simulates how an attacker might see encrypted ordered values.
The attacker:
- Assumes salaries follow a known public distribution (like INSEE data)
- Generates a sorted sample from this known distribution
- Matches the known ranks of the ciphertexts to the estimated ranks
We compare the estimated salaries with the original ones. Since the order is preserved, the attacker gets a surprisingly accurate estimation.
We compute the average absolute error between the real and estimated salaries, which in our simulation is around 83 β¬.
This simulation shows how order leakage β even without direct access to plaintexts β can significantly reduce the security of an encrypted database.
Knowing just the ranking of the encrypted values and the public distribution of the data, an attacker can perform a surprisingly effective inference attack.
To mitigate this, consider:
- Using fully homomorphic encryption (at cost)
- Avoiding order-revealing structures unless absolutely needed
- Adding noise or padding to make order inference harder
attack_simulation.py: Runs the full simulation with graphs.attack_notebook.ipynb: Visual Jupyter notebook version of the attack.
Helpful Blog -> Attack of the week
Built with β€οΈ for security awareness.