2020XCTF-华为系列专场 部分Writeup

2020年最后的一次比赛,共三场,一直想复盘一下再写WP的,最终还是咕了。。。
鲲鹏计算专场独自解了两道逆向+一道半Crypto+两道RealWorld,也是校队第一次进XCTF分站赛前十
鸿蒙专场AK了5道逆向+1道RealWorld,可惜当天起得晚了点加上中午有点事,基本都是四血,不过此次队友十分给力,短暂登过顶,最终也苟进了第五,算是2020年最好的成绩了!

鲲鹏计算专场 - Crypto

combinelfsr

lfsr,参考https://www.anquanke.com/post/id/184828

z3 求 R1,R2

R2= 90307

R1 = 13706

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from z3 import *

class lfsr():
def __init__(self, init, mask, length):
self.init = init
self.mask = mask
self.lengthmask = 2**(length+1)-1
self.length = length

def next(self):
        nextdata = (self.init << 1) & self.lengthmask
        i = self.init & self.mask & self.lengthmask
        output = 0
for j in range(self.length):
            output ^= (i & 1)
            i = i >> 1
        nextdata ^= output
self.init = nextdata
return output

def combine(x1,x2):
return (x1*x2)^(x2^1)

init1 = BitVec('init1', 18)
init2 = BitVec('init2', 18)

l1 = lfsr(init1, 0b110000010100010111, 18)
l2 = lfsr(init2, 0b100101101101110100, 18)

s = Solver()
with codecs.open('out', 'rb') as f:
    keystream = f.read()

outputs = []
for i in keystream:
    a = ord(i)
    b = '0'*(8 - len(bin(a)[2:])) + bin(a)[2:]
for j in b:
        outputs.append(int(j))

for i in range(80):
    s.add(outputs[i] == combine(l1.next(), l2.next()))

s.check()
print(s.model())
1
2
3
4
5
6
7
8
9
10
11
12
# from z3
R2= 90307
R1 = 13706

from hashlib import sha512
import random
from Crypto.Cipher import AES
key = sha512(str(R1)+str(R2)).digest()[:16]
aes = AES.new(key,AES.MODE_ECB)
flag= '\xb5\xbc\x56\xc1\x7d\xb4\xa7\xd8\x98\xce\x63\x65\x2d\x36\x56\x57\x2e\x4f\x5b\x67\x57\xfc\xce\xf8\xd8\xd3\xa3\x2d\xc6\x0b\xfc\x97\x2d\x40\xf0\x61\xf3\xa7\x15\x4f\x79\x75\xd5\x12\x6b\x05\x2d\xad'
flag = aes.decrypt(flag)
print(flag)

flag{d0b570e1-5292-4381-9d71-d6edab490854}

RRSSAA

简单的rsa,总共有三部分,part1直接解,part2利用韦达定理解

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from Crypto.Util.number import *
from gmpy2 import next_prime,invert,gcd,iroot
from sympy import nextprime
import os 
#level1
# x = getPrime(290)
# y = next_prime(21*x)
# z = next_prime(3*x*y)
# n1 = x*y*z
# n1 = x*21*x*3*x*21*x == 1323*x^4
e = 0x10001
def level1(c):
    n = 7296833146437859657873621309783663953888975990236533231501856312811032923469834028894995888763882827280881148914714991084488173289859941577252999932599209531912854472326211936264815965582591809770319779712527572174152560819828597241583278731544411246154674514626001858732363262751244419415544407653873858309154132440262888841600498885105451586030156787
    x4 = n/1323
    tmp = iroot(x4,4)[0] - 1000

while True:
        x = nextprime(tmp)
        y = nextprime(21*x)
        z = nextprime(3*x*y)
if x*y*z  == n:
            phi = (x-1)*(y-1)*(z-1)
            d = invert(e,phi)
            m = pow(c,d,n)
return m
else:
            tmp = nextprime(tmp)

# level2 
def level2(c):
    c2 = 1053537887874546462592488085073845416926774134662726673037396087573784978051621217625148167597158934482623108020431156088398328744249523064321014736213368948953544152743794110597131811143693267135550808438361187122132326433146425956042304765054715382524604818750722275967881325495437747007634396550743199481837826028546371516957749823388589606139743433172347723
    oxs = 2966384769329081457959929210854946307725303451729041111756565081822209869706734847077404063837454548238096227843381458842322035116059935545789370388767999132347222281376931478665079
    n2 = 8799438599707547810413590252769637047669730373282934937368515093438977181200080057948977998859737775815535703211966248578669447308370171323881776611030752648135480196879162497896464322936833458775227550623435000527614781055524145936353357662536280470664112516976033358499330391929435857811788923590666783090016628619936968367309955759172412259970189158362661969

'''
    o = getPrime(300)
    s = getPrime(300)
    t = next_prime(o)
    u = next_prime(s)

    a = o*s + t*u
    b = t*s + u*o
    print(a-b)
    '''

    txu = n2//oxs
print(oxs*txu == n2)
    a = oxs+txu
for i in range(1, 100000):
        b = a-i
        delta = b**2 - 4*n2
if delta<0:
continue
        rdelta = iroot(delta,2)
if rdelta[1]:
print(i, b)
# from sage
    r1 = 2966384769329081457959929210854946307725303451729041111756565081822209869706734847077404651306368582818672174524720657329423156396400608586670887330204238883628829887762408566296707
    r2 = 2966384769329081457959929210854946307725303451729041111756565081822209869706734847077404379002848561827294305095639384473736092631731049929066639898110490671436971914521438376531867

    o = gcd(r1, oxs)
    s = gcd(r2, oxs)
    t = next_prime(o)
    u = next_prime(s)
print(o*s*t*u == n2)

    phi = (o-1)*(s-1)*(t-1)*(u-1)
    d = invert(e, phi)
    m = pow(c2, d, n2)
print(m)
return m


def level3():
    n3 = 24502730939655407292543436897382196297516664227273320602397906878696723372242877776550446563950867624819352853122033114711732125433588724779869985477495098802744344448915032607469954642257825855931872281908232331623829725043031800535739432133948607448362641204034546581444904408754892037110031202573463399201625812005615264689877537231974023870006792196961829162058446662172634212427186470724599941352830546043772969297733239518604749366684163813795999625784931375110137805143337329
    mr = 81225738828166640599054154023183465870678960906769673605358084529196871174429427936591822589995476552044227730868809310992934103731850597399114246762836121101348301079296663951503688072299542357013093324718850936925265954204973634470836187733828189312553819810470405246669124171178070485118436102895117354417
    cr = 22238585749689335043198360403653248049710943304594623939441271714322821476047298977043454290592085809700500599520080107736858423927071836758485527270617538166045213386679961664240306883126224169183649140929168343634245637578487850945986688768857954082116136864696582066988005306045105860368497626822666433678879698344619056273526837700698315346972423482713305543394110949178233504551465821354514535155389087138867576532139739270960823294873497825040963862751772914087741831403951901
    c3 = 2385064917660948806957457681641614888669217960607006360543268900921017481245498563263991410918604891314384810533439253814523067168636768976220059028108900592323119524657903364697700329145453517769093265052715204625870232288203427545150983037310876534801548309890853026234248412421497939811385725642492104262954059677793538707604205179344884142656842895567795000647837461835179395742399372683460208271310884657279893532539121893558143029933794905470899127632780110459122203796256514

    mrinv3 = invert(pow(mr, 3, n3), n3)
    cr2 = cr*mrinv3 % n3
    kp = pow(mr, 4)-cr2
    p = gcd(kp, n3)
    q = n3//p
