반응형
삽질은 삽질로써 의미가 있다.
4byte 먼저 돌리고, 2byte씩 돌리는 방식
하지만, 동일한 값이 중간에 나오므로 이상한 문자가 나오면 따로 분리하여 결과물을 확인 해야함.
import hashlibE:\Temp>python codegate_compress_v.0.1.py
import string
def encode(input_string):
h = hashlib.md5(input_string[:4]).hexdigest()
table = {
'a': 1,
'b': 2,
'c': 3,
'd': 4,
'e': 5,
'f': 6,
'g': 7,
'h': 8,
'i': 9,
'j': 0
}
out = ""
prev = ""
stage1 = []
stage2 = []
stage3 = ""
passbyte = -1
for ch in input_string:
if ch in table.keys():
stage1.append(table[ch])
else:
stage1.append(ch)
for index, ch in enumerate(stage1):
if len(stage1) <= index+1:
if index != passbyte:
stage2.append(ch)
break
if passbyte != -1 and passbyte == index:
continue
if type(ch) == int and type(stage1[index+1])==int:
tmp = ch << 4
tmp |= stage1[index+1]
stage2.append(tmp)
passbyte = index+1
else:
stage2.append(ch)
for ch in stage2:
if type(ch) == int:
stage3 += chr(ch)
else:
stage3 += ch
for index, ch in enumerate(stage3):
if index >= len(h):
choice = 0
else:
choice = index
out += chr(ord(ch) ^ ord(h[choice]))
encoded = "~u/"
if out == encoded[0:len(out)]:
print "[%s] match" % input_string
return True
def main():
for index in string.ascii_letters:
for index1 in string.ascii_letters:
for index2 in string.ascii_letters:
for index3 in string.ascii_letters:
encode(index+index1+index2+index3)if __name__ == "__main__" :
main()
[dhdj] match
[diad] match
[FLag] match
[MAaf] match
import hashlib
import string
def encode(input_string):
h = hashlib.md5(input_string[:4]).hexdigest()
table = {
'a': 1,
'b': 2,
'c': 3,
'd': 4,
'e': 5,
'f': 6,
'g': 7,
'h': 8,
'i': 9,
'j': 0
}
out = ""
prev = ""
stage1 = []
stage2 = []
stage3 = ""
passbyte = -1
for ch in input_string:
if ch in table.keys():
stage1.append(table[ch])
else:
stage1.append(ch)
for index, ch in enumerate(stage1):
if len(stage1) <= index+1:
if index != passbyte:
stage2.append(ch)
break
if passbyte != -1 and passbyte == index:
continue
if type(ch) == int and type(stage1[index+1])==int:
tmp = ch << 4
tmp |= stage1[index+1]
stage2.append(tmp)
passbyte = index+1
else:
stage2.append(ch)
for ch in stage2:
if type(ch) == int:
stage3 += chr(ch)
else:
stage3 += ch
for index, ch in enumerate(stage3):
if index >= len(h):
choice = 0
else:
choice = index
out += chr(ord(ch) ^ ord(h[choice]))
encoded = "~u/\x15mK\x11N`[^\x13E2JKj0K;3^D3\x18\x15g\xbc\\Gb\x14T\x19E"
if out == encoded[0:len(out)]:
print "[%s] match" % input_string
return True
def main():
#org = "FLag is {compress_is_always_helpful!}"
input_str = "FLag"
encoded = "~u/\x15mK\x11N`[^\x13E2JKj0K;3^D3\x18\x15g\xbc\\Gb\x14T\x19E"
count = 4
print "string : %s" % input_str
while count < len(encoded):
for index in string.printable:
if encode(input_str+index) == True:
input_str += index
break
count += 1
if __name__ == "__main__" :
main()
E:\Temp>python codegate_compress_v.0.1.py
string : FLag
[FLag ] match
[FLag i] match
[FLag is] match
[FLag is ] match
[FLag is {] match
[FLag is {c] match
[FLag is {co] match
[FLag is {com] match
[FLag is {comp] match
[FLag is {compr] match
[FLag is {compre] match
[FLag is {compres] match
[FLag is {compress] match
[FLag is {compress_] match
[FLag is {compress_i] match
[FLag is {compress_is] match
[FLag is {compress_is_] match
[FLag is {compress_is_a] match
[FLag is {compress_is_al] match
[FLag is {compress_is_alw] match
[FLag is {compress_is_alwa] match
[FLag is {compress_is_alway] match
import hashlibE:\Temp>python _codegate_compress.py
import string
def encode(input_string):
h = hashlib.md5(input_string[:4]).hexdigest()
#str = "GDKggZ*!wX8"
#h = hashlib.md5(str[:4]).hexdigest()
table = {
'a': 1,
'b': 2,
'c': 3,
'd': 4,
'e': 5,
'f': 6,
'g': 7,
'h': 8,
'i': 9,
'j': 0
}
out = ""
prev = ""
stage1 = []
stage2 = []
stage3 = ""
passbyte = -1
for ch in input_string:
if ch in table.keys():
stage1.append(table[ch])
else:
stage1.append(ch)
for index, ch in enumerate(stage1):
if len(stage1) <= index+1:
if index != passbyte:
stage2.append(ch)
break
if passbyte != -1 and passbyte == index:
continue
if type(ch) == int and type(stage1[index+1])==int:
tmp = ch << 4
tmp |= stage1[index+1]
stage2.append(tmp)
passbyte = index+1
else:
stage2.append(ch)
for ch in stage2:
if type(ch) == int:
stage3 += chr(ch)
else:
stage3 += ch
for index, ch in enumerate(stage3):
if index >= len(h):
choice = 0
else:
choice = index
out += chr(ord(ch) ^ ord(h[choice]))
#if out == "~u/\x15mK\x11N`[^\x13E2JKj0K;3^D3\x18\x15g\xbc":
if out == "~u/\x15mK\x11N`[^\x13E2JKj0K;3^D3\x18\x15g\xbc\\Gb\x14T\x19E"[0:len(out)]:
print "[%s] match" % input_string
print "encode count : %d" % len(out)
return True
encoded = "~u/\x15mK\x11N`[^\x13E2JKj0K;3^D3\x18\x15g\xbc\\Gb\x14T\x19E"
input_str = "FLag is {compress_is_always_"
loop = len(input_str)
while loop < len(encoded):
for index in string.printable:
for index1 in string.printable:
if encode(input_str+index+index1) == True:
input_str += index+index1
loop += 2
print "decode string length : %d" % loop
print "encode string length : %d" % len(encoded)
[FLag is {compress_is_always_he] match
encode count : 28
[FLag is {compress_is_always_help] match
encode count : 30
[FLag is {compress_is_always_helpfu] match
encode count : 32
[FLag is {compress_is_always_helpful!] match
encode count : 34
반응형
'프로그래밍 > Python' 카테고리의 다른 글
pip update 할 경우 "invalid syntax" 에러 발생 시 조치 사항 (0) | 2023.02.10 |
---|---|
File Fuzzer v.0.1 (2) | 2013.08.11 |
danger_track를 이용한 crash dump 활용 (0) | 2013.07.30 |
win7 에서 pydbg 이용한 snap 찍기 (0) | 2013.07.29 |
Windows 7에서 pydbg 설치 하기 (0) | 2013.07.26 |