Home

Awesome

Crypton

Crypton is an educational library to learn and practice Offensive and Defensive Cryptography. It is basically a collection of explanation and implementation of all the existing vulnerabilities and attacks on various Encryption Systems (Symmetric and Asymmetric), Digital Signatures, Message Authentication Codes and Authenticated Encryption Systems. Each attack is also supplemented with example challenges from "Capture The Flag" contests and their respective write-ups. Individuals who are already acquainted (or are into CTFs) with this field can use Crypton as a tool to solve challenges based on a particular existing vulnerability.

The library will be continuously updated with attack explanations and CTF challenges! Feel free to email me regarding any suggestions!

I have written a blog post on the timeline of development of this library: https://masterpessimistaa.wordpress.com/2018/08/12/announcing-crypton-an-educational-library-to-learn-offensive-and-defensive-cryptography/

WARNING: The author in no way guarantees that the code is secure. The library is only meant for educational purposes and the code should not be used for implementing in real world. All the example scripts in the library are trivial implementations.

There are different sections in this README:


Motivation

Help CTF players and individuals interested in the field of Cryptography provide a platform for learning attacks in crypto and for experienced CTF players to practice challenges systematically divided into attacks associated with different sub-domains in crypto. Also, illustrate through various attack explanations how proper implementation of protocols is crucial.


Library Structure

picture


Domain Coverage

1. Block Ciphers

S.No.TopicExplanationImpl./ExploitChallenge#
1Block Cipher Basics- working of block ciphers, padding etc.<ul><li>- [x] [link]</li></ul><ul><li>- [ ] </li></ul><ul><li>- [ ] </li></ul>
2Modes of Encryption- different modes of operation on block ciphers: ECB, CBC, CTR<ul><li>- [x] [link]</li></ul><ul><li>- [ ] </li></ul><ul><li>- [ ] </li></ul>
3Block Size Detection- detect blocksize of a block cipher encrypting data on a remote service<ul><li>- [x] [link]</li></ul><ul><li>- [ ] </li></ul><ul><li>- [ ] </li></ul>
4Mode Detection- detect type of mode of encryption: independent or dependent encryption of blocks<ul><li>- [x] [link]</li></ul><ul><li>- [ ] </li></ul><ul><li>- [ ] </li></ul>
5ECB Byte at a Time- byte at a time decryption of a secret string running on a remote service encrypting input+secret in ECB mode<ul><li>- [x] [link]</li></ul><ul><li>- [ ] </li></ul><ul><li>- [x] [link] </li></ul>
6CBC IV Detection- detect the value of Initialisation Vector on a remote service that is encrypting our input using a block cipher in CBC mode<ul><li>- [x] [link] </li></ul><ul><li>- [x] [link] </li></ul><ul><li>- [ ] </li></ul>
7CBC Bit Flipping Attack- exploiting cookie generation mechanism to login as admin when cookie is generated using a block cipher in CBC mode<ul><li>- [x] [link] </li></ul><ul><li>- [ ] </li></ul><ul><li>- [x] [link] </li></ul>
8CBC Byte at a Time- byte at a time decryption of a secret string running on a remote service encrypting input+secret in ECB mode<ul><li>- [x] [link] </li></ul><ul><li>- [x] [link] </li></ul><ul><li>- [ ] </li></ul>
9CBC Padding Oracle Attack- decryption of data encrypted by a vulnerable service providing encryption/decryption<ul><li>- [x] [link] </li></ul><ul><li>- [ ] </li></ul><ul><li>- [x] [link] </li></ul>
10CTR Bit Flipping- exploiting cookie generation mechanism to login as admin when cookie is generated using a block cipher in CBC mode<ul><li>- [x] [link] </li></ul><ul><li>- [ ] </li></ul><ul><li>- [x] [link] </li></ul>

2. RSA Encryption

