Skip to content

Commit 488812f

Browse files
committed
Solutions for cryptoBreaker part 1
1 parent 27790ed commit 488812f

14 files changed

+199
-28
lines changed

trainingportal/qna.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ let analysisEnc = (mes) => {
217217
}
218218
let keyInfoB64 = util.btoa(JSON.stringify(keyInfo));
219219
let postData = `kmb64=${keyInfoB64}`;
220-
let post = `POST / HTTP/1.1\n`;
221-
post+=`Host: finance.biznis\n`;
222-
post+=`Content-length: ${postData.length}\n\n`;
220+
let post = `POST / HTTP/1.1\r\n`;
221+
post+=`Host: finance.biznis\r\n`;
222+
post+=`Content-length: ${postData.length}\r\n\r\n`;
223223
post+= postData;
224224

225225
let mesKey = crypto.randomBytes(16);

trainingportal/static/lessons/cryptoBreaker/crypto_analysis.md

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ In this challenge you will have to leverage all the basic data transformation me
2222

2323
You are given an intercepted cipher text for a client/server application. The intercepted message is an `indicator` which contains information about the golden key. It is being sent periodically to transmit a new the golden key which is then used to digitally sign transactions. The developers of the application have decided to implement a lightweigh message encryption algorithm because the application is used in financial transactions and has to have minimum latency.
2424

25-
**NOTE: Writing your own encryption algorithm or using known weak ciphers to improve performance is a known fallacy. Cryptographic algorithms such as AES 256, at this point in time, have a very strong mathematic foundation and have evolved over multiple iterations to optimize performance and resilience to attacks.**
25+
**NOTE: Writing your own encryption algorithm or using known weak ciphers to improve performance is a known fallacy. Cryptographic algorithms such as AES, at this point in time, have a very strong mathematic foundation and have evolved over multiple iterations to optimize performance and resilience to attacks.**
2626

2727
You know that the application uses HTTP for communication. Having this insight you must determine the key and extract a randomly generated golden key from the message.
2828

@@ -31,32 +31,13 @@ The golden key is wrapped in several layers of encoding so you will need to reco
3131
#### Challenge Tips
3232

3333
- Go back and read some of the previous lessons. They contain information that will help with this challenge.
34-
- HTTP is a well known communication protocol, there are many common words. Keep trying until you reconstruct most of the key.
35-
- If you recover part of the encryption key, pad the missing bytes with 0x0. This way when the key repeats you can uncover more of the message.
34+
- HTTP is a well known communication protocol, there are many common words. Request lines for HTTP messages that send data often look like this: `POST / HTTP/1.1\r\n`
3635
- In one of the previous lessons you've decrypted a key using the plain text and the cipher. That should point you to what algorithm is being used.
37-
- Once you uncover more of the message, or you are able to infer the text, add the correct bytes to the key. Then copy the resulting longer key to a file and identify the repeating bytes.
38-
39-
Example:
40-
41-
//You uncovered the following key bytes: `1 2 3 4`. Now the message looks like this
42-
"PLAIJ#UB]S"
43-
//Add a 0 to the key: `1 2 3 4 0`. Now the message looks like this
44-
"PLAIK TEXQ"
45-
//Now you can probably guess the message but let's assume for the sake of the example that you only know 'TEXT' which gives you the last byte in the sequence `5`. Write all the bytes together
46-
`1 2 3 4 0 1 2 3 4 5`
47-
//Now identify the repeating bytes
48-
`1 2 3 4 0`
49-
`1 2 3 4 5`
50-
//Replace `0` with `5` and apply the new key below to the cipher.
51-
`1 2 3 4 5 1 2 3 4 5`
52-
//Now you are able to decrypt the message
53-
"PLAIN TEXT"
54-
//Note that you don't need to repeat the byte sequence. You can simply use `1 2 3 4 5` as the key.
55-
56-
In our example we used a 5 byte key, however key sizes are usually multiples of 2: 16 bytes, 32 bytes, 64 bytes. Start with 16 and go to higher lengths if needed.
5736

37+
**NOTE: If you decide to use the Solution, open the Solution as a new tab or Window so you don't reset the cipher.**
5838

5939
#### References
6040