print(p*q == n3)

    phi = (p-1)*(q-1)
while True:
        s = getPrime(10)
if(gcd(s,p-1) == 1):
            sinv = invert(s,p-1)
            e = 4*s*sinv+3
if pow(mr, e, n3)==cr:
print(s, e)
break
    d = invert(e, phi)
    m3 = pow(c3, d, n3)
print(m3)
return m3

print long_to_bytes(level1(level2(level3())))

flag{4c2fd4e6-44de-445f-8c34-1235464de2de}

鲲鹏计算 && 鸿蒙专场 - Reverse

逆向部分WP写得比较简单,较为详细的wp可以参考师妹的博客https://c10udlnk.top/2020/12/29/wpFor-2020XCTF/

mips

三个迷宫,走完就行,这道题多解

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
g = [0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000003, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000001, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000001, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000001, 0x00000000, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x00000000, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x00000000, 0x00000003, 0x00000000, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x00000000, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x00000000, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x00000000, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x00000000, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000001, 0x00000001, 0x00000000, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000001, 0x00000001, 0x00000000, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x00000000, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000001, 0x00000000, 0x00000001, 0x00000001, 0x00000000, 0x00000001, 0x00000001, 0x00000000, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x00000000]

for i in range(3):
for j in range(15):
for k in range(15):
print(g[i*225+j*15+k],end=' ')
print()
print('----------------')

sssssssddddddds
1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 
1 1 1 1 1 0 3 0 1 0 0 0 0 0 0 
1 1 1 1 1 0 1 0 1 0 0 0 0 0 0 
1 1 1 1 1 0 1 0 1 0 0 0 0 0 0 
1 1 1 1 1 0 1 0 1 1 1 1 1 0 0 
1 1 1 1 1 0 1 0 0 0 0 0 1 0 0 
1 1 1 1 1 0 1 0 0 0 0 0 1 0 0 
1 1 1 1 1 0 1 0 0 0 0 0 1 1 0 
1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 
1 1 1 1 1 0 0 0 0 0 0 0 0 4 0 
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
----------------

ssssssssssdddddddddds
1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 
1 1 0 3 0 1 1 1 1 0 0 0 0 0 0 
1 1 0 1 0 0 0 0 1 0 0 0 0 0 0 
1 1 0 1 0 0 0 0 1 0 0 0 0 0 0 
1 1 0 1 1 0 0 0 1 1 1 1 1 0 0 
1 1 0 1 1 0 0 0 0 0 0 0 1 0 0 
1 1 0 1 1 0 0 0 0 0 0 0 1 0 0 
1 1 0 1 1 0 0 0 0 0 1 1 1 1 0 
1 1 0 1 1 0 0 0 0 0 1 0 0 1 0 
1 1 0 1 1 0 0 0 0 0 1 0 0 0 0 
1 1 0 1 1 1 1 1 1 0 1 0 1 1 0 
1 1 0 1 1 1 1 1 1 1 1 1 1 1 0 
1 1 0 0 0 0 0 0 0 0 0 0 0 4 0 
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
----------------

ddssddwddssssssdddssssdddss
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 3 1 1 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 1 0 1 1 1 0 0 0 0 0 0 0 
0 0 0 1 1 1 0 1 0 0 0 0 0 0 0 
0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 
0 1 1 0 1 0 0 1 0 0 0 0 0 0 0 
0 0 1 1 1 0 0 1 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 4 0

pypy

解包,反编译 https://github.com/extremecoders-re/pyinstxtractor/wiki/Extracting-Linux-ELF-binaries

rc4,这里注意python3的encode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# from Crypto.Cipher import ARC4
# key = b'Y\xf3\x02\xc3%\x9a\x820\x0b\xbb%\x7f~;\xd2\xdc'
# c = b'\x27\x5b\x39\xc3\x81\xc2\x8b\x70\x1a\xc3\x97\x23\x38\x45\x60\x22\xc2\xba\x06\xc3\xb0\x4f\x55\x01\x47\x1c\x47\xc3\x8a\xc3\x80\xc2\x9b\x72\xc3\xb5\xc3\x8a\x7e\xc2\xa5\xc2\xa0'
# print(c)
# enc = ARC4.new(key)
# print(enc.decrypt(c))
DEFAULT_KEY = u'Y\xf3\x02\xc3%\x9a\x820\x0b\xbb%\x7f~;\xd2\xdc'
def rc4(v11, key=DEFAULT_KEY, skip=1024):
    v12 = 0
    v13 = bytearray([v14 for v14 in range(256)])
    v12 = 0
for v15 in range(256):
        v12 = (v12 + v13[v15] + ord(key[(v15 % len(key))])) % 256
        v16 = v13[v15]
        v17 = v13[v12]
        v13[v15] = v13[v12]
        v13[v12] = v16
else:
        v12 = 0
        v18 = 0
        v19 = []
if skip > 0:
for v15 in range(skip):
                v12 = (v12 + 1) % 256
                v18 = (v18 + v13[v12]) % 256
                v13[v12], v13[v18] = v13[v18], v13[v12]

for v20 in v11:
            v12 = (v12 + 1) % 256
            v18 = (v18 + v13[v12]) % 256
            v13[v12], v13[v18] = v13[v18], v13[v12]
            v21 = v13[((v13[v12] + v13[v18]) % 256)]
            v19.append(chr(ord(v20) ^ v21))
else:
return ''.join(v19)


def func(v22):
    v23 = rc4(v22)
return v23
# if v23.encode('utf-8').hex() == '275b39c381c28b701ac3972338456022c2ba06c3b04f5501471c47c38ac380c29b72c3b5c38a7ec2a5c2a0':
#     return 'YOU WIN'
# return 'YOU LOSE'
print func(u'\x27\x5b\x39\xc3\x81\xc2\x8b\x70\x1a\xc3\x97\x23\x38\x45\x60\x22\xc2\xba\x06\xc3\xb0\x4f\x55\x01\x47\x1c\x47\xc3\x8a\xc3\x80\xc2\x9b\x72\xc3\xb5\xc3\x8a\x7e\xc2\xa5\xc2\xa0')
print func(u'\x27\x5b\x39\xc1\x8b\x70\x1a\xd7\x23\x38\x45\x60\x22\xba\x06\xf0\x4f\x55\x01\x47\x1c\x47\xca\xc0\x9b\x72\xf5\xca\x7e\xa5\xa0')
print func('flag{snake_bao_is_really_lucky}').encode('hex')

re123

chm文件,用chmdecompiler反编译,doc.htm有一段base64编码的powershell shellcode,解base64

img

执行,得到一个pe,补文件头,可以看到就是一个简单的后门,aes加密,密文,密钥直接给出,直接解即可

