import libnum from Crypto.Util.number import long_to_bytes
q = 304008741604601924494328155975272418463 p = 285960468890451637935629440372639283459 e = 65537 n = 86934482296048119190666062003494800588905656017203025617216654058378322103517
# invmod(a, n) - 求a对于n的模逆,这里逆向加密过程中计算ψ(n)=(p-1)(q-1),对ψ(n)保密,也就是对应根据e*d=1 mod ψ(n),求出d d = libnum.invmod(e, (p - 1) * (q - 1))
e = 65537 n = 86934482296048119190666062003494800588905656017203025617216654058378322103517 p = 285960468890451637935629440372639283459 q = 304008741604601924494328155975272418463
phin = (q - 1) * (p - 1)
d = gmpy2.invert(e, phin)
key = rsa.PrivateKey(n, e, int(d), p, q)
# 读取密文 withopen("./flag.txt", "rb") as f: ciphertext = f.read()
import libnum from Crypto.Util.number import long_to_bytes
q = 282164587459512124844245113950593348271 p = 366669102002966856876605669837014229419 e = 65537 c = 0xad939ff59f6e70bcbfad406f2494993757eee98b91bc244184a377520d06fc35 n = 103461035900816914121390101299049044413950405173712170434161686539878160984549
# invmod(a, n) - 求a对于n的模逆,这里逆向加密过程中计算ψ(n)=(p-1)(q-1),对ψ(n)保密,也就是对应根据e*d=1 mod ψ(n),求出d d = libnum.invmod(e, (p - 1) * (q - 1)) m = pow(c, d, n) string = long_to_bytes(m) # 获取m明文,要转成字符串 # print(ex(m)[2:].decode('hex')) print(string)
[WUSTCTF2020]level1
给了个output文件
直接逆
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# 初始化列表 numbers = []
# 打开文件并读取数据 withopen('output.txt', 'r') as file: for line in file: # 将每行的数字转换为整数并添加到列表 numbers.append(int(line.strip()))
for i inrange(1, len(numbers) + 1): if (i & 1) != 0: print(chr(numbers[i - 1] >> i), end='') else: print(chr(numbers[i - 1] // i), end='')
flag = '' flag += chr(166163712 // 1629056) flag += chr(731332800 // 6771600) flag += chr(357245568 // 3682944) flag += chr(1074393000 // 10431000) flag += chr(489211344 // 3977328) flag += chr(518971936 // 5138336) flag += '?' flag += chr(406741500 // 7532250) flag += chr(294236496 // 5551632) flag += chr(177305856 // 3409728) flag += chr(650683500 // 13013670) flag += chr(298351053 // 6088797) flag += chr(386348487 // 7884663) flag += chr(438258597 // 8944053) flag += chr(249527520 // 5198490) flag += chr(445362764 // 4544518) flag += chr(981182160 // 10115280) flag += chr(174988800 // 3645600) flag += chr(493042704 // 9667504) flag += chr(257493600 // 5364450) flag += chr(767478780 // 13464540) flag += chr(312840624 // 5488432) flag += chr(1404511500 // 14479500) flag += chr(316139670 // 6451830) flag += chr(619005024 // 6252576) flag += chr(372641472 // 7763364) flag += chr(373693320 // 7327320) flag += chr(498266640 // 8741520) flag += chr(452465676 // 8871876) flag += chr(208422720 // 4086720) flag += chr(515592000 // 9374400) flag += chr(719890500 // 5759124) print(flag)
memset(Destination, 0, sizeof(Destination)); memset(String1, 0, sizeof(String1)); v7 = 0; printf("pls input the first passwd(1): "); scanf("%s", Destination); if ( strlen(Destination) != 6 ) { printf("Must be 6 characters!\n"); ExitProcess(0); } v7 = atoi(Destination); if ( v7 < 100000 ) ExitProcess(0); strcat(Destination, "@DBApp"); v3 = strlen(Destination); sub_40100A((BYTE *)Destination, v3, String1); if ( !_strcmpi(String1, "6E32D0943418C2C33385BC35A1470250DD8923A9") ) { printf("continue...\n\n"); printf("pls input the first passwd(2): "); memset(Str, 0, sizeof(Str)); scanf("%s", Str); if ( strlen(Str) != 6 ) { printf("Must be 6 characters!\n"); ExitProcess(0); } strcat(Str, Destination); memset(String1, 0, sizeof(String1)); v4 = strlen(Str); sub_401019((BYTE *)Str, v4, String1); if ( !_strcmpi("27019e688a4e62a649fd99cadaafdb4e", String1) ) { if ( !(unsigned __int8)sub_40100F(Str) ) { printf("Error!!\n"); ExitProcess(0); } printf("bye ~~\n"); } } return0; }
sub_401019函数实现了对输入数据 pbData 进行 SHA-1 哈希计算,并将计算结果转换为一个十六进制字符串,存储在 lpString1 中。函数内部通过调用 Windows CryptoAPI 来完成加密和哈希操作。
1 2 3 4 5 6 7 8 9 10 11 12
import hashlib import string
last = '@DBApp'
for i inrange(100000,1000000): enc = str(i) + last a = hashlib.sha1(enc.encode("utf-8")).hexdigest() if a.upper() == "6E32D0943418C2C33385BC35A1470250DD8923A9": print(i) break
123321@DBApp
下面那个是MD5
万一MD5查不到怎么办思考下,
1 2 3 4 5 6 7 8 9 10 11 12 13
last = "123321@DBApp"
for i in string.printable: for j in string.printable: for k in string.printable: for c in string.printable: for d in string.printable: for e in string.printable: enc = i + j + k + c + d + e + last a = hashlib.md5(enc.encode("utf")).hexdigest() if a == "27019e688a4e62a649fd99cadaafdb4e": print(enc) break
for i inrange(len(enc)): if enc[i] >= 'a'and enc[i] <= 'z': print(chr(ord(enc[i]) - 32),end='') elif enc[i] >= 'A'and enc[i] <= 'Z': print(chr(ord(enc[i]) + 32),end='') else: print(enc[i],end='')
print() key = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' key_ord = [ord(i) for i in key] for i inrange(6,15): key_ord[i],key_ord[i + 10]=key_ord[i + 10],key_ord[i]
for i in key_ord: print(chr(i),end='')
flag{bAse64_h2s_a_Surprise}
[MRCTF2020]Xor
无法反编译,但是可以看出是xor的逻辑,跟踪到这个
MSAWB~FXZ:J:`tQJ”N@ bpdd}8g
1 2 3 4
enc = 'MSAWB~FXZ:J:`tQJ"N@ bpdd}8g'
for i inrange(len(enc)): print(chr(ord(enc[i]) ^ i), end='')
这样也行
[SUCTF2019]SignIn
看着就像rsa算法,后面的10和16应该是进制
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
import libnum from Crypto.Util.number import long_to_bytes
q = 282164587459512124844245113950593348271 p = 366669102002966856876605669837014229419 e = 65537 c = 0xad939ff59f6e70bcbfad406f2494993757eee98b91bc244184a377520d06fc35 n = 103461035900816914121390101299049044413950405173712170434161686539878160984549
# invmod(a, n) - 求a对于n的模逆,这里逆向加密过程中计算ψ(n)=(p-1)(q-1),对ψ(n)保密,也就是对应根据e*d=1 mod ψ(n),求出d d = libnum.invmod(e, (p - 1) * (q - 1)) m = pow(c, d, n) string = long_to_bytes(m) # 获取m明文,要转成字符串 # print(ex(m)[2:].decode('hex')) print(string)