from pwn import * import numpy as np from hashlib import md5
yes_strs = [ # 'This is the beginning. You can only go south.', b'Just do it', b'GOGOGO', b'Wuhu', # ida调出来是没有找到这个字符串的,跑脚本的过程中发现有这个输出,就加上了 b'Wuhu~!', b'You are so good', b'Nice.', b'Yeah~~~', b'Let\'s go.', b'Never stop', b'So smart' ]
no_strs = [ b'Oh!!Monster', b'Uh... yeah, no.', b'nononononono', b'Let me out!!!', b'I can\'t see the sky', b'Fxxk!!!', b'Maybe this is a mistack', b'Shit!!', b'Oh no!!!', b'Wall!!!', b'OUCH!!!!' ]
# final_str = b'Good Job. \nAnd the flag is flag md5If not, you may need to go faster!' final_str = b'Good Job.'
SCALE = 500
START = -1 OK = 0 WALKED = 1 WALL = 2 mark = np.zeros( (SCALE, SCALE), dtype = int )
Find the flag routine: routine: SSSSSSSSSDDDDDDWWWWAAWWAAWWDDDDDDDDDDDDDDDDDDDDSSDDSSAASSSSAAAAWWAAWWWWAASSSSSSAASSDDSSSSDDWWWWDDSSDDDDWWDDDDDDWWAAAAWWDDDDWWAAWWWWDDSSDDSSSSSSSSSSDDDDSSAAAASSSSSSAASSSSAAWWAASSSSDDDDDDDDDDSSDDSSAASSSSAASSSSSSSSDDWWWWWWDDWWWWDDWWWWDDSSSSSSSSAASSSSDDDDSSDDDDWWDDSSDDSSDDDDDDDDSSDDSSSSDDDDSSDDSSSSSSDDSSSSDDDDSSSSDDDDDDSSSSDDSSDSSASSSSAASSDDSSAASSDDDDDDSSDDDDWWDDSSSSSSDDDDWWAAWWWWDDDDSSSSDDDDDDSSAASSSSSSDDDDDDDDSSDDDDSSSSSSDDWWDDDDDDSSSSSSSSAASSDDSSSSSSAASSDDS flag: 078c8fbc1d0d033f663dcc58e899c101
from PIL import Image from decimal import * import numpy as np import random getcontext().prec = 20
deff1(x): # It is based on logistic map in chaotic systems # The parameter r takes the largest legal value assert(x>=0) assert(x<=1) ...
deff2(x): # same as f1 ... deff3(x): # same as f1 ...
defencryptImage(path): im = Image.open(path) size = im.size pic = np.array(im) im.close() r1 = Decimal('0.478706063089473894123') r2 = Decimal('0.613494245341234672318') r3 = Decimal('0.946365754637812381837') w,h = size for i inrange(200): r1 = f1(r1) r2 = f2(r2) r3 = f3(r3) const = 10**14 for x inrange(w): for y inrange(h): x1 = int(round(const*r1))%w y1 = int(round(const*r2))%h r1 = f1(r1) r2 = f2(r2) tmp = pic[y,x] pic[y,x] = pic[y1,x1] pic[y1,x1] = tmp p0 = random.randint(100,104) c0 = random.randint(200,204) config = (p0,c0) for x inrange(w): for y inrange(h): k = int(round(const*r3))%256 k = bin(k)[2:].ljust(8,'0') k = int(k[p0%8:]+k[:p0%8],2) r3 = f3(r3) p0 = pic[y,x] c0 = k^((k+p0)%256)^c0 pic[y,x] = c0
return pic,size,config defoutputImage(path,pic,size): im = Image.new('P', size,'white') pixels = im.load() for i inrange(im.size[0]): for j inrange(im.size[1]): pixels[i,j] = (int(pic[j][i]))
残缺的部分有作用相同的f1、f2、f3方法和解密方法,也就是还原了f1方法就能还原整个加密过程。直接google搜"logistic map in chaotic systems",从wikipedia词条得到公式xn+1=r∗xn∗(1−xn),其中xn,xn+1∈[0,1]。为了保证x的取值范围,r的最大值取4(用基本不等式可以推出),修复f1等3个方法如下