Skip to content

Commit 04fba91

Browse files
committed
Added more writeups, and made small adjustments to previous writeups I submitted
1 parent 1a3c2f3 commit 04fba91

13 files changed

+1428
-13
lines changed
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Hash On Hash - 100 points
2+
3+
There's a lot of hex strings here. Maybe they're hiding a message? [hexstrings](../files/HashOnHash.txt)
4+
5+
### Solution
6+
###### Writeup by Valar Dragon
7+
8+
9+
The file hexstrings is a file with many lines of 32 chars of hex.
10+
I ignored the hint, and put the first few into the online hash cracker [CrackStation](https://crackstation.net/)
11+
12+
From that you could see that they were all MD5 hashes of 1 letter!
13+
Then it was easy,
14+
I just wrote a script to make all the 256 1 character MD5's.
15+
Then iterate line by line and replace the lines with character that md5's to it. Concatenate the characters, and print the corresponding characters.
16+
17+
```
18+
$ python3 hexstringsSolver.py
19+
Im far too lazy to put anything meaningful here. Instead, here's some information about what you just solved.
20+
The MD5 algorithm is a widely used hash function producing a 128-bit hash value. Although MD5 was initially designed to be used as a cryptographic hash function, it has been found to suffer from extensive vulnerabilities. It can still be used as a checksum to verify data integrity, but only against unintentional corruption.
21+
Like most hash functions, MD5 is neither encryption nor encoding. It can be cracked by brute-force attack and suffers from extensive vulnerabilities as detailed in the security section below.
22+
MD5 was designed by Ronald Rivest in 1991 to replace an earlier hash function MD4.[3] The source code in RFC 1321 contains a "by attribution" RSA license. The abbreviation "MD" stands for "Message Digest."
23+
The security of the MD5 has been severely compromised, with its weaknesses having been exploited in the field, most infamously by the Flame malware in 2012. The CMU Software Engineering Institute considers MD5 essentially "cryptographically broken and unsuitable for further use".[4]
24+
easyctf{1_h0p3_y0u_d1dn7_d0_7h47_by_h4nd}
25+
```
26+
27+
We learn a few facts about MD5 and get our flag!
28+
29+
### External Writeups
30+
31+
* [https://github.com/HackThisCode/CTF-Writeups/tree/master/2017/EasyCTF/Hash%20On%20Hash/README.md](https://github.com/HackThisCode/CTF-Writeups/tree/master/2017/EasyCTF/Hash%20On%20Hash/README.md)
+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Premium RSA - 350 points
2+
3+
My RSA is the greatest. It's so strong, in fact, that I'll even give you [d](../files/premiumRSA.txt)!
4+
5+
### Solution
6+
###### Writeup by Valar Dragon
7+
8+
9+
10+
This was a terrific challenge about RSA Partial Key Recovery! (Something I didn't even know existed before) Thankfully we were given over half of the private key. If we were given a quarter of the key, we would have to implement the Coppersmith attack, in addition to whats below.
11+
12+
**Due to a lack of Latex, if notation is non-standard mathematics notation, it is Python notation**
13+
14+
We are given N, The last 2048 bits of d, e, and c, and asked to get the message!
15+
16+
Lets call the least significant 2048 bits of d we have `d0`
17+
18+
Solving this involved a lot of derivation and reading up on RSA Attacks, namely the following two documents:
19+
* http://www.ijser.org/researchpaper/Attack_on_RSA_Cryptosystem.pdf
20+
* http://honors.cs.umd.edu/reports/lowexprsa.pdf
21+
22+
The idea is that `ed - k(N-p-q+1) = 1` by definition of modulo. `[1]`
23+
24+
Note that `N-p-q+1 = φ(N)`
25+
26+
d must be less than φ(N), since `d = modInv(e,φ(N))`
27+
28+
Therefore `k < e` since `ed > kφ(N)`
29+
30+
Thus k is in `range(1,e)`!
31+
32+
But we don't have φ(N), we have N, so we will switch φ(N) with N in the `[1]`
33+
34+
Lets call this `d'` since its just an approximation.
35+
`ed' - kN = 1`
36+
37+
Rearrange, and solve for `d'` as:
38+
39+
`d' = (kN + 1) // e`
40+
41+
The maximum error in d' is: `3 sqrt(nBitSize)` bits, where nBitSize is how many bits long the modulus is. See the links for a proof of this maximum error.
42+
43+
That error is less than `dBitSize/2`, so we can just replace the least significant bits with `d0`
44+
and get the plaintext!
45+
46+
But we need a way of testing k. One way to do it would be to try encrypting a known message with e and n, and decrypting it with the d were getting from that particular k.
47+
The only issue is that modpows are slow, especially as the exponent d is growing, as is the case with increasing k.
48+
49+
We actually have a way to speed this up greatly!
50+
Using `[1]` again,
51+
```
52+
ed - k(N-p-q+1) = 1
53+
ed ≡ 1 mod k
54+
ed -1 ≡ 0 mod k
55+
```
56+
Nearly all k will fail that criterion, making it perfect!
57+
I'm then going to decrypt test messages, just to be absolutely sure.
58+
Now we have e,d, and N! Just for completion, lets find p and q.
59+
Rearranging `[1]`
60+
`φ(N) = (ed - 1)//k`
61+
```
62+
φ(N) = (p-1)(q-1) = n - p - q + 1
63+
p^2 - p^2 - N + N = 0
64+
p^2 - p^2 - pq + N = 0
65+
p^2 + (-p -q)p + N = 0
66+
p^2 + (φ(N) -n -1) + N = 0
67+
```
68+
Solving this quadratic for variable p:
69+
``` python
70+
b = totientN - n - 1
71+
discriminant = b*b - 4*n
72+
#make sure discriminant is perfect square
73+
root = self.floorSqrt(discriminant)
74+
assert root*root == discriminant
75+
p = (-b + root) // 2
76+
q = n // p
77+
```
78+
Now raise the message to d, and we get our flag!
79+
80+
My code is in [premiumRSA.py](https://github.com/HackThisCode/CTF-Writeups/blob/master/2017/EasyCTF/Premium%20RSA/premiumRSA.py), the method halfdPartialKeyRecoveryAttack
81+
comes from my RSA Solver, https://github.com/ValarDragon/CTF-Crypto/blob/master/RSA/RSATool.py
82+
83+
``` bash
84+
$ python3 premiumRSA.py
85+
easyctf{wow_i_pR0bABLY_5h0uldntA_l33k3d_d}
86+
```
87+
_All the flags have randomized 1337 speak, so your flag may vary_
88+
### External Writeups
89+
90+
* [https://github.com/HackThisCode/CTF-Writeups/blob/master/2017/EasyCTF/Premium%20RSA/README.md](https://github.com/HackThisCode/CTF-Writeups/blob/master/2017/EasyCTF/Premium%20RSA/README.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Security Through Obscurity - 150 points
2+
3+
I've never seen such a cryptosystem]before! It looks like a public key cryptosystem, though... Could you help me crack it?
4+
5+
[encrypt.sage](../files/sage.py)
6+
[publickey_and_ciphertext.txt](../files/key.txt)
7+
8+
### Solution
9+
###### Writeup by Valar Dragon
10+
11+
12+
I think this problem achieves the true definition of failed Security Through Obscurity! These files, except for my [solver](https://github.com/HackThisCode/CTF-Writeups/blob/master/2017/EasyCTF/Security%20Through%20Obscurity/sageSolver.py), are all sage files.
13+
Sage is an open source python-based alternative to Mathematica and Matlab.
14+
15+
Lets analyze the code in sage.py
16+
17+
``` python
18+
def calc_root(num, mod, n):
19+
f = GF(mod)
20+
temp = f(num)
21+
return temp.nth_root(n)
22+
```
23+
Looking through the Sage documentation, we can see that
24+
f becomes a finite field of order mod. Mod is actually a prime, being passed from `gen_v_list(primelist, p, secret)`.
25+
26+
temp.nth_root(n) is finding the nth root of temp in this finite field. This means that
27+
``` python
28+
pow(temp.nth_root(n),n) ≡ temp mod num
29+
```
30+
31+
This means that we can quite easily brute force for SECRET, see [sageSecret](https://github.com/HackThisCode/CTF-Writeups/blob/master/2017/EasyCTF/Security%20Through%20Obscurity/sageSecret.py) file.
32+
We don't actually need to solve for SECRET however.
33+
34+
So now this tells us what
35+
``` python
36+
def gen_v_list(primelist, p, secret):
37+
a = []
38+
for prime in primelist:
39+
a.append(calc_root(prime, p, secret))
40+
return a
41+
```
42+
means. gen_v_list is the nth root of each prime in the finite field of size p.
43+
44+
``` python
45+
primelist = [2,3,5,7,11,13,17,19,23,29,31,37,43,47,53,59]
46+
message = REDACTED
47+
chunks = []
48+
for i in range(0,len(message),2):
49+
chunks += [message[i:i+2]]
50+
```
51+
This splits the message into 2 byte chunks
52+
53+
``` python
54+
for chunk in chunks:
55+
binarized = bin(int(chunk.encode('hex'),16)).replace('0b','').zfill(16)[::-1] #lsb first
56+
enc = 1
57+
for bit in range(len(binarized)):
58+
enc *= vlist[bit]**int(binarized[bit])
59+
enc = enc%p
60+
print(enc)
61+
```
62+
This converts every chunk to hex, removes any `0b` in the hex, converts it to binary, pads the left with 0's until its 16 bits longs, and then reverses the string. The for loop is multiplying enc by that
63+
index in vlist if binarized[i] is 1. If its 0, then do nothing to enc. Finally take enc modulo p.
64+
65+
Wait!!! Only 16 bits in a chunk?? That means theres only `2**16 = 65536` options, well within the brute force range!
66+
We can just do a reverse lookup on everything in the ciphertext!
67+
68+
69+
Brute forcing all 16 bits of options, and doing reverse lookups on Ciphertext, gives us the flag:
70+
``` bash
71+
$ python3 sageSolver.py
72+
flag{i_actu4lly_d0nt_know_th3_name_of_th15_crypt0sy5tem}
73+
```
74+
75+
In discussion with Neptunia, the challenge creator, I found out this was actually an unintended solution,
76+
and this solution reduced the point value from 500 points (iirc),
77+
to this current 150.
78+
79+
The intended solution involved learning what cryptosystem this is through google, and from there figuring out its decrypt function.
80+
81+
A link for the cryptosystem given post-CTF on this cryptosystem is:
82+
https://www.di.ens.fr/~stern/data/St63.pdf
83+
### External Writeups
84+
85+
* [https://github.com/HackThisCode/CTF-Writeups/blob/master/2017/EasyCTF/Security%20Through%20Obscurity/README.md](https://github.com/HackThisCode/CTF-Writeups/blob/master/2017/EasyCTF/Security%20Through%20Obscurity/README.md)

cryptography/genius-230-points.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Your boss told you that this team has come up with the cryptographic hash of the future, but something about their operation just seems a little fishy.
44

55
### Solution
6-
6+
###### Writeup by Valar Dragon
77
Here's the site:
88
![Screenshot 1](https://raw.githubusercontent.com/ValarDragon/CTF-Writeups/master/2017/EasyCTF/Genius/Site-1.png)
99
![Screenshot 2](https://raw.githubusercontent.com/ValarDragon/CTF-Writeups/master/2017/EasyCTF/Genius/Site-2.png)
@@ -18,9 +18,10 @@ This shows us that there are 4 byte words in these hashes!
1818
Lets take the MD5 hash of `like`, and see how it compares to these strings.
1919

2020
`md5(like) = be1ab1632e4285edc3733b142935c60b`
21-
That hash is be1ab1632e4285edc3733b142935c60b90383bad42309f7f6850d2b4250a713d0b2d7a97350465a02554d29d92bfefaf
21+
The hash it was found in is
22+
`be1ab1632e4285edc3733b142935c60b90383bad42309f7f6850d2b4250a713d0b2d7a97350465a02554d29d92bfefaf`
2223

23-
So, these md5's are looking like they are concatenations of 3 md5's of 4 byte strings!
24+
So the md5 of `like` is the first 32 chars of the line it was in! Each line of the hash is looking like it is the concatenation of 3 md5's of 4 byte strings!
2425

2526
So I split the given hash into 32 char chunks, and than began brute forcing 4 byte strings with lowercase and UPPERCASE letters, `{_}`, and numbers.
2627
This gives us:
@@ -53,4 +54,4 @@ Putting that into the website's prompt gives a popup with the flag:
5354

5455
### External Writeups
5556

56-
* [https://github.com/ValarDragon/CTF-Writeups/blob/master/2017/EasyCTF/Genius/README.md](https://github.com/ValarDragon/CTF-Writeups/blob/master/2017/EasyCTF/Genius/README.md)
57+
* [https://github.com/HackThisCode/CTF-Writeups/blob/master/2017/EasyCTF/Genius/README.md](https://github.com/HackThisCode/CTF-Writeups/blob/master/2017/EasyCTF/Genius/README.md)

cryptography/paillier-service-400-points.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ My friend made some sort of encryption service using the Paillier cryptosystem.
55
Access his encryption service at `paillier.tcp.easyctf.com 8570`
66

77
### Solution
8-
8+
###### Writeup by Valar Dragon
99
This was a really easy/straightforward Paillier Cryptosystem Problem! It was a great way to learn about the Paillier Cryptosystem!
1010

1111
We are not actually 'cracking' the Paillier Cryptosystem for this challenge, we are gaining the ability to encrypt our own messages already given the ability to choose the message and random number.
@@ -69,4 +69,4 @@ as our flag!
6969

7070
### External Writeups
7171

72-
* [https://github.com/ValarDragon/CTF-Writeups/blob/master/2017/EasyCTF/Paillier%20Service/README.md](https://github.com/ValarDragon/CTF-Writeups/blob/master/2017/EasyCTF/Paillier%20Service/README.md)
72+
* [https://github.com/HackThisCode/CTF-Writeups/tree/master/2017/EasyCTF/Paillier%20Service/README.md](https://github.com/HackThisCode/CTF-Writeups/tree/master/2017/EasyCTF/Paillier%20Service/README.md)

cryptography/rsa-4-200-points.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
After doing so much RSA, I finally messed up.... pls help. I encrypted my secret [message](../files/rsa4.txt) but the decryption isn't working!!
44

55
### Solution
6+
###### Writeup by Valar Dragon
67

78
\*Unfortunately due to a flag leak this challenge was taken down.
89

@@ -75,4 +76,4 @@ bytearray(b'easyctf{m0dul4r_fuN!}')
7576

7677
### External Writeups
7778

78-
* [https://github.com/ValarDragon/CTF-Writeups/tree/master/2017/EasyCTF/RSA%204/README.md](https://github.com/ValarDragon/CTF-Writeups/tree/master/2017/EasyCTF/RSA%204/README.md)
79+
* [https://github.com/HackThisCode/CTF-Writeups/blob/master/2017/EasyCTF/RSA%204/README.md](https://github.com/HackThisCode/CTF-Writeups/blob/master/2017/EasyCTF/RSA%204/README.md)

0 commit comments

Comments
 (0)