1
2
3
4
5
6
7
key = b'\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c'
cipher = b'\xb5\xf4\x3f\x45\x43\xd6\x99\xe7\x56\x1b\x2a\xaa\x84\x20\xc4\x46'

from Crypto.Cipher import AES

enc = AES.new(key,AES.MODE_ECB)
print(enc.decrypt(cipher))

flag{youcangues}

crash

crash包含多个可执行文件,binwalk分离获取主程序,password校验算法为按字节xor 0x17,之后每四个字节取md5和常量比对

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# "bf2b36d56f5757c13cad80494b385e78"
# "3fe9dbae5dc4408350500affa20074aa"
# "1fa6770eca6b57e47a042ffe52eca8ff"
# "1aad6b7da1122b4b5a53bf5a4d3b11b0"
# "e7b77d9e0ab19fc9ea98154f994fccc5"
# "75d9128cfeb61b8949664f6a067f6469"
# "d8b0a52c64d6075017b7346140550c46"
# "306529c7cdedfb06e27b39f7b2babf4d"

f = "bo&tn&o#~{c|vut.yb&y|''s.v|gg `"
print('flag{',end='')
for i in list(f):
print(chr(ord(i)^0x17),end='')
print('}',end='')

flag{ux1cy1x4iltkahbc9nu1nk00d9akpp7w}

arm

arm架构,程序输入key和flag,用key作为随机数种子(取低8位)初始化随机数池,作为常数(取低8位+1)形成42元一次方程组,output.txt就是方程组的ans。

hook程序地址00107A0,使程序直接打印生成的随机数序列,共42*42个

之后只要遍历一个字节的key,尝试解方程即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import pexpect
from sympy import *

# data=[]
# with open('output.txt','r') as f:
# tmp=f.read().split('\r\n')
# data=[int(x,16) for x in tmp]
# print(data)
data = [775008, 736965, 579982, 832102, 739711, 689694, 621261, 786007, 687380, 870278, 671072, 705346, 695702, 726075, 693811, 726115, 797388, 839688, 798029, 773858, 732406, 632966, 740936, 775656, 710214, 858672, 686622, 608896, 815068, 521720, 693197, 560581, 885102, 635306, 732285, 770318, 702253, 632762, 839978, 813599, 651986, 875709]
src = [0xA0, 0xE4, 0xBA, 0xFB, 0x10, 0xDD, 0xAC, 0x65, 0x8D, 0x0B, 0x57, 0x1A, 0xE4, 0x28, 0x96, 0xB3, 0x0C, 0x79, 0x4D, 0x80, 0x90, 0x99, 0x58, 0xFE, 0x50, 0xD3, 0xF9, 0x3C, 0x0F, 0xC1, 0xE3, 0xA6, 0x39, 0xC3, 0x28, 0x75, 0xF8, 0xC9, 0xC8, 0xCD, 0x78, 0x26]
flag = 'flag{000000000000000000000000000000000000}'

var=[]
for num in range(42):
exec("x"+str(num)+"=Symbol('x'+str(num))")
var.append("x"+str(num))
for i in range(256):
r = pexpect.spawn('./qemu-arm -L ./ ./aRm_getRand')
r.sendline(str(i))
r.sendline(flag)
r.readline()
r.readline()
rand = []
for j in range(42*42):
s = r.readline()
rand.append(int(str(s)[2:-5],16))
r.wait()
exper=[]
for j in range(42):
anEx=""
for k in range(42):
anEx+=str(rand[j*42+k])+"*"+var[k]+"+"
anEx=anEx[:-1]+"-"+str(data[j])
exper.append(anEx)
res=solve(exper,var)
print(str(i)+": ")
print(res.values())

82:

dict_values([198, 136, 219, 156, 107, 228, 152, 7, 239, 63, 97, 127, 134, 5, 247, 131, 109, 75, 96, 180, 241, 173, 57, 211, 49, 224, 157, 9, 34, 243, 129, 199, 1, 244, 31, 17, 157, 171, 252, 249, 64, 91])

xor table getflag

1
2
3
4
5
6
arr=[0xA0, 0xE4, 0xBA, 0xFB, 0x10, 0xDD, 0xAC, 0x65, 0x8D, 0x0B, 0x57, 0x1A, 0xE4, 0x28, 0x96, 0xB3, 0x0C, 0x79, 0x4D, 0x80, 0x90, 0x99, 0x58, 0xFE, 0x50, 0xD3, 0xF9, 0x3C, 0x0F, 0xC1, 0xE3, 0xA6, 0x39, 0xC3, 0x28, 0x75, 0xF8, 0xC9, 0xC8, 0xCD, 0x78, 0x26]
x=[198, 136, 219, 156, 107, 228, 152, 7, 239, 63, 97, 127, 134, 5, 247, 131, 109, 75, 96, 180, 241, 173, 57, 211, 49, 224, 157, 9, 34, 243, 129, 199, 1, 244, 31, 17, 157, 171, 252, 249, 64, 91]
flag=""
for i in range(42):
flag+=chr(x[i]^arr[i])
print(flag)

flag{94bb46eb-a0a2-4a4a-a3d5-2ba877deb448}

arm_pe

windows-arm架构,无环境,静态硬刚

普莱费尔密码

密钥表

1
2
3
4
5
6
7
8
9
CREIH

TQGNU

AOVXL

DZKYM

PBWFS

密文

KIMLXDWRZXTHXTHQTXTXHZWC

按规则解密即可

YE SM AY BE YO UC AN RU NA NA RM PE

flag{YESMAYBEYOUCANRUNANARMPE}

puzzle

mips架构

