File tree Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Original file line number Diff line number Diff line change
1
+ from pwn import remote , context
2
+ import random
3
+ import string
4
+ import time
5
+
6
+ def substitute (s1 , sbox , key ):
7
+ sbox = sbox
8
+ key = key
9
+ s = []
10
+
11
+ for value in s1 :
12
+ r = key
13
+ while value :
14
+ r = sbox [r ]
15
+ value -= 1
16
+ s .append (r )
17
+
18
+ return bytes (s ).hex ()
19
+
20
+
21
+ host , port = "0.cloud.chals.io" , 31202
22
+ context .log_level = "debug"
23
+
24
+ io = remote (host , port )
25
+
26
+ io .recvuntil (b">" )
27
+ io .sendline (b"1" )
28
+ seed = int (time .time ())
29
+ io .recvuntil (b"flag: " )
30
+ enc = io .recvline ().strip ().decode ()
31
+ chunks = []
32
+
33
+ for i in range (0 , len (enc ), 2 ):
34
+ chunks .append (enc [i :i + 2 ])
35
+
36
+ for trial in range (seed - 0x100 , seed + 0x100 ):
37
+ random .seed (trial )
38
+ sbox = list (range (256 ))
39
+ random .shuffle (sbox )
40
+
41
+ charset = string .printable
42
+ mapping = {}
43
+
44
+ for key in range (0xff ):
45
+ for value in charset :
46
+ r = substitute (value .encode (), sbox , key )
47
+ mapping [r ] = value
48
+
49
+ flag = ""
50
+ try :
51
+ for chunk in chunks :
52
+ flag += mapping [chunk ]
53
+ except KeyError :
54
+ pass
55
+
56
+ if "csean-ctf" in flag :
57
+ print (flag )
58
+ break
59
+
60
+
61
+ io .interactive ()
You can’t perform that action at this time.
0 commit comments