# coding:utf-8
# author: sherllyyang00@gmail.com
# encrypt文件为bin中0x40087f-0x400a78的数据
def decrypt(start,filename,key):
with open("encrypt","rb") as f:
data = f.read()[start:]
res=[]
for i in range(32,127):
res=[]
found = 0
for d in data:
byte = ord(d)^i^key
res.append(chr(byte))
if byte == 0x90 and res[-2] == '\xfb':
print "[*] key: ",chr(i)
found = 1
if found == 1:
# print len(res)
# print res
if i == ord('a'):
pos1 = "".join(res).find("\xfb\x90")
print pos1
pos2 = res[pos1+2:].index('\x90')
print pos2
pos = pos1+2+pos2+1
res = res[:pos1+2+pos2+1]
with open(filename,"wb") as f:
f.write("".join(res))
return pos
def decrypt_end(start,filename,key):
with open("encrypt","rb") as f:
data = f.read()[start:]
res=[]
for i in range(32,127):
res=[]
found = 0
for d in data:
byte = ord(d)^i^key
res.append(chr(byte))
if byte == 0x90:
print "[*] key: ",chr(i)
found = 1
print len(res)
break
if found == 1:
# print len(res)
# print res
if i == ord('K'):
pos = "".join(res).find("\x90")
print pos
res = res[:pos+1]
with open(filename,"wb") as f:
f.write("".join(res))
return pos
return 0
pos = decrypt(start=0,filename="decrypt_1",key=0) # 'e'
pos = decrypt(start=74,filename="decrypt_2",key=ord('e')) # 'v'
pos = decrypt(start=74+71,filename="decrypt_3",key=ord('e')^ord('v')) # 'X' /'6' 'W' 'X'
pos = decrypt(start=74+71+71,filename="decrypt_4",key=ord('e')^ord('v')^ord('X')) # 'n'
pos = decrypt(start=74+71+71+71,filename="decrypt_5",key=ord('e')^ord('v')^ord('X')^ord('n')) # 'a'
pos = decrypt_end(start=74+71+71+71+62,filename="decrypt_6",key=ord('e')^ord('v')^ord('X')^ord('n')^ord('a')) # 'K'
# evXnaK
得到正确的key值为evXnaK,输入验证下:
# coding:utf-8
# author: sherllyyang00@gmail.com
# encrypt文件为bin中0x40087f-0x400a78的数据
def decrypt(start,filename,key):
with open("encrypt","rb") as f:
data = f.read()[start:]
res=[]
for i in range(32,127):
res=[]
found = 0
for d in data:
byte = ord(d)^i^key
res.append(chr(byte))
if byte == 0x90 and res[-2] == '\xfb':
print "[*] key: ",chr(i)
found = 1
if found == 1:
# print len(res)
# print res
if i == ord('a'):
pos1 = "".join(res).find("\xfb\x90")
print pos1
pos2 = res[pos1+2:].index('\x90')
print pos2
pos = pos1+2+pos2+1
res = res[:pos1+2+pos2+1]
with open(filename,"wb") as f:
f.write("".join(res))
return pos
def decrypt_end(start,filename,key):
with open("encrypt","rb") as f:
data = f.read()[start:]
res=[]
for i in range(32,127):
res=[]
found = 0
for d in data:
byte = ord(d)^i^key
res.append(chr(byte))
if byte == 0x90:
print "[*] key: ",chr(i)
found = 1
print len(res)
break
if found == 1:
# print len(res)
# print res
if i == ord('K'):
pos = "".join(res).find("\x90")
print pos
res = res[:pos+1]
with open(filename,"wb") as f:
f.write("".join(res))
return pos
return 0
pos = decrypt(start=0,filename="decrypt_1",key=0) # 'e'
pos = decrypt(start=74,filename="decrypt_2",key=ord('e')) # 'v'
pos = decrypt(start=74+71,filename="decrypt_3",key=ord('e')^ord('v')) # 'X' /'6' 'W' 'X'
pos = decrypt(start=74+71+71,filename="decrypt_4",key=ord('e')^ord('v')^ord('X')) # 'n'
pos = decrypt(start=74+71+71+71,filename="decrypt_5",key=ord('e')^ord('v')^ord('X')^ord('n')) # 'a'
pos = decrypt_end(start=74+71+71+71+62,filename="decrypt_6",key=ord('e')^ord('v')^ord('X')^ord('n')^ord('a')) # 'K'
# evXnaK