6141
- [Wikipedia: Cryptanalysis](https://en.wikipedia.org/wiki/Cryptanalysis)
62-
- [Wikipedia: Cryptanalysis of the Enigma](https://en.wikipedia.org/wiki/Cryptanalysis_of_the_Enigma)
42+
- [Wikipedia: Cryptanalysis of the Enigma](https://en.wikipedia.org/wiki/Cryptanalysis_of_the_Enigma)
43+
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
### Solution for "Cryptanalysis" challenge
2+
3+
This challenge puts together all types of text transformation techniques encountered so far.
4+
5+
You will leverage the fact that you are able to guess the starting line in the message.
6+
7+
The HTTP protocol defines messages that follow the format below:
8+
9+
{HTTP METHOD} {PATH} {PROTOCOL}\r\n
10+
{HEADER 1}:{VALUE 1}\r\n
11+
...
12+
{HEADER N}:{VALUE N}\r\n
13+
\r\n
14+
{OPTIONAL BODY}
15+
\r\n
16+
17+
18+
{HTTP METHOD} can be any of the following: GET, POST, HEAD, OPTIONS, PUT, DELETE, but most commonly GET and POST are used.
19+
20+
POST in particular is used to transmit data in the request body.
21+
22+
A typical request will look like this:
23+
24+
POST /{path} HTTP/{version}
25+
26+
27+
Path can be anything
28+
Version can be 1.0, 1.1, 2 or more. However versions 2 and above are binary protocols so they are a bit more complicated for cryptanalysis.
29+
30+
HTTP/1.1 was the protocol of choice for a very long time so it's a good guess.
31+
32+
You could start with POST / and build up from it, but for the purpose of this challenge let's assume we can guess the entire request line from the start:
33+
34+
POST / HTTP/1.1
35+
36+
Now you can remember the XOR challenge and the property of XOR below:
37+
38+
A ^ B = C
39+
B ^ C = A
40+
A ^ C = B
41+
42+
43+
##### Step 1 - Recover the key
44+
45+
Use a online tool to get the ASCII code for `POST / HTTP/1.1` **in hexadecimal**.
46+
47+
48+
You will get something like this:
49+
50+
50 4F 53 54 20 2F 20 48 54 54 50 2F 31 2E 31
51+
52+
This is only 15 bytes. Add `0D` (CR) to make it 16 bytes, which is a multiple of 2 and likely the length of the key.
53+
54+
50 4F 53 54 20 2F 20 48 54 54 50 2F 31 2E 31 0D
55+
56+
Now **XOR** the assumed plain text with the cipher **as a hexadecimal key** and copy down the resulting first 16 bytes.
57+
58+
41 35 BA 75 45 C3 A0 80 53 0E 5F 54 0A 05 13 CD
59+
60+
61+
##### Step 2 - Recover the HTTP message
62+
63+
64+
Now **XOR** the recovered key bytes with the cipher. Display the result as printable characters:
65+
66+
You will get something like the below.
67+
68+
POST / HTTP/1.1
69+
Host: finance.biznis
70+
Content-length: 326
71+
72+
kmb64=eyJrZXlNYXRlcmlhbFNoaWZ0ZWQiOiJHV01FWUZHIENTRFBBIFVNT0VJRCBFR1JJViBHR0NHTFcgUUNDSiBRQUNQWiBYQUNIRlYgWFRQVlZBIFdXU0lEWiIsImdvbGRlbktleVNoaWZ0SGFzaCI6ImE1MTZmZjc0ZTIyMmMzYmJkM2FiOTI0ZTk2ZmVmZTBjIiwiZ29sZGVuS2V5U2FsdEhhc2giOiJhOGQzMTM5ZTAwNzUyZjg4NzZlNDdiMmZiZGNlMDc0ZCIsImhhc2hpbmdGdW5jdGlvbiI6IlNIQTI1NiIsIml0ZXIiOjEwMDB9
73+
74+
75+
##### Step 3 - Decode the kmb64 parameter
76+
77+
Decode the kmb64 parameter using an online base64 decoder.
78+
79+
Now we can see a JSON message similar to the example below:
80+
81+
{
82+
"keyMaterialShifted":"GWMEYFG CSDPA UMOEID EGRIV GGCGLW QCCJ QACPZ XACHFV XTPVVA WWSIDZ",
83+
"goldenKeyShiftHash":"a516ff74e222c3bbd3ab924e96fefe0c",
84+
"goldenKeySaltHash":"a8d3139e00752f8876e47b2fbdce074d",
85+
"hashingFunction":"SHA256",
86+
"iter":1000
87+
}
88+
89+
##### Step 4 - Look-up the hashes
90+
91+
Using your online rainbow table of choice identify the Shift and the Salt hashes.
92+
93+
For the given example:
94+
95+
a516ff74e222c3bbd3ab924e96fefe0c - LOREM
96+
a8d3139e00752f8876e47b2fbdce074d - VIVAMUS
97+
98+
##### Step 5 - Unscramble the key material using Vigenère
99+
100+
Using an online tool unscramble the text using the value associated with `goldenKeyShiftHash` as a key:
101+
102+
GWMEYFG CSDPA UMOEID EGRIV GGCGLW QCCJ QACPZ XACHFV XTPVVA WWSIDZ
103+
VIVAMUS LOREM DICTUM AUGUE CURSUS EROS MORBI TORTOR LIBERO LIBERO
104+
105+
106+
##### Step 6 - Generate the PBKDF2
107+
108+
Using an online tool generate a PBKDF2 key using the parameters associated with the JSON.
109+
110+
For our example:
111+
112+
Password: VIVAMUS LOREM DICTUM AUGUE CURSUS EROS MORBI TORTOR LIBERO LIBERO
113+
Algortithm: SHA256
114+
Salt: VIVAMUS
115+
Iterations: 1000
116+
117+
The solution is the resulting hex value.
118+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Solution for "ASCII" challenge
2+
3+
Use an online ASCII decoder tool to convert the ASCII codes into characters.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Solution for "Base64" challenge
2+
3+
Use an online Base64 decoder tool to convert the base64 encoding into characters.

trainingportal/static/lessons/cryptoBreaker/crypto_caesar.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ Here are a few recommendations:
1414

1515
You may also use your programming/scripting language of choice.
1616

17+
**NOTE: If you decide to view the Solution, open the Solution as a new tab or Window so you don't reset the cipher.**
18+
1719
`Important Note: You're allowed to conduct offline brute force attacks, however trying answer combinations in an automatic fashion using the portal is strictly forbidden.`
1820

1921
We begin with one of the oldest methods used to hide a message, known to be used by Julius Caesar.
2022

2123
#### Algorithm
24+
2225
Shift letters by a number of positions. The number of positions is the key.
2326

2427
##### Example
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
### Solution for "Caesar" challenge
2+
3+
Use an online tool to unscramble the text.
4+
5+
If you need a challenge you could also try shifting the letters like in the example below, until they make sense. The words are from the well known Lorem Ipsum text used in printing and typsetting.
6+
7+
NQTGO
8+
<- MPSFN
9+
<- LOREM

trainingportal/static/lessons/cryptoBreaker/crypto_hash.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Most algorithms leverage the characteristics of the data to arrive at a unique v
2828

2929
##### Weaknesses
3030

31-
Digests can be pre-calculated making them as easy to reverse as an ASCII code. Indeed websites like `crackstation.net` or `hashes.com` contain large databases of pre-calculated digests also known as rainbow tables. The best way to prevent reversing hashed words is to concatenate a random string to the text. This is known as adding a salt. Another mitigation involves hashing the message several times (adding iterations). This increases the amount of computations necessary to calculate the hash.
31+
Digests can be pre-calculated making them as easy to reverse as an ASCII code. Indeed websites like `dCode.fr`, `crackstation.net` or `hashes.com` contain large databases of pre-calculated digests also known as rainbow tables. The best way to prevent reversing hashed words is to concatenate a random string to the text. This is known as adding a salt. Another mitigation involves hashing the message several times (adding iterations). This increases the amount of computations necessary to calculate the hash.
3232

3333
Hashing algorithms are also vulnerable to collision attacks. Such attacks involve altering the input to arrive at the same digest. This is particularly dangerous when using hashing functions to ensure the integrity of executable files. Both MD5 and SHA1 algorithms are vulnerable to collision attacks.
3434

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
### Solution for "One Way Hash" challenge
2+
3+
Use an online rainbow table tool to identify the words corresponding to each hash.
4+
5+
It's a good idea to write down the hashes and then reconstruct the text in order as some of the tools remove hashes or change the order when using bulk look-ups.
6+
7+
a516ff74e222c3bbd3ab924e96fefe0c -> LOREM
8+
e17acb30902a2d91764780ec14400766 -> IPSUM
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### Solution for "Password Based Key" challenge
2+
3+
Use an online tool to generate a PBKDF key with the provided parameters.
4+
5+
Once you have the key, copy the hexadecimal value and use an online tool to decrypt the XOR cipher.

0 commit comments

Comments
 (0)