S.No.TopicExplanationImpl./ExploitChallenge#
1Unpadded RSA Enc/Dec- key generation, distribution, encryption/decryption, verification of decryption formula and padding in RSA<ul><li>- [x] [link] </li></ul><ul><li>- [ ] </li></ul><ul><li>- [ ] </li></ul>
2Direct Root Attack- attack on unpadded RSA with low public key exponent<ul><li>- [x] [link] </li></ul><ul><li>- [ ] </li></ul><ul><li>- [ ] </li></ul>
3Fermat's Factorisation- technique used to factor modulus n when p and q values are in proximity<ul><li>- [x] [link]</li></ul><ul><li>- [x] [link] </li></ul><ul><li>- [x] [link] </li></ul>
4Pollard's p-1 Factorisation- technique to factorise n when both of it's factors p & q, p-1 and q-1 have very small prime divisors<ul><li>- [x] [link]</li></ul><ul><li>- [x] [link] </li></ul><ul><li>- [x] [link] </li></ul>
5Common Modulus Attack- decrypt ciphertext when it's corresponding plaintext is encrypted two different times with the same modulus n<ul><li>- [x] [link]</li></ul><ul><li>- [x] [link] </li></ul><ul><li>- [x] [link] </li></ul>
6Common Prime Attack- retrieve factors of moduli n1 and n2 when they have a common factor<ul><li>- [x] [link]</li></ul><ul><li>- [ ] </li></ul><ul><li>- [x] [link] </li></ul>
7Wiener's Attack- get value of decryption key exponent d when d < N<sup>0.25</sup><ul><li>- [x] [link]</li></ul><ul><li>- [x] [link] </li></ul><ul><li>- [x] [link] </li></ul>
8Wiener's Attack Variant- get value of decryption key exponent d when d is a few bits greater than N<sup>0.25</sup> or d < N<sup>0.25</sup><ul><li>- [x] [link]</li></ul><ul><li>- [x] [link] </li></ul><ul><li>- [x] [link] </li></ul>
9Coppersmith's Attack- coppersmith's theorem, attack on stereotyped messages and factoring n with high bits known<ul><li>- [x] [link]</li></ul><ul><li>- [x] [link] </li></ul><ul><li>- [x] [link] </li></ul>
10Franklin Reiter Related Message Attack- attack to retrieve related messages encrypted using the same modulus<ul><li>- [x] [link]</li></ul><ul><li>- [x] [link] </li></ul><ul><li>- [x] [link] </li></ul>
11Hastad's Broadcast Attack- with extension- attack to retrieve a message broadcasted among different people, encrypted using same exponent but different moduli<ul><li>- [x] [link]</li></ul><ul><li>- [x] [link] </li></ul><ul><li>- [x] [link] </li></ul>
12PKCS1-v1.5-Padded-RSA-Encryption/Decryption- ASN1 encoding, padded RSA encryption (needs to be fixed)<ul><li>- [ ] </li></ul><ul><li>- [ ] </li></ul><ul><li>- [ ] </li></ul>
13Least Significant Bit Oracle Attack- attack on RSA oracle leaking least significant bit value on decryption<ul><li>-[x] [link]</li></ul><ul><li>-[x] [link] </li></ul><ul><li>- [ ] </li></ul>
14Attack-Retrieve-Modulus- attack on RSA oracle to extract value of modulus in case it is not public<ul><li>-[x] [link] </li></ul><ul><li>-[x] [link] </li></ul><ul><li>-[x] [link] </li></ul>
15Intro-RSA-Challenges- basic challenges in RSA related to Number Theory<ul><li>- [x] [link]</li></ul><ul><li>- [ ] </li></ul><ul><li>- [x] [link] </li></ul>

3. Message Authentication Codes (MACs)

S.No.TopicExplanationImpl./ExploitChallenge#
1Message Authentication Code- internals and security analysis of MACs<ul><li>- [x] [link]</li></ul><ul><li>- [ ] </li></ul><ul><li>- [ ] </li></ul>
2CBC MAC Forgery- generating two message M1 and M2 having the same CBC-MAC authentication tag<ul><li>- [x] [link]</li></ul><ul><li>- [ ] </li></ul><ul><li>- [x] [link] </li></ul>
3Length Extension Attack on CBC-MAC- generate a valid authentication tag of message M1 || M2 (concatenation) given MAC(M1)<ul><li>- [x] [link]</li></ul><ul><li>- [x] [link] </li></ul><ul><li>- [ ] </li></ul>

4. Discrete Logarithm Problem

S.No.TopicExplanationImpl./ExploitChallenge#
1DLP- Cyclic Groups, Discrete Logarithm Problem<ul><li>- [x] [link]</li></ul><ul><li>- [ ] </li></ul><ul><li>- [x] [link] </li></ul>
2Pollard's Rho Algorithm to solve DLP<ul><li>- [x] [link]</li></ul><ul><li>- [x] [link]</li></ul><ul><li>- [x] [link]</li></ul>
3Baby Step Giant Step Algorithm to solve DLP<ul><li>- [x] [link]</li></ul><ul><li>- [x] [link]</li></ul><ul><li>- [ ] </li></ul>
4Pohlig Hellman Algorithm to solve DLP<ul><li>- [x] [link]</li></ul><ul><li>- [x] [link]</li></ul><ul><li>- [ ] </li></ul>
5Elliptic Curve DLP- defining identity element, inverse of a point, cyclic groups over points on an EC, Hasse's theorem, ECDLP<ul><li>- [x] [link]</li></ul><ul><li>- [ ] </li></ul><ul><li>- [ ] </li></ul>
6Baby Step Giant Step Algorithm to solve Elliptic Curve DLP<ul><li>- [x] [link]</li></ul><ul><li>- [x] [link]</li></ul><ul><li>- [ ] </li></ul>
7Pollard's Rho Algorithm to solve Elliptic Curve DLP<ul><li>- [x] [link]</li></ul><ul><li>- [x] [link]</li></ul><ul><li>- [x] [link]</li></ul>

5. ElGamal Encryption

S.No.TopicExplanationImpl./ExploitChallenge#
1ElGamal Cryptosystem- Encryption/Decryption- key generation, encryption, decryption in ElGamal Cryptosystem<ul><li>- [x] [link]</li></ul><ul><li>- [x] [link] </li></ul><ul><li>- [x] [link]</li></ul>

