标签 Python逆向 下的文章

python一道很简单的逆向题

uncompyle2恢复源码

#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Archerx
# @time: 2018/10/20 上午 09:58

def encrypt(key, seed, string):
    rst = []
    for v in string:
        rst.append((ord(v) + seed ^ ord(key[seed])) % 255)
        seed = (seed + 1) % len(key)

    return rst


if __name__ == '__main__':

    flag = ''
    KEY1 = 'SDUT Network and information security laboratory'
    KEY2 = [54, 14, 30, 3, 5, 30, 43, 28, 37, 231, 28, 79, 52, 44, 15, 40, 6, 17, 2, 56, 233, 22, 35, 170, 18, 24, 12,
            236, 42, 227, 39, 235, 164, 4, 193, 229, 5, 238, 239, 224, 253, 210, 222, 46]
    en_out = encrypt(KEY1, 5, flag)
    if KEY2 == en_out:
        print 'FLAG IS flag{%s}' % flag
    else:
        print 'No'
  • 关于代码中出现余除并且代码并不复杂情况先优先考虑爆破

下面给出了三种解决方法:

#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Archerx
# @time: 2018/10/19 下午 09:53

def encrypt(key, seed, string):
    rst = []
    for v in string:
        rst.append((ord(v) + seed ^ ord(key[seed])) % 255)
        seed = (seed + 1) % len(key)
    return rst

def decrypt(key1,seed,key2):
    str = ''
    for i in key2:
        v = (i^ord(key1[seed]))-seed
        seed = (seed+1)%len(key1)
        str += chr(v)
    return str


def force_de(KEY1,seed,KEY2):
    flag = ''
    for i in KEY2:
        for j in range(130):
            if i == (j + seed ^ ord(KEY1[seed])) % 255:
                flag+=chr(j)
                seed = (seed + 1) % len(KEY1)
                break
    print(flag)

def force_de2(KEY1,seed,KEY2):
    flag = ''
    for j in range(23):
        for i in range(130):
            if KEY2[j] == (i + seed ^ ord(KEY1[seed])) % 255:
                flag += chr(i)
                seed = (seed + 1) % len(KEY1)
                break
    print(flag)

if __name__ == '__main__':
    KEY1 = 'SDUT Network and information security laboratory'
    flag = '************************************'
    # print(decrypt(KEY1,5,KEY2))
    # force_de(KEY1,5,KEY2)
    # force_de2(KEY1,5,KEY2)
    KEY2 = [54, 14, 30, 3, 5, 30, 43, 28, 37, 231, 28, 79, 52, 44, 15, 40, 6, 17, 2, 56, 233, 22, 35, 170, 18, 24, 12, 236, 42, 227, 39, 235, 164, 4, 193, 229, 5, 238, 239, 224, 253, 210, 222, 46]
    print(encrypt(KEY1,5,flag))
    print(decrypt(KEY1,5,KEY2))
  • 改编自豫商杯一道题
preView