一个华容道游戏,八数码问题,用现成的算法算出走的方向

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include <iostream>
#include <vector>
#include <ctime>
#include <cstdlib>
#define maxState 10000
#define N 3
using namespace std;
bool isEqual(int a[N][N][maxState],int b[N][N],int n){
for(int i = 0;i < N;i ++){
for(int j = 0;j < N;j ++){
if(a[i][j][n] != b[i][j]) return false;
}
}
return true;
}
bool isEqual(int a[N][N],int b[N][N]){
for(int i = 0;i < N;i ++){
for(int j = 0;j < N;j ++){
if(a[i][j] != b[i][j]) return false;
}
}
return true;
}
int evalute(int state[N][N],int target[N][N]){
int num = 0;
for(int i = 0;i < N;i ++){
for(int j = 0;j < N;j ++)
if(state[i][j] != target[i][j]) num ++;
}
return num;
}
void findBrack(int a[N][N],int x,int y){
for(int i = 0;i < N;i ++){
for(int j = 0;j < N;j ++){
if(a[i][j] == 0) {
x = i;y = j;return;
}
}
}
}
bool move(int a[N][N],int b[N][N],int dir){
//1 up 2 down 3 left 4 right
int x = 0,y = 0;
for(int i = 0;i < N;i ++){
for(int j = 0;j < N;j ++){
b[i][j] = a[i][j];
if(a[i][j] == 0) {
x = i;y = j;
}
}
}
if(x == 0 && dir == 1) return false;
if(x == N-1 && dir == 2) return false;
if(y == 0 && dir == 3) return false;
if(y == N-1 && dir == 4) return false;
if(dir == 1){b[x-1][y] = 0;b[x][y] = a[x-1][y];}
else if(dir == 2){b[x+1][y] = 0;b[x][y] = a[x+1][y];}
else if(dir == 3){b[x][y-1] = 0;b[x][y] = a[x][y-1];}
else if(dir == 4){b[x][y+1] = 0;b[x][y] = a[x][y+1];}
else return false;
return true;
}
void statecpy(int a[N][N][maxState],int b[N][N],int n){
for(int i = 0;i < N;i ++){
for(int j = 0;j < N;j ++){
a[i][j][n] = b[i][j];
}
}
}
void getState(int a[N][N][maxState],int b[N][N],int n){
for(int i = 0;i < N;i ++){
for(int j = 0;j < N;j ++){
b[i][j] = a[i][j][n];
}
}
}
void statecpy(int a[N][N],int b[N][N]){
for(int i = 0;i < N;i++){
for(int j = 0;j < N;j++)
a[i][j] = b[i][j];
}
}
int checkAdd(int a[N][N][maxState],int b[N][N],int n){
for(int i = 0;i < n;i ++){
if(isEqual(a,b,i)) return i;
}
return -1;
}
int Astar(int a[N][N][maxState],int start[N][N],int target[N][N],int path[maxState]){
bool visited[maxState] = {false};
int fitness[maxState] = {0};
int passLen[maxState] = {0};
int curpos[N][N];
statecpy(curpos,start);
int id = 0,Curid = 0;
fitness[id] = evalute(curpos,target);
statecpy(a,start,id++);
while(!isEqual(curpos,target)){
for(int i = 1;i < 5;i ++){//向四周找方向
int tmp[N][N] = {0};
if(move(curpos,tmp,i)){
int state = checkAdd(a,tmp,id);
if(state == -1){//not add
path[id] = Curid;
passLen[id] = passLen[Curid] + 1;
fitness[id] = evalute(tmp,target) + passLen[id];
statecpy(a,tmp,id++);
}else{//add
int len = passLen[Curid] + 1,fit = evalute(tmp,target) + len;
if(fit < fitness[state]){
path[state] = Curid;
passLen[state] = len;
fitness[state] = fit;
visited[state] = false;
}
}
}
}
visited[Curid] = true;
//找到适应度最小的最为下一个带搜索节点
int minCur = -1;
for(int i = 0;i < id;i ++)
if(!visited[i] && (minCur == -1 || fitness[i] < fitness[minCur])) minCur = i;
Curid = minCur;
getState(a,curpos,Curid);
if(id == maxState) return -1;
}
return Curid;
}
void show(int a[N][N][maxState],int n){
cout << "-------------------------------\n";
for(int i = 0;i < N;i ++){
for(int j =0;j < N;j ++){
cout << a[i][j][n] << " ";
}
cout << endl;
}
cout << "-------------------------------\n";
}
int calDe(int a[N][N]){
int sum = 0;
for(int i = 0;i < N*N;i ++){
for(int j = i+1;j < N*N;j ++){
int m,n,c,d;
m = i/N;n = i%N;
c = j/N;d = j%N;
if(a[c][d] == 0) continue;
if(a[m][n] > a[c][d]) sum ++;
}
}
return sum;
}
void autoGenerate(int a[N][N]){
int maxMove = 50;
srand((unsigned)time(NULL));
int tmp[N][N];
while(maxMove --){
int dir = rand()%4 + 1;
if(move(a,tmp,dir)) statecpy(a,tmp);
}
}
int main(){
int a[N][N][maxState] = {0};
// int start[N][N] = {1,2,3,4,5,6,7,8,0};
// autoGenerate(start);
// cout << start[0][0] << start[1][1];
int start[N][N] = {4, 0, 3, 7, 2, 6, 8, 1, 5};
int target[N][N] = {1,2,3,4,5,6,7,8,0};
if(!(calDe(start)%2 == calDe(target)%2)){
cout << "无解\n";
return 0;
}
int path[maxState] = {0};
int res = Astar(a,start,target,path);
if(res == -1){
cout << "达到最大搜索能力\n";
return 0;
}
int shortest[maxState] = {0},j = 0;
while(res != 0){
shortest[j++] = res;
res = path[res];
}
cout << "第 0 步\n";
show(a,0);
for(int i = j - 1;i >= 0;i --){
cout << "第 " << j-i << " 步\n";
show(a,shortest[i]);
}
return 0;
}
//884226886224488

base64换表求解

1
2
3
4
5
6
7
8
9
10
11
12
import base64
b64table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'

def b64encode(src, table):

if len(table) != 64:
return 'Table length error'

return base64.b64encode(src.encode()).decode().translate(
str.maketrans(b64table, table))
a = b64encode('884226886224488','uvwxyz0123456789+/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrst')
print('flag{%s}' % a)

flag{8xOi6R2k8xOk6R2i7xOm}

鲲鹏计算 && 鸿蒙专场 - RealWorld

realworld这几道都比较简单,有手就行

AESbaby

arm架构,买个鲲鹏处理器的云服务器编译即可

抄个aes,table优化成52/62,百分之五十概率能打通,分段传shellcode,exp打通概率百分之二十左右

远程exp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from base64 import *
from pwn import *
from hashlib import md5
import string
context.log_level="debug"
def crackmd5(pre):
    table = string.ascii_letters+string.digits
for i in range(62):
for j in range(62):
for k in range(62):
for z in range(62):
                    post = table[i]+table[j]+table[k]+table[z]
                    tmp = pre+post

if md5(tmp).hexdigest().startswith('0'*6):
print('get')
print(tmp)
return post
print("error")
return 'error'

p = remote('139.159.190.149',10000)
p.recvuntil(b'md5(')
pre = p.recvuntil(b'+')[:-1]
print ('pre -> ',pre)

p.send(crackmd5(pre))
p.sendline('')
sleep(1)
print (p.recvuntil(b'base64:')
)
sleep(1)
with open('./a.out','rb') as r:
    a = r.read()
    c = b64encode(a)
for i in range(0,len(c)/1024):
        p.send(c[i*1024:(i+1)*1024])
if len(c)%1024 !=0:
        p.sendline(c[(len(c)/1024)*1024:])
print(len(c))
print(len(c)/1024)
sleep(50)
print p.recvuntil("}")

可执行文件源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553

/*
 * Advanced Encryption Standard
 * @author Dani Huertas
 * @email huertas.dani@gmail.com
 *
 * Based on the document FIPS PUB 197
 */
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
/*
 * Addition in GF(2^8)
 * http://en.wikipedia.org/wiki/Finite_field_arithmetic
 */
uint8_t gadd(uint8_t a, uint8_t b) {
return a ^ b;
}

/*
 * Subtraction in GF(2^8)
 * http://en.wikipedia.org/wiki/Finite_field_arithmetic
 */
uint8_t gsub(uint8_t a, uint8_t b) {
return a ^ b;
}

