第三届河北省大学生网络与信息安全选拔赛-Crypto-WP

2020年10月18日 41点热度 0人点赞 0条评论

可爱小小桃的CSDN

math [一血]

题目:

from Crypto.Util.number import *
from hashlib import md5

flag = "XXX"
assert len(flag) == 14
pad = bytes_to_long(md5(flag).digest())

hack = 0

for char in flag:
    hack+= pad
    hack*= ord(char)

print hack
#hack = 64364485357060434848865708402537097493512746702748009007197338675
#flag_to_submit = "flag{" + flag + "}"

根据题目,首先hack通过分解,得到了多个因子

hack = pad * last_char * (1 + ...+n)
pad = (min_md5,max_md5)

直接爆破hack的值,对每个值进行计算
解密脚本如下

#python2

from Crypto.Util.number import *
from hashlib import md5
from itertools import combinations

len_flag = 14
hack = 64364485357060434848865708402537097493512746702748009007197338675

raw_input()

def get_all_candidate(hack):
    return [chr(i) for i in range(32, 129) if hack % i == 0]

def backtrack(i, h, p, ans, deep):
    if h < 0:
        return False
    if len(ans) > len_flag:
        return False
    if h / ord(i) == p and p == bytes_to_long(md5(ans[::-1]).digest()):
        print ans[::-1]
        raw_input()
        return True
    candidate = get_all_candidate(h/ord(i) - p)

    if not candidate:
        return False
    else:
        done = False
        for j in candidate:
            if not backtrack(j, h/ord(i) - p, p, ans + j, deep + 1):
                pass
            else:
                done = True

        return done

c = [3, 3, 5, 5, 7, 107, 487, 607, 28429, 29287, 420577267963, 3680317203978923, 1002528655290265069]
for r in range(1, 14):
    for factors in combinations(c, r):
        pad = 1
        for f in factors:
            pad *= f
        if pad > 340282366920938457608348813069405954094 or pad < 3922569271515906540887:
            continue
        print factors

        for k in get_all_candidate(hack):
            print "————————"
            backtrack(k, hack, pad, k, 1)
            # raw_input()

#flag{d0y0ul1keM@TH?}

rsa [一血]

题目:

n=22561172536677648559787604959523195072179259409010314452272275495363968755657659138742248552894595529382230922241140656549843203305826473571445603834757787255736898096406153231539420740606617993518122317969410178044748567867122389763000873035273736666346624950112390179154333942974763371969584888993523474785703126407758739432302547292610981495520537518042779911203114321445895667363586256353373620877601821136901641493999842631467944779970213905636039444786194077923883593166806502276718151627041975659783265190382918098071120315433981040541826821825277381380527761087122467964932153713194745798177997722042776467823
e=65537
c=19328196358751658895450655392637127310222166740765135237100788629359244004186017531913542633846914446577530070361990508415396536818488820222120779983101438854297373364445564149526771854808100054824945213757075977600155153794380392843250249421227703382007213012131876851828154156292326203220320138218001022549062888054700986604924812634110284449199586085012678155983265546720208230278018003075240556412400816319188195980878492235194635353445804239756712398169138480766013684092405117638265070954612493845540746705265223696626365851780172702852574231465793269945857869635628236488314786408909172723290733282538209968247
2d+phi(n)=24114829899810646031152927156356440623523513950820570971172657869605295042116148846058663431685177495769257006671204194892172258274371716987566720411992577862665150660975369465525447840121901649254226473481778722127378865051369383216827923429416969207860136204997233907126159519798979336641129811969668501246242088955574999107571615543760265312436830459903515683689045577164832265662220035876790112563967655077079968881948607640842264058086427875121914327767238217629898601698947580820398969991591620306905238666381003642185305206988597488619954300386153696163111726576675781435154124871145727025050765235161063120482

通过题目给出的2d+phi(n),因为amodb(amodb)+b的值一样

2 \times d + phi(n)= A
A \times e = 2\times d\times e + e\times phi(n) mod phi(n)
A\times e = 2mod phi(n)
phi(n) = A \times e - 2

同理可以解出d,得到d、n、c直接求得m

from Crypto.Util.number import *
from gmpy2 import *
from libnum import *