6. Authenticated Encryption (AE)

S.No.TopicExplanationImpl./ExploitChallenge#
1AE basics & internals- working of authenticated encryption<ul><li>- [x] [link]</li></ul><ul><li>- [ ] </li></ul><ul><li>- [ ] </li></ul>
2AE with MACs- different techniques of implementing AE with MACs: Encrypt and MAC, MAC then encrypt and encrypt then MAC<ul><li>- [x] [link]</li></ul><ul><li>- [ ] </li></ul><ul><li>- [ ] </li></ul>
3Authenticated Ciphers<ul><li>- [x] [link]</li></ul><ul><li>- [ ] </li></ul><ul><li>- [ ] </li></ul>
4AE with Associated Data<ul><li>- [x] [link]</li></ul><ul><li>- [ ] </li></ul><ul><li>- [ ] </li></ul>
5AES-GCM- encryption in AES-GCM, Wegman-Carter MAC<ul><li>- [x] [link]</li></ul><ul><li>- [x] [link] </li></ul><ul><li>- [ ] </li></ul>
6Forbidden Attack on AES-GCM- attack on AES-GCM due to nonce-reuse<ul><li>- [x] [link]</li></ul><ul><li>- [ ] </li></ul><ul><li>- [x] [link] </li></ul>

7. Elliptic Curves

S.No.TopicExplanationImpl./ExploitChallenge#
1Elliptic Curve Internals- defining Elliptic Curves, point addition, point doubling and scalar multiplication<ul><li>- [x] [link]</li></ul><ul><li>- [x] [python], [sage]</li></ul><ul><li>- [ ] </li></ul>

8. Digital Signatures

S.No.TopicExplanationImpl./ExploitChallenge#
1ElGamal Signatures- key generation, signature generation, signature verification and correctness of ElGamal Signature scheme<ul><li>- [x] [link]</li></ul><ul><li>- [x] [link]</li></ul><ul><li>- [x] [link]</li></ul>
2Elliptic Curve DSA- signature generation, signature verification and correctness of signature algorithm<ul><li>- [x] [link]</li></ul><ul><li>- [ ] </li></ul><ul><li>- [ ] </li></ul>
3Attack k-reuse ECDSA- forging of ECDSA signatures due to reuse of k<ul><li>- [x] [link]</li></ul><ul><li>- [ ] </li></ul><ul><li>- [ ] </li></ul>
4Unpadded RSA Digital Signatures- signature generation and verification in RSA digital signature scheme<ul><li>- [x] [link]</li></ul><ul><li>- [x] [link]</li></ul><ul><li>- [ ] </li></ul>
5PKCS1-v1.5 padded RSA Digital Signatures<ul><li>- [x] [link]</li></ul><ul><li>- [x] [link]</li></ul><ul><li>- [ ] </li></ul>
6e=3 Bleichenbacher's Attack<ul><li>- [x] [link]</li></ul><ul><li>- [x] [link]</li></ul><ul><li>- [x] [link]</li></ul>

9. Identification

S.No.TopicExplanationImpl./ExploitChallenge#
1Identification Internals<ul><li>- [x] [link]</li></ul><ul><li>- [ ] </li></ul><ul><li>- [ ] </li></ul>
2Ephemeral Key Authentication<ul><li>- [x] [link]</li></ul><ul><li>- [ ] </li></ul><ul><li>- [x] [link]</li></ul>

10. Diffie Hellman Key Exchange

S.No.TopicExplanationImpl./ExploitChallenge#
1Diffie Hellman Key Exchange Internals<ul><li>- [x] [link]</li></ul><ul><li>- [x] [link]</li></ul><ul><li>- [ ] </li></ul>
2Small Subgroup Confinement Attacks<ul><li>- [x] [link]</li></ul><ul><li>- [x] [link]</li></ul><ul><li>- [x] [link]</li></ul>
3Invalid Curve Point Attack<ul><li>- [x] [link]</li></ul><ul><li>- [x] [link]</li></ul><ul><li>- [x] [link]</li></ul>

TODO

  1. RSA Encryption
    • PKCS1-v1.5 Padded RSA encryption
    • Chosen Ciphertext Attack on RSA Cryptosystem- LSB Decryption Oracle [Done]
    • Padding Oracle Attack on PKCS1 padded RSA encryption system
    • Fermat's Factorisation
      • Sieve Improvement
    • Coppersmith's Attack
      • Boneh Durfee Attack
    • Hastad's Broadcast Attack
      • Implementation of HBA on padded messages
  2. Pseudo-Random-Number-Generators
    • Linear Congruential Generator
    • Mersenne Twister PRNG
    • Linear Feedback Shift Register
  3. Digital Signatures
    • Blinding Attack on RSA Digital Signatures
  4. Diffie Hellman Key Exchange[Done]
    • Elliptic Curve Diffie Hellman
  5. [More to be added]

Author

Ashutosh Ahelleya