/*
 * Multiplication in GF(2^8)
 * http://en.wikipedia.org/wiki/Finite_field_arithmetic
 * Irreducible polynomial m(x) = x8 + x4 + x3 + x + 1
 *
 * NOTE: This function can be easily replaced with a look up table for a speed
 *       boost, at the expense of an increase in memory size (around 65 KB).
 */
uint8_t gmult(uint8_t a, uint8_t b) {
uint8_t p = 0, i = 0, hbs = 0;

for (i = 0; i < 8; i++) {
if (b & 1) {
      p ^= a;
    }

    hbs = a & 0x80;
    a <<= 1;
if (hbs)
      a ^= 0x1b;  // 0000 0001 0001 1011
    b >>= 1;
  }

return (uint8_t)p;
}

/*
 * Addition of 4 byte words
 * m(x) = x4+1
 */
void coef_add(uint8_t a[], uint8_t b[], uint8_t d[]) {
d[0] = a[0] ^ b[0];
d[1] = a[1] ^ b[1];
d[2] = a[2] ^ b[2];
d[3] = a[3] ^ b[3];
}

/*
 * Multiplication of 4 byte words
 * m(x) = x4+1
 */
void coef_mult(uint8_t* a, uint8_t* b, uint8_t* d) {
d[0] = gmult(a[0], b[0]) ^ gmult(a[3], b[1]) ^ gmult(a[2], b[2]) ^
gmult(a[1], b[3]);
d[1] = gmult(a[1], b[0]) ^ gmult(a[0], b[1]) ^ gmult(a[3], b[2]) ^
gmult(a[2], b[3]);
d[2] = gmult(a[2], b[0]) ^ gmult(a[1], b[1]) ^ gmult(a[0], b[2]) ^
gmult(a[3], b[3]);
d[3] = gmult(a[3], b[0]) ^ gmult(a[2], b[1]) ^ gmult(a[1], b[2]) ^
gmult(a[0], b[3]);
}

/*
 * The cipher Key.
 */
int K;

/*
 * Number of columns (32-bit words) comprising the State. For this
 * standard, Nb = 4.
 */
int Nb = 4;

/*
 * Number of 32-bit words comprising the Cipher Key. For this
 * standard, Nk = 4, 6, or 8.
 */
int Nk;

/*
 * Number of rounds, which is a function of  Nk  and  Nb (which is
 * fixed). For this standard, Nr = 10, 12, or 14.
 */
int Nr;

/*
 * S-box transformation table
 */
static uint8_t s_box[256] = {
// 0     1     2     3     4     5     6     7     8     9     a     b     c
// d     e     f
0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5,
0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,  // 0
0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,  // 1
0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc,
0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,  // 2
0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a,
0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,  // 3
0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,  // 4
0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b,
0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,  // 5
0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85,
0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,  // 6
0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,  // 7
0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17,
0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,  // 8
0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88,
0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,  // 9
0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,  // a
0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9,
0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,  // b
0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6,
0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,  // c
0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,  // d
0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94,
0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,  // e
0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68,
0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16};  // f

/*
 * Inverse S-box transformation table
 */
static uint8_t inv_s_box[256] = {
// 0     1     2     3     4     5     6     7     8     9     a     b     c
// d     e     f
0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38,
0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb,  // 0
0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb,  // 1
0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d,
0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,  // 2
0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2,
0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25,  // 3
0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92,  // 4
0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda,
0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,  // 5
0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a,
0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06,  // 6
0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b,  // 7
0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea,
0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,  // 8
0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85,
0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e,  // 9
0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b,  // a
0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20,
0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,  // b
0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31,
0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f,  // c
0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef,  // d
0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0,
0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,  // e
0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26,
0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d};  // f

/*
 * Generates the round constant Rcon[i]
 */
uint8_t R[] = {0x02, 0x00, 0x00, 0x00};

uint8_t* Rcon(uint8_t i) {
if (i == 1) {
R[0] = 0x01;  // x^(1-1) = x^0 = 1
  } else if (i > 1) {
R[0] = 0x02;
    i--;
while (i - 1 > 0) {
R[0] = gmult(R[0], 0x02);
      i--;
    }
  }

return R;
}

/*
 * Transformation in the Cipher and Inverse Cipher in which a Round
 * Key is added to the State using an XOR operation. The length of a
 * Round Key equals the size of the State (i.e., for Nb = 4, the Round
 * Key length equals 128 bits/16 bytes).
 */
void add_round_key(uint8_t* state, uint8_t* w, uint8_t r) {
uint8_t c;

for (c = 0; c < Nb; c++) {
state[Nb * 0 + c] =
state[Nb * 0 + c] ^
w[4 * Nb * r + 4 * c + 0];  // debug, so it works for Nb !=4
state[Nb * 1 + c] = state[Nb * 1 + c] ^ w[4 * Nb * r + 4 * c + 1];
state[Nb * 2 + c] = state[Nb * 2 + c] ^ w[4 * Nb * r + 4 * c + 2];
state[Nb * 3 + c] = state[Nb * 3 + c] ^ w[4 * Nb * r + 4 * c + 3];
  }
}

/*
 * Transformation in the Cipher that takes all of the columns of the
 * State and mixes their data (independently of one another) to
 * produce new columns.
 */
void mix_columns(uint8_t* state) {
uint8_t a[] = {0x02, 0x01, 0x01,
0x03};  // a(x) = {02} + {01}x + {01}x2 + {03}x3
uint8_t i, j, col[4], res[4];

for (j = 0; j < Nb; j++) {
for (i = 0; i < 4; i++) {
col[i] = state[Nb * i + j];
    }

coef_mult(a, col, res);

for (i = 0; i < 4; i++) {
state[Nb * i + j] = res[i];
    }
  }
}

/*
 * Transformation in the Inverse Cipher that is the inverse of
 * MixColumns().
 */
void inv_mix_columns(uint8_t* state) {
uint8_t a[] = {0x0e, 0x09, 0x0d,
0x0b};  // a(x) = {0e} + {09}x + {0d}x2 + {0b}x3
uint8_t i, j, col[4], res[4];

for (j = 0; j < Nb; j++) {
for (i = 0; i < 4; i++) {
col[i] = state[Nb * i + j];
    }

coef_mult(a, col, res);

for (i = 0; i < 4; i++) {
state[Nb * i + j] = res[i];
    }
  }
}

/*
 * Transformation in the Cipher that processes the State by cyclically
 * shifting the last three rows of the State by different offsets.
 */
void shift_rows(uint8_t* state) {
uint8_t i, k, s, tmp;

for (i = 1; i < 4; i++) {
// shift(1,4)=1; shift(2,4)=2; shift(3,4)=3
// shift(r, 4) = r;
    s = 0;
while (s < i) {
      tmp = state[Nb * i + 0];

for (k = 1; k < Nb; k++) {
state[Nb * i + k - 1] = state[Nb * i + k];
      }

state[Nb * i + Nb - 1] = tmp;
      s++;
    }
  }
}

/*
 * Transformation in the Inverse Cipher that is the inverse of
 * ShiftRows().
 */
