We will exploit the fact that numpy’s array class is int64
. So, what we’re gonna do is basically generate random passwords, with digits, lowercase and uppercase letters and hope that one of these passwords have both sum and product (overflowed) prime.
For this, we need password with three restrictions:
- It is large enough for the overflow to occur
- All the digits are odd (if we have any even digit, the product will be even, and therefore not prime)
- The length must be odd, so the sum will also be odd, as prime numbers should be odd numbers only
I guess the last criteria is luck. I managed to brute force this quite quickly. Also note that int64
on Linux and Windows are different for numpy
for some reason.
(Dumb) Python script:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
from Crypto.Util.number import isPrime
import numpy as np
import re
from pwn import *
import json
def check(password):
if not re.fullmatch(r"\w*", password, flags=re.ASCII):
return "Password contains invalid characters."
if not re.search(r"\d", password):
return "Password should have at least one digit."
if not re.search(r"[A-Z]", password):
return "Password should have at least one upper case letter."
if not re.search(r"[a-z]", password):
return "Password should have at least one lower case letter."
array = np.array(list(map(ord, password)))
if isPrime(int(array.sum())) and isPrime(int(array.prod())):
return "lmao"
else:
return f"Wrong password, sum was {array.sum()} and product was {array.prod()}"
for i in range(500):
test = "1aA" + 'a' * i
if check(test) == "lmao":
io = remote('socket.cryptohack.org', 13400)
io.recvline()
to_send = dict()
to_send['password'] = test
io.sendline(json.dumps(to_send).encode())
io.interactive()
break
|