text = list("killshadow") key = list("ADSFKNDCLS") ans = "" v5 = len(key) v3 = 0 for i inrange(v5): if key[v3%v5]>'@'and key[v3%v5]<='Z': key[i] = chr(ord(key[v3%v5]) + 32) v3 += 1 print(key[i],end="") print() for i inrange(v5): for j inrange(32,128): if (j>64and j<91) or (j>96and j<123): if (j-39-ord(key[v3%v5])+97)%26+97 == ord(text[i]): v3 += 1 ans += chr(j) break print(ans) ''' adsfkndcls KLDQCUDFZO '''
1
flag{KLDQCUDFZO}
2. luck_guy
无壳,64位ELF,载入IDA分析一下。随着main函数进入关键函数。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# 将f2串加上0x,再放入列表 tmp_list = [] index = 0 while index < 15: tmp = eval('0x' + f2[index:index+2]) tmp_list.append(tmp) index += 2
for i inrange(len(tmp_list)): if i % 2 == 1: tmp_list[i] = tmp_list[i] - 2 else: tmp_list[i] = tmp_list[i] - 1 ans += chr(tmp_list[i]) print(ans) ''' GXY{do_not_hate_me} '''
#include<stdio.h> intsub_4010F0(char * a1, int a2, int a3) { int result; // eax int i; // esi int v5; // ecx int v6; // edx
result = a3; for (i = a2; i <= a3; a2 = i) { v5 = i; v6 = a1[i]; if (a2 < result && i < result) { do { if (v6 > a1[result]) { if (i >= result) break; ++i; a1[v5] = a1[result]; if (i >= result) break; while (a1[i] <= v6) { if (++i >= result) goto LABEL_13; } if (i >= result) break; v5 = i; a1[result] = a1[i]; } --result; } while (i < result); } LABEL_13: a1[result] = v6; sub_4010F0(a1, a2, i - 1); result = a3; ++i; } return result; }
#!/usr/bin/env python # visit https://tool.lu/pyc/ for more information print'Welcome to Re World!' print'Your input1 is your flag~' l = len(input1) for i inrange(l): num = ((input1[i] + i) % 128 + 128) % 128 code += num
for i inrange(l - 1): code[i] = code[i] ^ code[i + 1]
┌──(v5le0n9㉿kali)-[~/RsaCtfTool] └─$ python3 RsaCtfTool.py --publickey pub.key --uncipherfile flag.enc 1 ⨯ private argument is not set, the private key will not be displayed, even if recovered.
[*] Testing key pub.key. [*] Performing system_primes_gcd attack on pub.key. 100%|███████████████████████████████| 7007/7007 [00:00<00:00, 1370394.86it/s] [*] Performing fibonacci_gcd attack on pub.key. 100%|████████████████████████████████| 9999/9999 [00:00<00:00, 302473.41it/s] [*] Performing pastctfprimes attack on pub.key. 100%|█████████████████████████████████| 113/113 [00:00<00:00, 2246238.64it/s] [*] Performing smallq attack on pub.key. [*] Performing factordb attack on pub.key. [*] Attack success with factordb method !
Results for pub.key:
Unciphered data : HEX : 0x00029d207b7a521e08e4e6180600666c61677b646563727970745f3235367d0a INT (big endian) : 4618144028027957675862906963888332345633248954043303780331531906089123082 INT (little endian) : 4744358497414744401850218354568232353073084770228403473305939615805528146432 utf-16 : Ȁ穻Ṓᣦ汦条摻捥祲瑰㉟㘵 STR : b'\x00\x02\x9d {zR\x1e\x08\xe4\xe6\x18\x06\x00flag{decrypt_256}\n'
rtf = [0x7b,0x5c,0x72,0x74,0x66,0x31] res = [0x05,0x7d,0x41,0x15,0x26,0x01] ans = "" for i inrange(len(rtf)): ans += chr(rtf[i] ^ res[i]) print(ans) ''' ~!3a@0 '''
import base64 flag = list("Iodl>Qnb(ocy") flag.append(127) flag.extend("y.i") flag.append(127) flag.extend("d`3w}wek9{iy=~yL@EC") v18 = flag for i inrange(len(flag)): ifisinstance(flag[i],int): v18[i] = chr(flag[i] ^ i) else: v18[i] = chr(ord(flag[i]) ^ i) print(v18[i],end="") print() v18.append('0') v18.append('0') v18.append('0') str=''.join(v18) print(str) bs = base64.b64encode(str.encode("utf-8")) for i inrange(9): bs = base64.b64encode(bs) print(bs) ''' Info:The first four chars are `flag` Info:The first four chars are `flag`000 b'Vm0wd2QyVkZOVWRXV0doVVYwZDRWRmx0ZEhkVU1WcDBUVmM1VjFadGVIbFhhMk0xVmpGYWRHVkdiR0ZXVjJoeVdWZDRZV014WkhGUmJVWlhWakZLU1ZkV1dsWmxSbGw0V2toV2FGSnNjSEJXTUdSdlpWWmtWMWR0ZEZSTlZ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ZKaFZqSktWVkZZYUZkV1JWcFlWV3BHYTFkWFRrZFRiV3hvVFVoQ1dsWXhaRFJpTWtsM1RVaG9hbEpYYUhOVmJUVkRZekZhY1ZKcmRGTk5Wa3A2VjJ0U1ExWlhTbFpqUldoYVRVWndkbFpxUmtwbGJVWklZVVprYUdFeGNHOVhXSEJIWkRGS2RGSnJhR2hTYXpWdlZGVm9RMlJzV25STldHUlZUVlpXTlZadE5VOVdiVXBJVld4c1dtSllUWGhXTUZwell6RmFkRkpzVWxOaVNFSktWa1phVTFFeFduUlRhMlJxVWxad1YxWnRlRXRXTVZaSFVsUnNVVlZVTURrPQ==' for i inrange(10): bs = str(base64.b64decode(bs), "utf-8") print(bs) ''' https://bbs.pediy.com/thread-254172.htm '''
v1 = list("flag") b6cc = [0x40,0x35,0x20,0x56,0x5d,0x18,0x22,0x45,0x17,0x2f,0x24,0x6e,0x62,0x3c,0x27,0x54,0x48,0x6c,0x24,0x6e,0x72,0x3c,0x32,0x45,0x5b] ans = "" for i inrange(4): v1[i] = ord(v1[i]) ^ b6cc[i] for i inrange(len(b6cc)): ans += chr(b6cc[i] ^ v1[i%4]) print(ans) ''' flag{Act1ve_Defen5e_Test} '''
9. [GUET-CTF2019]re
ELF文件,有UPX壳。ELF脱UPX壳在Linux下执行脱壳命令与Windows一致。
1 2 3 4 5 6 7 8 9 10
v5le0n9@ubuntu:~/Desktop$ upx -d re Ultimate Packer for eXecutables Copyright (C) 1996 - 2013 UPX 3.91 Markus Oberhumer, Laszlo Molnar & John Reiser Sep 30th 2013
File size Ratio Format Name -------------------- ------ ----------- ----------- 841042 <- 304524 36.21% linux/ElfAMD re
ans = "" ans += chr(166163712//1629056) ans += chr(731332800//6771600) ans += chr(357245568//3682944) ans += chr(1074393000//10431000) ans += chr(489211344//3977328) ans += chr(518971936//5138336) ans += " " ans += chr(406741500//7532250) ans += chr(294236496//5551632) ans += chr(177305856//3409728) ans += chr(650683500//13013670) ans += chr(298351053//6088797) ans += chr(386348487//7884663) ans += chr(438258597//8944053) ans += chr(249527520//5198490) ans += chr(445362764//4544518) ans += chr(981182160//10115280) ans += chr(174988800//3645600) ans += chr(493042704//9667504) ans += chr(257493600//5364450) ans += chr(767478780//13464540) ans += chr(312840624//5488432) ans += chr(1404511500//14479500) ans += chr(316139670//6451830) ans += chr(619005024//6252576) ans += chr(372641472//7763364) ans += chr(373693320//7327320) ans += chr(498266640//8741520) ans += chr(452465676//8871876) ans += chr(208422720//4086720) ans += chr(515592000//9374400) ans += chr(719890500//5759124) print(ans) ''' flag{e 65421110ba03099a1c039337} '''
n = v4 = 103461035900816914121390101299049044413950405173712170434161686539878160984549 e = v5 = 65537 c = v7 = 0xad939ff59f6e70bcbfad406f2494993757eee98b91bc244184a377520d06fc35
p = 282164587459512124844245113950593348271 q = 366669102002966856876605669837014229419
然后用RSA解密脚本直接得出私钥d,进而得到明文m。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
import gmpy2 n = 103461035900816914121390101299049044413950405173712170434161686539878160984549 p = 282164587459512124844245113950593348271 q = 366669102002966856876605669837014229419 e = 65537
d = gmpy2.invert(e,(p-1)*(q-1)) print ("d = " + str(d)) #d为私钥 c = 0xad939ff59f6e70bcbfad406f2494993757eee98b91bc244184a377520d06fc35 m = gmpy2.powmod(c,d,n) print("m = " + str(m)) ''' d = 91646299298871237857836940212608056141193465208586711901499120163393577626813 m = 185534734614696481020381637136165435809958101675798337848243069 '''
flag = [0x67,0x79,0x7b,0x7f,0x75,0x2b,0x3c,0x52,0x53,0x79,0x57,0x5e,0x5d,0x42,0x7b,0x2d,0x2a,0x66,0x42,0x7e,0x4c,0x57,0x79,0x41,0x6b,0x7e,0x65,0x3c,0x5c,0x45,0x6f,0x62,0x4d] qiao = [9,0xa,0xf,0x17,7,0x18,0x0c,6,1,0x10,3,0x11,0x20,0x1d,0x0b,0x1e,0x1b,0x16,4,0x0d,0x13,0x14,0x15,2,0x19,5,0x1f,8,0x12,0x1a,0x1c,0x0e,0] ans = [0for x inrange(0,33)] #定义列表长度并初始化为0 st = [0for x inrange(0,33)] for i inrange(len(flag)): ans[i] = flag[i] ^ qiao[i] print(chr(ans[i]),end="") print() for i inrange(len(ans)): # qiao的元素是st的下标,其实就是IDA那一行换过来赋值,我可能是困了在这里绕了好久!! st[qiao[i]] = ans[i] for i inrange(len(st)): print(chr(st[i]),end="") print() ''' nsthr30TRiTO}_p31pFs_ClCr{z4N_slM MRCTF{Tr4nsp0sltiON_Clph3r_1s_3z} '''
result = "TOiZiZtOrYaToUwPnToBsOaOapsyS" flag = '' f418 = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm"
# 下标为双数进行操作 for i inrange(len(result)): if i % 2 == 1: flag += result[i] continue # 如果是大写字母,一定是小写字母转换来的 if(result[i].isupper()): flag += chr(f418.find(result[i]) + 96) else: flag += chr(f418.find(result[i]) + 38) print (flag) ''' dOGZGZDOCYJTHUAPXTHBKOJOJpKyk '''
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
result = "TOiZiZtOrYaToUwPnToBsOaOapsyS" flag = '' f418 = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm"
# 下标为单数进行操作 for i inrange(len(result)): if i % 2 == 0: flag += result[i] continue if(result[i].isupper()): flag += chr(f418.find(result[i]) + 96) else: flag += chr(f418.find(result[i]) + 38) print (flag) ''' ThisisthreadofwindowshahaIsES '''
flag = list('MSAWB~FXZ:J:`tQJ"N@ bpdd}8g') ans = '' for i inrange(len(flag)): ans += chr(ord(flag[i]) ^ i) print(ans) ''' MRCTF{@_R3@1ly_E2_R3verse!} '''
b201 = [0x42,9,0x4a,0x49,0x35,0x43,0x0a,0x41,0xf0,0x19,0xe6,0x0b,0xf5,0xf2,0x0e,0x0b,0x2b,0x28,0x35,0x4a,6,0x3a,0x0a,0x4f] flag = list("********CENSORED********") ans = '' for i inrange(len(flag)): ans += chr(b201[i] + ord(flag[i])) print(ans) ''' l3ts_m4kij^Ĵ^ńńSOUR_t0d4y '''
# 把数据换成二进制数据然后再用十六进制字符串表示 b = binascii.b2a_hex(data.encode()) #bin to ascii hex print(b) #结果: #b'636f6e73756d6572' #十六进制字符格式换成原数据 print(binascii.a2b_hex(b)) #ascii hex to bin #结果: #b'consumer'
for i inrange(len(key)): p = enc[i * 8:(i + 1) * 8][::-1] # 因为key是小端存储,所以enc要逆序过来进行运算 a = binascii.b2a_hex(p.encode('ascii')) # 将字符串转换成二进制形式再用十六进制字符串表示 b = binascii.a2b_hex(hex(int(a, 16) + key[i])[2:])[::-1] # 将a转换成十进制与key相加后再转换成十六进制形式,去掉前缀0x,转换成字节数据,再逆序输出 flag += b print(flag.decode()) ''' l3ts_m4k3_4_DETOUR_t0d4y '''