void inv_shift_rows(uint8_t* state) {
uint8_t i, k, s, tmp;

for (i = 1; i < 4; i++) {
    s = 0;
while (s < i) {
      tmp = state[Nb * i + Nb - 1];

for (k = Nb - 1; k > 0; k--) {
state[Nb * i + k] = state[Nb * i + k - 1];
      }

state[Nb * i + 0] = tmp;
      s++;
    }
  }
}

/*
 * Transformation in the Cipher that processes the State using a non­
 * linear byte substitution table (S-box) that operates on each of the
 * State bytes independently.
 */
void sub_bytes(uint8_t* state) {
uint8_t i, j;
uint8_t row, col;

for (i = 0; i < 4; i++) {
for (j = 0; j < Nb; j++) {
      row = (state[Nb * i + j] & 0xf0) >> 4;
      col = state[Nb * i + j] & 0x0f;
state[Nb * i + j] = s_box[16 * row + col];
    }
  }
}

/*
 * Transformation in the Inverse Cipher that is the inverse of
 * SubBytes().
 */
void inv_sub_bytes(uint8_t* state) {
uint8_t i, j;
uint8_t row, col;

for (i = 0; i < 4; i++) {
for (j = 0; j < Nb; j++) {
      row = (state[Nb * i + j] & 0xf0) >> 4;
      col = state[Nb * i + j] & 0x0f;
state[Nb * i + j] = inv_s_box[16 * row + col];
    }
  }
}

/*
 * Function used in the Key Expansion routine that takes a four-byte
 * input word and applies an S-box to each of the four bytes to
 * produce an output word.
 */
void sub_word(uint8_t* w) {
uint8_t i;

for (i = 0; i < 4; i++) {
w[i] = s_box[16 * ((w[i] & 0xf0) >> 4) + (w[i] & 0x0f)];
  }
}

/*
 * Function used in the Key Expansion routine that takes a four-byte
 * word and performs a cyclic permutation.
 */
void rot_word(uint8_t* w) {
uint8_t tmp;
uint8_t i;

  tmp = w[0];

for (i = 0; i < 3; i++) {
w[i] = w[i + 1];
  }

w[3] = tmp;
}

/*
 * Key Expansion
 */
void aes_key_expansion(uint8_t* key, uint8_t* w) {
uint8_t tmp[4];
uint8_t i, j;
uint8_t len = Nb * (Nr + 1);

for (i = 0; i < Nk; i++) {
w[4 * i + 0] = key[4 * i + 0];
w[4 * i + 1] = key[4 * i + 1];
w[4 * i + 2] = key[4 * i + 2];
w[4 * i + 3] = key[4 * i + 3];
  }

for (i = Nk; i < len; i++) {
tmp[0] = w[4 * (i - 1) + 0];
tmp[1] = w[4 * (i - 1) + 1];
tmp[2] = w[4 * (i - 1) + 2];
tmp[3] = w[4 * (i - 1) + 3];

if (i % Nk == 0) {
rot_word(tmp);
sub_word(tmp);
coef_add(tmp, Rcon(i / Nk), tmp);

    } else if (Nk > 6 && i % Nk == 4) {
sub_word(tmp);
    }

w[4 * i + 0] = w[4 * (i - Nk) + 0] ^ tmp[0];
w[4 * i + 1] = w[4 * (i - Nk) + 1] ^ tmp[1];
w[4 * i + 2] = w[4 * (i - Nk) + 2] ^ tmp[2];
w[4 * i + 3] = w[4 * (i - Nk) + 3] ^ tmp[3];
  }
}

/*
 * Initialize AES variables and allocate memory for expanded key
 */
uint8_t* aes_init(size_t key_size) {
switch (key_size) {
default:
case 16:
      Nk = 4;
      Nr = 10;
break;
case 24:
      Nk = 6;
      Nr = 12;
break;
case 32:
      Nk = 8;
      Nr = 14;
break;
  }

return malloc(Nb * (Nr + 1) * 4);
}

/*
 * Performs the AES cipher operation
 */
void aes_cipher(uint8_t* in, uint8_t* out, uint8_t* w) {
uint8_t state[4 * Nb];
uint8_t r, i, j;

for (i = 0; i < 4; i++) {
for (j = 0; j < Nb; j++) {
state[Nb * i + j] = in[i + 4 * j];
    }
  }

add_round_key(state, w, 0);

for (r = 1; r < Nr; r++) {
sub_bytes(state);
shift_rows(state);
mix_columns(state);
add_round_key(state, w, r);
  }

sub_bytes(state);
shift_rows(state);
add_round_key(state, w, Nr);

for (i = 0; i < 4; i++) {
for (j = 0; j < Nb; j++) {
out[i + 4 * j] = state[Nb * i + j];
    }
  }
}

/*
 * Performs the AES inverse cipher operation
 */
void aes_inv_cipher(uint8_t* in, uint8_t* out, uint8_t* w) {
uint8_t state[4 * Nb];
uint8_t r, i, j;

for (i = 0; i < 4; i++) {
for (j = 0; j < Nb; j++) {
state[Nb * i + j] = in[i + 4 * j];
    }
  }

add_round_key(state, w, Nr);

for (r = Nr - 1; r >= 1; r--) {
inv_shift_rows(state);
inv_sub_bytes(state);
add_round_key(state, w, r);
inv_mix_columns(state);
  }

inv_shift_rows(state);
inv_sub_bytes(state);
add_round_key(state, w, 0);

for (i = 0; i < 4; i++) {
for (j = 0; j < Nb; j++) {
out[i + 4 * j] = state[Nb * i + j];
    }
  }
}


