-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathencoding.py
More file actions
58 lines (41 loc) · 1.43 KB
/
encoding.py
File metadata and controls
58 lines (41 loc) · 1.43 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from binascii import unhexlify
from pwn import *
import base64
import codecs
from Crypto.Util.number import bytes_to_long, long_to_bytes
import json
import sys
import Crypto
r = remote('socket.cryptohack.org', 13377, level = 'debug')
class Decoder(object):
def __init__(self,data):
self.type = ''
self.data = ''
loaded_json = json.loads(data)
self.type = loaded_json['type']
self.data = loaded_json['encoded']
print("recieved this %s,%s",self.data,self.type)
def calling(self):
if self.type == "base64":
return base64.b64decode(self.data).decode('ISO-8859-1')
elif self.type == "hex":
return bytes.fromhex(self.data).decode('ISO-8859-1')
elif self.type == "rot13":
return codecs.decode(self.data, 'rot_13')
elif self.type == "bigint":
len_decode = len(self.data)
x = int(self.data, 16).to_bytes(len_decode, 'big')
return str(x, 'UTF-8').lstrip('\x00')
elif self.type == "utf-8":
return ''.join(chr(o) for o in self.data)
for i in range(100):
retrieve = r.recv_raw(1024)
decoder = Decoder(retrieve)
decode = decoder.calling()
print("decoded ==== %s %s",i,decode)
decode = {
"decoded": decode
}
response = json.dumps(decode)
r.send(response)
print('\n\nthe flag is:'+r.recv(1024).decode('ISO-8859-1'))