首页
社区
课程
招聘
ctf2018-第4题
2018-6-22 15:32 3094

ctf2018-第4题

2018-6-22 15:32
3094
创建子进程, 子进程会结束父进程, 子进程中g_v = 1
.text:004031D7                 call    x_check_if_spawn_child
.data:00495728 g_v             dd 0

sn分成两部分, 记为part1, part2

检测part2
rsa_n: 7da39de66016477b1afc3dc8e309dc429b5de855f0d616d225b570b68b88a585
rsa_e: 3e9
rsa_enc(part2) == 208CBB7CD6ECC64516D07D978F5F0681F534EAD235D5C49ADD72D2DB840D5304

.text:00403237                 push    eax
.text:00403238                 push    offset g_sn_part2
.text:0040323D                 lea     edx, [ebp+var_38+3]
.text:00403240                 push    edx
.text:00403241                 call    x_bin_to_hex
.text:00403246                 add     esp, 0Ch
.text:00403249                 call    x_rsa_check
yafu分解rsa_n: factor(56828191929550499896142468009756520490526164668720784286547535509684830643589)
P39 = 208096057845685678782766058500526476379
P39 = 273086345401562743300402731618892888991
rsa_d: 2E70A649E6A648F78A9D2C1074A7D51F0099C13F7F9BCBB78BAD2C1B1B1D96F1
part2=iamahandsomeguyhaha1

检测part1
char key[16];
memcpy(key+3, "1314000000000");
key[0]=part1[0];
key[1]=part1[1];
key[2]=part1[2]+g_v;
aes_enc(key, "pediy") == 912CA2036A9A0656D17B6B552F157F8E

.text:00403251                 push    3               ; size_t
.text:00403253                 lea     eax, [ebp+var_38]
.text:00403256                 push    eax             ; void *
.text:00403257                 lea     ecx, [ebp+sn_part1]
.text:0040325A                 push    ecx             ; void *
.text:0040325B                 call    _memcpy
.text:00403260                 add     esp, 0Ch
.text:00403263                 lea     edx, [ebp+sn_part1]
.text:00403266                 push    edx
.text:00403267                 call    x_is_all_digit
.text:0040326C                 add     esp, 4
.text:0040326F                 and     eax, 0FFh
.text:00403274                 test    eax, eax
.text:00403276                 jz      short loc_403289
.text:00403278                 lea     eax, [ebp+sn_part1]
.text:0040327B                 push    eax
.text:0040327C                 call    x_aes_check
.text:00403281                 add     esp, 4
穷举得到key[0:3]==521
part1=520

import itertools
from Cryptodome.Cipher import AES


# noinspection SpellCheckingInspection
def egcd(a, b):
    x, y, u, v = 0, 1, 1, 0
    gcd = 0
    while a != 0:
        q, r = b // a, b % a
        m, n = x - u * q, y - v * q
        b, a, x, y, u, v = a, r, u, v, m, n
        gcd = b
    return gcd, x, y


def gen_rsa_param(p, q, e):
    n = p * q
    # phi(n)
    phi = (p - 1) * (q - 1)
    # modular inverse of e
    _, d, _ = egcd(e, phi)
    return n, e, d


def long_to_bin(z):
    s = hex(z)
    s = s.replace('0x', '')
    s = s.replace('L', '')
    if (len(s) % 2) != 0:
        s = '0' + s
    return s.decode('hex')


def get_part1():
    buf_part1 = ''
    for i in itertools.count():
        if i >= 1000:
            break
        key = str(i).zfill(3) + '1314000000000'
        buf_enc = '912CA2036A9A0656D17B6B552F157F8E'.decode('hex')
        cipher = AES.new(key, AES.MODE_ECB)
        buf_plain = cipher.decrypt(buf_enc)
        if buf_plain[0:5] == 'pediy':
            print('aes_key: %s' % key)
            buf_part1 = str(i - 1).zfill(3)
    return buf_part1


def get_part2():
    p = 208096057845685678782766058500526476379
    q = 273086345401562743300402731618892888991
    e = 0x3e9
    n, e, d = gen_rsa_param(p, q, e)
    print('rsa_n: %s' % hex(n))
    print('rsa_e: %s' % hex(e))
    print('rsa_d: %s' % hex(d))
    c = 0x208CBB7CD6ECC64516D07D978F5F0681F534EAD235D5C49ADD72D2DB840D5304
    m = long_to_bin(pow(c, d, n))
    return m


print('sn: %s%s' % (get_part1(), get_part2()))


[培训]二进制漏洞攻防(第3期);满10人开班;模糊测试与工具使用二次开发;网络协议漏洞挖掘;Linux内核漏洞挖掘与利用;AOSP漏洞挖掘与利用;代码审计。

最后于 2018-6-22 16:24 被风间仁编辑 ,原因:
收藏
点赞1
打赏
分享
最新回复 (1)
雪    币: 0
活跃值: (133)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
Puggs 2018-8-5 23:20
2
0
学习学习
游客
登录 | 注册 方可回帖
返回