int main(int argc, char* argv[]) {


char s[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
// char s[] = "124";
uint8_t buf[20];
scanf("%12s",&buf);
uint8_t tmp[100];
uint8_t cipher[16];
scanf("%32s",&tmp);
for(int i=0;i<32;i++){
if (tmp[i]>0x40){
tmp[i] -= 0x57;
        }else{
tmp[i] -=0x30;
        }
    }
for(int i=0;i<32;i+=2){
cipher[i/2] = (tmp[i] << 4) | tmp[i+1];
    }

for(int i =0;i<52;i++){
for(int j =0;j<52;j++){
for(int k =0;k<52;k++){
for(int z =0;z<52;z++){
buf[12] = s[i];
buf[13] = s[j];
buf[14] = s[k];
buf[15] = s[z];
buf[16] = '\x00';
uint8_t* w;  // expanded key
                    w = aes_init(sizeof(buf));
aes_key_expansion(buf, w);
uint8_t plain[16]={0};
aes_inv_cipher(cipher, plain, w);
// puts(plain);
// puts(buf);
// puts(plain);
if(!strncmp(plain,"KUNPENG_HPC_AES!",16)){
printf("%s",buf+12);
return 0;
                    }
                }
            }
        }   
    }

return 0;
}

Hash

老规矩,随便找个sha256源码,鲲鹏编译,大概百分之二的概率能出

exp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from base64 import *
from pwn import *
from hashlib import md5
import string
context.log_level="debug"
def crackmd5(pre):
    table = string.ascii_letters+string.digits
for i in range(62):
for j in range(62):
for k in range(62):
for z in range(62):
for m in range(62):
                        post = table[i]+table[j]+table[k]+table[z]+table[m]
                        tmp = pre+post

if md5(tmp).hexdigest().startswith('0'*7):
print('get')
print(tmp)
return post
print("error")
return 'error'

p = remote('139.159.190.149',10002)
p.recvuntil(b'md5(')
pre = p.recvuntil(b'+')[:-1]
print ('pre -> ',pre)

p.send(crackmd5(pre))
p.sendline('')
sleep(1)
print (p.recvuntil(b'base64:'))
p.interactive()
# sleep(1)
# with open('./a.out','rb') as r:
#     a = r.read()
#     c = b64encode(a)
#     for i in range(0,len(c)/1024):
#         p.send(c[i*1024:(i+1)*1024])
#     if len(c)%1024 !=0:
#         p.sendline(c[(len(c)/1024)*1024:])
#     print(len(c))
#     print(len(c)/1024)
# sleep(50)
# print p.recvuntil("}")

main.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*********************************************************************
* Filename:   sha256.c
* Author:     Brad Conte (brad AT bradconte.com)
* Copyright:
* Disclaimer: This code is presented "as is" without any guarantees.
* Details:    Performs known-answer tests on the corresponding SHA1
              implementation. These tests do not encompass the full
              range of available test vectors, however, if the tests
              pass it is very, very likely that the code is correct
              and was compiled properly. This code also serves as
              example usage of the functions.
*********************************************************************/

/*************************** HEADER FILES ***************************/
#include <stdio.h>
#include <memory.h>
#include <string.h>
#include "sha256.h"

/*********************** FUNCTION DEFINITIONS ***********************/
int main()
{
    BYTE text1[20] = {0};
scanf("%10s",&text1);
char s[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
for(int i =0;i<62;i++){
for(int j =0;j<62;j++){
for(int k =0;k<62;k++){
for(int m=0;m<62;m++){
for(int z =0;z<62;z++){
text1[10] = s[i];
text1[11] = s[j];
text1[12] = s[k];
text1[13] = s[m];
text1[14] = s[z];
text1[15] = '\x00';
                        BYTE buf[SHA256_BLOCK_SIZE];
                        SHA256_CTX ctx;
int idx;
int pass = 1;
sha256_init(&ctx);
sha256_update(&ctx, text1, 15);
sha256_final(&ctx, buf);
if(buf[0] == 0 && buf[1] ==0 &&buf[2] == 0 && ((buf[3] >> 2) == 0)){
printf("%s",text1+10);
return 0;

                        }
                    }
                }
            }
        }   
    }

// for(int i=0;i<32;i++){
//     printf("%02x",buf[i]&0xff);
// }
return(0);
}

sha256.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*********************************************************************
* Filename:   sha256.h
* Author:     Brad Conte (brad AT bradconte.com)
* Copyright:
* Disclaimer: This code is presented "as is" without any guarantees.
* Details:    Defines the API for the corresponding SHA1 implementation.
*********************************************************************/

#ifndef SHA256_H
#define SHA256_H

/*************************** HEADER FILES ***************************/
#include <stddef.h>

/****************************** MACROS ******************************/
#define SHA256_BLOCK_SIZE 32            // SHA256 outputs a 32 byte digest

/**************************** DATA TYPES ****************************/
typedef unsigned char BYTE;             // 8-bit byte
typedef unsigned int  WORD;             // 32-bit word, change to "long" for 16-bit machines

typedef struct {
    BYTE data[64];
    WORD datalen;
unsigned long long bitlen;
    WORD state[8];
} SHA256_CTX;

/*********************** FUNCTION DECLARATIONS **********************/
void sha256_init(SHA256_CTX *ctx);
void sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len);
void sha256_final(SHA256_CTX *ctx, BYTE hash[]);

#endif   // SHA256_H

sha256.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*********************************************************************
* Filename:   sha256.c
* Author:     Brad Conte (brad AT bradconte.com)
* Copyright:
* Disclaimer: This codeis presented "as is" without any guarantees.
* Details:    Implementation of the SHA-256 hashing algorithm.
              SHA-256 is one of the three algorithms in the SHA2
              specification. The others, SHA-384 and SHA-512, are not
              offered in this implementation.
              Algorithm specification can be found here:
               * http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf
              This implementation uses little endian byte order.
*********************************************************************/

/*************************** HEADER FILES ***************************/
#include <stdlib.h>
#include <memory.h>
#include "sha256.h"

/****************************** MACROS ******************************/
#define ROTLEFT(a,b) (((a) << (b)) | ((a) >> (32-(b))))
#define ROTRIGHT(a,b) (((a) >> (b)) | ((a) << (32-(b))))

#define CH(x,y,z) (((x) & (y)) ^ (~(x) & (z)))
#define MAJ(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
#define EP0(x) (ROTRIGHT(x,2) ^ ROTRIGHT(x,13) ^ ROTRIGHT(x,22))
#define EP1(x) (ROTRIGHT(x,6) ^ ROTRIGHT(x,11) ^ ROTRIGHT(x,25))
#define SIG0(x) (ROTRIGHT(x,7) ^ ROTRIGHT(x,18) ^ ((x) >> 3))
#define SIG1(x) (ROTRIGHT(x,17) ^ ROTRIGHT(x,19) ^ ((x) >> 10))

/**************************** VARIABLES *****************************/
static const WORD k[64] = {
0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5,
0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174,
0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc,0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da,
0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7,0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967,
0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13,0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85,
0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3,0xd192e819,0xd6990624,0xf40e3585,0x106aa070,
0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5,0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3,
0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2
};

/*********************** FUNCTION DEFINITIONS ***********************/
void sha256_transform(SHA256_CTX *ctx, const BYTE data[])
{
    WORD a, b, c, d, e, f, g, h, i, j, t1, t2, m[64];

for (i = 0, j = 0; i < 16; ++i, j += 4)
m[i] = (data[j] << 24) | (data[j + 1] << 16) | (data[j + 2] << 8) | (data[j + 3]);
for ( ; i < 64; ++i)
m[i] = SIG1(m[i - 2]) + m[i - 7] + SIG0(m[i - 15]) + m[i - 16];

    a = ctx->state[0];
    b = ctx->state[1];
    c = ctx->state[2];
    d = ctx->state[3];
    e = ctx->state[4];
    f = ctx->state[5];
    g = ctx->state[6];
    h = ctx->state[7];

for (i = 0; i < 64; ++i) {
        t1 = h + EP1(e) + CH(e,f,g) + k[i] + m[i];
        t2 = EP0(a) + MAJ(a,b,c);
        h = g;
        g = f;
        f = e;
        e = d + t1;
        d = c;
        c = b;
        b = a;
        a = t1 + t2;
    }

ctx->state[0] += a;
ctx->state[1] += b;
ctx->state[2] += c;
ctx->state[3] += d;
ctx->state[4] += e;
ctx->state[5] += f;
ctx->state[6] += g;
ctx->state[7] += h;
}

void sha256_init(SHA256_CTX *ctx)
{
ctx->datalen = 0;
ctx->bitlen = 0;
ctx->state[0] = 0x6a09e667;
ctx->state[1] = 0xbb67ae85;
ctx->state[2] = 0x3c6ef372;
ctx->state[3] = 0xa54ff53a;
ctx->state[4] = 0x510e527f;
ctx->state[5] = 0x9b05688c;
ctx->state[6] = 0x1f83d9ab;
ctx->state[7] = 0x5be0cd19;
}

void sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len)
{
    WORD i;

for (i = 0; i < len; ++i) {
ctx->data[ctx->datalen] = data[i];
ctx->datalen++;
if (ctx->datalen == 64) {
sha256_transform(ctx, ctx->data);
ctx->bitlen += 512;
ctx->datalen = 0;
        }
    }
}

