Network and information security special competition writeup

crypto sm4:

The title hints that this is a sm4 encrypted topic, given the key and ciphertext, so I found an sm4 encrypted code on the Internet ( https://blog.csdn.net/songdawww/article/details/79112548 ), a little Modify it to get the correct answer (decrypt the ecb of the main function of the source code and leave it, and put the key and ciphertext)

key_data = [13, 204, 99, 177, 254, 41, 198, 163, 201, 226, 56, 214, 192, 194, 98, 104]
    iv_data = [0x5a]*16
en_data=[46, 48, 220, 156, 184, 218, 57, 13, 246, 91, 1, 63, 60, 67, 105, 64, 149, 240, 217, 77, 107, 49, 222, 61, 155, 225, 231, 196, 167, 121, 9, 16, 60, 182, 65, 101, 39, 253, 250, 224, 9, 204, 154, 122, 206, 43, 97, 59]
sm4_d.sm4_set_key(key_data, DECRYPT)
de_data = sm4_d.sm4_crypt_ecb(en_data)
de_data_str = "".join([chr(x) for x in de_data])
print de_data_str

crypto dp:

In the title we can get e, n, dp, c, where dp = e ^ (-1) mod (p-1). So we have m ^ (e * dp) mod p = m, that is, m ^ (e * dp) = k * p + m, so we have (m ^ (e * dp)) mod n = (k * p + m) mod n = k * p + m, then we have gcd (((m ^ (e * dp)) mod n) -m, n) = gcd (k * p, n) = p, which is normal Factor n

code show as below

import binascii
import gmpy2
e=65537
n=9637571466652899741848142654451413405801976834328667418509217149503238513830870985353918314633160277580591819016181785300521866901536670666234046521697590230079161867282389124998093526637796571100147052430445089605759722456767679930869250538932528092292071024877213105462554819256136145385237821098127348787416199401770954567019811050508888349297579329222552491826770225583983899834347983888473219771888063393354348613119521862989609112706536794212028369088219375364362615622092005578099889045473175051574207130932430162265994221914833343534531743589037146933738549770365029230545884239551015472122598634133661853901
dp=81339405704902517676022188908547543689627829453799865550091494842725439570571310071337729038516525539158092247771184675844795891671744082925462138427070614848951224652874430072917346702280925974595608822751382808802457160317381440319175601623719969138918927272712366710634393379149593082774688540571485214097
c=5971372776574706905158546698157178098706187597204981662036310534369575915776950962893790809274833462545672702278129839887482283641996814437707885716134279091994238891294614019371247451378504745748882207694219990495603397913371579808848136183106703158532870472345648247817132700604598385677497138485776569096958910782582696229046024695529762572289705021673895852985396416704278321332667281973074372362761992335826576550161390158761314769544548809326036026461123102509831887999493584436939086255411387879202594399181211724444617225689922628790388129032022982596393215038044861544602046137258904612792518629229736324827

# Random R
r = 2
# n = pq
p = gmpy2.gcd(n, pow(r, (e*dp), n) - r)
q = gmpy2.div(n, p)
print("p: %d" % p)
print("q: %d" % q)
# calculate d
phi = (p-1) * (q-1)
d = gmpy2.invert(e, phi)
print("phi: %d" % phi)
print("d: %d" % d)
# Calculate message
m = int(pow(c, d, n))
print("m: %d" % m)
# Convert int message to string
mHex = format(m, 'x')
print(mHex)
message = binascii.unhexlify(mHex).decode("utf-8")
print(message)

re src_leak:

We look at the source code and find that we need to comply with func3 <func2 <x1> is 1 and _func1 <x1> :: result is the value in the output in the file. We will find that when _func1 <i> :: result is 1, i = 1, 2, 3, and when _func1 <i> :: result is 2, i = 4, 5, 6, 7, 8. At this time, we will find that when _func1 <i> :: result is k, i has 2k + 1, and the order is from 1 to back. So we can calculate the range of i with _func1 <i> :: result k

sum=0;
for i in xrange(1,963):
    sum=sum+(2*i+1)

print sum

We substitute numbers in this range into func3 <func2 <x1> and find the minimum value where the final result is 1 is part of the flag

Next we need to know how many fun4 <i> :: value == 1 in 0 <i <10000. We found that when i is a prime number, fun4 <i> :: value == 1. At this time, we only need to find how many prime numbers in 0 <i <10000.

re flat

The title prompts uuid, so we enter flag {uuid} to go to uuid's inspection and gradually execute the uuid inspection program. We found that the following changes have been made in the program, and he changed the original "0123456789" number in the original uuid to " ABCDEFGHIJ ", convert the letters abcdef to the number" 123456 ", and then we can observe the stack during execution. We will find the ciphertext obtained by our uuid encryption and the final ciphertext to be checked, so we only need to decrypt the ciphertext To get the answer

dict1={"A":"0","B":"1","C":"2","D":"3","E":"4","F":"5","G":"6","H":"7","I":"8","J":"9","1":"a","2":"b","3":"c","4":"d","5":"e","6":"f"}
cipher="J2261C63-3I2I-EGE4-IBCC-IE41A5I5F4HB"
message=""
for i in cipher:
    if dict1.has_key(i):
        message=message+dict1[i]
    else:
        message=message+i

print message

 

Published 43 original articles · Like 23 · Visits 30,000+

Guess you like

Origin blog.csdn.net/zhang14916/article/details/99713802