Jun 15 02:30:15 server sshd[5678]: Accepted password for attacker from 192.168.42.77 port 1337
SSH 用户名: attacker
攻击者 IP: 192.168.42.77
在syslog中发现:
Jun 15 02:35:15 server systemd[1]: Started hidden_backdoor.service Jun 15 02:35:15 server hidden_backdoor: listening on [any] 31337 ...
恶意服务名称: hidden_backdoor(不包括 .service 后缀)
在dnsmasq.log中发现:
Jun 15 02:40:15 dnsmasq[123]: query[A] CiAgICByb290Oio6MTk0Nzk6MDo5OTk5OTo3Ojo6.data.leak.ev from 192.168.42.77 Jun 15 02:40:17 dnsmasq[123]: query[A] CmRhZW1vbjoqOjE5NDc5OjA6OTk5OTk6Nzo6Ogph.data.leak.ev from 192.168.42.77 Jun 15 02:40:19 dnsmasq[123]: query[A] dHRhY2tlcjokNiRzZWNyZXQkZW5jcnlwdGVkcGFz.data.leak.ev from 192.168.42.77 Jun 15 02:40:21 dnsmasq[123]: query[A] c3dvcmQ6MTk0Nzk6MDo5OTk5OTo3Ojo6CiAgICA.data.leak.ev from 192.168.42.77
C:UsersSimplicityDesktop>fastcoll_v1.0.0.5.exe MD5 collision generator v1.5 by Marc Stevens (http://www.win./hashclash/) Allowed options: -h [ --help ] Show options. -q [ --quiet ] Be less verbose. -i [ --ihv ] arg Use specified initial value. Default is MD5 initial value. -p [ --prefixfile ] arg Calculate initial value using given prefixfile. Also copies data to output files. -o [ --out ] arg Set output filenames. This must be the last option and exactly 2 filenames must be specified. Default: -o msg1.bin msg2.bin
import gmpy2 from Crypto.Util.number import * n = e = ciphertext = [] param1 = phi = n + 1 - param1 d = gmpy2.invert(e, phi) m = pow(ciphertext[0], d, n) print(long_to_bytes(m))
逆向分析
encodefile
image-20250621135512738
连续3年出的RC4题目,拖入IDA分析,没有main函数。
考虑从字符串下手:
image-20250621135608643
根据flag.txt定位到关键代码:
image-20250621135653562
找到key和两个文件名,逻辑显示是通过key加密flag.txt数据后存储到enc.dat。
我们直接追踪key的数据流即可,发现有两个函数用到key。
第一个函数很明显,两轮255次循环,打乱密钥盒,可以识别出是RC4算法:
image-20250621135810805
尝试使用RC4模板对密文进行解密:
defrc4_decrypt(key, ciphertext): ''' RC4 解密函数 :param key: 密钥(bytes) :param ciphertext: 密文(bytes) :return: 解密后的明文(bytes) ''' # RC4 密钥调度算法(KSA) S = list(range(256)) j = 0 for i in range(256): j = (j + S[i] + key[i % len(key)]) % 256 S[i], S[j] = S[j], S[i] # 伪随机生成算法(PRGA)解密 i = j = 0 plaintext = [] for byte in ciphertext: i = (i + 1) % 256 j = (j + S[i]) % 256 S[i], S[j] = S[j], S[i] k = S[(S[i] + S[j]) % 256] plaintext.append(byte ^ k) return bytes(plaintext) with open('enc.dat', 'rb') as f: ciphertext = f.read() key = b'key2025lqb' plaintext = rc4_decrypt(key, ciphertext) print('Decrypted Data (Hex):', plaintext.hex()) try: print('Decrypted Text:', plaintext.decode('utf-8')) except UnicodeDecodeError: print('Decrypted Data is not UTF-8 text.')
可以直接得到Flag,那就不需要继续后续分析了。
rand_pyc
断网环境出这种题目就比较离谱,如果你python版本太低或者太高就做不了。
这个题目需要使用python3.8或者相近的版本,否则会报错无法反编译。
先使用pyinstxtractor将exe反编译为pyc文件:
python pyinstxtractor.py ../rand_pyc_obf.exe [+] Processing ../rand_pyc_obf.exe [+] Pyinstaller version: 2.1+ [+] Python version: 3.8 [+] Length of package: 5579332 bytes [+] Found 58 files in CArchive [+] Beginning extraction...please standby [+] Possible entry point: pyiboot01_bootstrap.pyc [+] Possible entry point: rand_pyc_obf.pyc [+] Found 74 files in PYZ archive [+] Successfully extracted pyinstaller archive: ../rand_pyc_obf.exe You can now use a python decompiler on the pyc files within the extracted directory
然后使用uncompyle6将pyc反编译为py源代码:
uncompyle6 rand_pyc_obf.pyc > decompiled.py
# uncompyle6 version 3.9.2 # Python bytecode version base 3.8.0 (3413) # Decompiled from: Python 3.8.9 (tags/v3.8.9:a743f81, Apr 6 2021, 14:02:34) [MSC v.1928 64 bit (AMD64)] # Embedded file name: rand_pyc_obf.py import sys, random, base64 Ii = input('Please input the flag: ').strip() ifnot (Ii.startswith('flag{') and Ii.endswith('}') and len(Ii) == 42): print('Length incorrect') sys.exit(-999) oo0O000ooO = base64.b64encode(Ii.encode()).decode() + '_easyctf' ii = [] for iiI in oo0O000ooO: random.seed(ord(iiI)) ii.append(random.randint(1000000, 9999999)) else: iii111 = [ 4417023, 5690625, 9639225, 1327718, 4417023, 5085550, 5752075, 9556690, 5240080, 6431679, 3428007, 3189766, 3438336, 5757818, 3189766, 5690625, 4148389, 2254831, 6292433, 2122126, 5240080, 6431679, 9488271, 2464675, 7216908, 5757818, 3189766, 5690625, 3438336, 6431679, 2360475, 6002055, 5240080, 9040261, 8655414, 9347278, 3438336, 2254831, 2122126, 5135281, 2360475, 9347278, 4417023, 1327718, 3438336, 3448715, 9488271, 5501611, 5240080, 5757818, 9488271, 5501611, 5240080, 9347278, 4148389, 1714134, 9923116, 4267438, 4263793, 5752075, 2464675, 7777627, 6002055, 3485900] Iio0 = [] for iiI in oo0O000ooO: random.seed(ord(iiI)) Iio0.append(random.randint(1000000, 9999999)) else: if Iio0 != iii111: print('Wrong flag') sys.exit(-1) print('Correct!') # okay decompiling rand_pyc_obf.pyc