void sha256_final(SHA256_CTX *ctx, BYTE hash[])
{
    WORD i;

    i = ctx->datalen;

// Pad whatever data is left in the buffer.
if (ctx->datalen < 56) {
ctx->data[i++] = 0x80;
while (i < 56)
ctx->data[i++] = 0x00;
    }
else {
ctx->data[i++] = 0x80;
while (i < 64)
ctx->data[i++] = 0x00;
sha256_transform(ctx, ctx->data);
memset(ctx->data, 0, 56);
    }

// Append to the padding the total message's length in bits and transform.
ctx->bitlen += ctx->datalen * 8;
ctx->data[63] = ctx->bitlen;
ctx->data[62] = ctx->bitlen >> 8;
ctx->data[61] = ctx->bitlen >> 16;
ctx->data[60] = ctx->bitlen >> 24;
ctx->data[59] = ctx->bitlen >> 32;
ctx->data[58] = ctx->bitlen >> 40;
ctx->data[57] = ctx->bitlen >> 48;
ctx->data[56] = ctx->bitlen >> 56;
sha256_transform(ctx, ctx->data);

// Since this implementation uses little endian byte ordering and SHA uses big endian,
// reverse all the bytes when copying the final state to the output hash.
for (i = 0; i < 4; ++i) {
hash[i]      = (ctx->state[0] >> (24 - i * 8)) & 0x000000ff;
hash[i + 4]  = (ctx->state[1] >> (24 - i * 8)) & 0x000000ff;
hash[i + 8]  = (ctx->state[2] >> (24 - i * 8)) & 0x000000ff;
hash[i + 12] = (ctx->state[3] >> (24 - i * 8)) & 0x000000ff;
hash[i + 16] = (ctx->state[4] >> (24 - i * 8)) & 0x000000ff;
hash[i + 20] = (ctx->state[5] >> (24 - i * 8)) & 0x000000ff;
hash[i + 24] = (ctx->state[6] >> (24 - i * 8)) & 0x000000ff;
hash[i + 28] = (ctx->state[7] >> (24 - i * 8)) & 0x000000ff;
    }
}

flag{QuiCK_H4sh_cbDbdBdcd6}

luaplayground01

鸿蒙系统运行的lua,execute被禁用,通过io读文件,hexencode分段读取

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function bin2hex(s)
s=string.gsub(s,"(.)",function (x) return string.format("%02X ",string.byte(x)) end)
return s
end

ff=io.open('/bin/flag_app',r):read("*a")

print(bin2hex(string.sub(ff,1,300)))
print(bin2hex(string.sub(ff,301,600)))
print(bin2hex(string.sub(ff,601,900)))
print(bin2hex(string.sub(ff,901,1200)))
print(bin2hex(string.sub(ff,1201,1500)))
print(bin2hex(string.sub(ff,1501,1800)))
print(bin2hex(string.sub(ff,1801,2100)))
print(bin2hex(string.sub(ff,2101,2400)))
print(bin2hex(string.sub(ff,2401,2700)))
print(bin2hex(string.sub(ff,2701,3000)))
print(bin2hex(string.sub(ff,3001,3300)))
print(bin2hex(string.sub(ff,3301,3600)))
print(bin2hex(string.sub(ff,3601,3900)))
print(bin2hex(string.sub(ff,3901,4200)))
print(bin2hex(string.sub(ff,4201,4500)))
print(bin2hex(string.sub(ff,4501,4800)))
print(bin2hex(string.sub(ff,4801,5100)))
print(bin2hex(string.sub(ff,5101,5400)))
print(bin2hex(string.sub(ff,5401,5700)))
print(bin2hex(string.sub(ff,5701,6000)))
print(bin2hex(string.sub(ff,6001,6300)))
print(bin2hex(string.sub(ff,6301,6600)))
print(bin2hex(string.sub(ff,6601,6900)))
print(bin2hex(string.sub(ff,6901,7200)))
print(bin2hex(string.sub(ff,7201,7500)))
print(bin2hex(string.sub(ff,7501,7800)))
print(bin2hex(string.sub(ff,7801,8100)))
print(bin2hex(string.sub(ff,8101,8400)))
print(bin2hex(string.sub(ff,8401,8700)))
print(bin2hex(string.sub(ff,8701,9000)))
print(bin2hex(string.sub(ff,9001,9300)))
print(bin2hex(string.sub(ff,9301,9600)))
print(bin2hex(string.sub(ff,9601,9900)))
print(bin2hex(string.sub(ff,9901,10200)))
print(bin2hex(string.sub(ff,10201,10500)))
print(bin2hex(string.sub(ff,10501,10800)))
print(bin2hex(string.sub(ff,10801,11100)))
print(bin2hex(string.sub(ff,11101,11400)))
print(bin2hex(string.sub(ff,11401,11700)))
print(bin2hex(string.sub(ff,11701,12000)))
print(bin2hex(string.sub(ff,12001,12300)))
print(bin2hex(string.sub(ff,12301,12600)))
print(bin2hex(string.sub(ff,12601,12900)))
print(bin2hex(string.sub(ff,12901,13200)))
print(bin2hex(string.sub(ff,13201,13489)))

简单逆向

1
2
3
4
5
6
b = [0x9C, 0x6D, 0xE7, 0x56, 0x06, 0xD2, 0x0D, 0xEB, 0xDD, 0xF0, 0x9E, 0xB7, 0xFB, 0xE6, 0xEC, 0x3B, 0xB7, 0x5E, 0x75, 0x53, 0xD6, 0x83, 0x75, 0xAF, 0x18, 0xF7, 0x99, 0x95, 0xF2, 0xC1, 0xF2, 0xDB, 0x9F, 0x65, 0xB4, 0x06, 0x49, 0x87, 0x58, 0xE2, 0xDE, 0xB5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
a = [0xFA, 0x01, 0x86, 0x31, 0x7D, 0xB1, 0x69, 0xD3, 0xB8, 0xC8, 0xA6, 0xD6, 0x98, 0xCB, 0x8E, 0x03, 0xD1, 0x68, 0x58, 0x67, 0xB2, 0xE6, 0x40, 0x82, 0x7A, 0xC3, 0xFD, 0xA1, 0xDF, 0xF0, 0x96, 0xBF]


for i in range(42):
print(chr(b[i] ^ a[i&31]),end='')

flag{cd8e88ac-b8f6-4de5-b4d4-1dded274611f}

0%