n = 22561172536677648559787604959523195072179259409010314452272275495363968755657659138742248552894595529382230922241140656549843203305826473571445603834757787255736898096406153231539420740606617993518122317969410178044748567867122389763000873035273736666346624950112390179154333942974763371969584888993523474785703126407758739432302547292610981495520537518042779911203114321445895667363586256353373620877601821136901641493999842631467944779970213905636039444786194077923883593166806502276718151627041975659783265190382918098071120315433981040541826821825277381380527761087122467964932153713194745798177997722042776467823
c = 19328196358751658895450655392637127310222166740765135237100788629359244004186017531913542633846914446577530070361990508415396536818488820222120779983101438854297373364445564149526771854808100054824945213757075977600155153794380392843250249421227703382007213012131876851828154156292326203220320138218001022549062888054700986604924812634110284449199586085012678155983265546720208230278018003075240556412400816319188195980878492235194635353445804239756712398169138480766013684092405117638265070954612493845540746705265223696626365851780172702852574231465793269945857869635628236488314786408909172723290733282538209968247

#2d+phi(n) = 24114829899810646031152927156356440623523513950820570971172657869605295042116148846058663431685177495769257006671204194892172258274371716987566720411992577862665150660975369465525447840121901649254226473481778722127378865051369383216827923429416969207860136204997233907126159519798979336641129811969668501246242088955574999107571615543760265312436830459903515683689045577164832265662220035876790112563967655077079968881948607640842264058086427875121914327767238217629898601698947580820398969991591620306905238666381003642185305206988597488619954300386153696163111726576675781435154124871145727025050765235161063120482
#a = 2d+phi(n)
#d = a//2
#print(d)

d = 12057414949905323015576463578178220311761756975410285485586328934802647521058074423029331715842588747884628503335602097446086129137185858493783360205996288931332575330487684732762723920060950824627113236740889361063689432525684691608413961714708484603930068102498616953563079759899489668320564905984834250623121044477787499553785807771880132656218415229951757841844522788582416132831110017938395056281983827538539984440974303820421132029043213937560957163883619108814949300849473790410199484995795810153452619333190501821092652603494298744309977150193076848081555863288337890717577062435572863512525382617580531560241

m = pow(c,d,n)
print(n2s(m))
#easyctf{ilnirawvhfpey2nrxx}

crypto

题目:

import random
rand = random.randint(1, 10)
flag = 'flag{******************************}'
k = []
for i in range(len(flag)):
    k.append(ord(flag[i]) & 15 ^ rand)
    k.append(ord(flag[i]) & 240)

print k
#k = [4, 96, 14, 96, 3, 96, 5, 96, 9, 112, 4, 48, 7, 48, 3, 48, 0, 48, 0, 96, 6, 96, 6, 48, 1, 48, 6, 96, 11, 48, 1, 96, 3, 96, 3, 96, 4, 48, 7, 96, 2, 48, 0, 48, 1, 96, 11, 48, 11, 48, 2, 48, 0, 96, 2, 48, 3, 96, 10, 48, 0, 48, 4, 48, 7, 48, 0, 48, 6, 96, 1, 96, 3, 96, 15, 112]

题目原理不难,通过加密的方式逆过去解密,根据题目的脚本逆向过去写解密脚本

rand = 2
flag = ''
k = [4, 96, 14, 96, 3, 96, 5, 96, 9, 112, 4, 48, 7, 48, 3, 48, 0, 48, 0, 96, 6, 96, 6, 48, 1, 48, 6, 96, 11, 48, 1, 96,
     3, 96, 3, 96, 4, 48, 7, 96, 2, 48, 0, 48, 1, 96, 11, 48, 11, 48, 2, 48, 0, 96, 2, 48, 3, 96, 10, 48, 0, 48, 4, 48,
     7, 48, 0, 48, 6, 96, 1, 96, 3, 96, 15, 112]
for i in range(0, len(k), 2):
    for j in range(0,128):
        if ((k[i] ^ rand) == (j & 15)) and (k[i+1] == (j & 240)):
            flag += chr(j)

print(flag)
#flag{6512bd43d9caa6e02c990b0a82652dca}

总结

总体来说题目并不是很难(比赛的时间不是特别长),这次比赛拿到了两个一血,非常开心!继续加油吧,希望有一天能够成为密码学大佬

luoluo

我爱吃螺蛳粉

文章评论