主要还是以题来讲解,主打一个做笔记。
SICTF 2023 round3 一起上号不 主要利用工具: 1.Wireshark 2.github脚本 (1)CS_Decrypt-main (ps)其中Beacon_metadata_RSA_Decrypt.py环境不好配置,导致得到key困难。 (2)cs-scripts-master 3.为解决环境配置问题使用另一项脚本test.py(在文章下写出)
首先得到流量包分析得到key 使用cs-scripts-master将RSA密钥导出 再从流量包中的load中把cookie导出 把上面两个在Beacon_metadata_RSA_Decrypt.py解密得到AES key和HMCA key (M2Crypto的环境配置不好因此无法解决) 修改解密脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 import base64 import hexdump import hashlib import argparse import javaobj.v2 as javaobj from Crypto.PublicKey import RSA from Crypto.Cipher import PKCS1_v1_5 def parse_arguments(): parser = argparse.ArgumentParser() parser.add_argument("-f" , type =str, default=None, required=True, help ="输入JAVA序列化文件 .cobaltstrike.beacon_keys 路径" ) return parser.parse_args() def get_RSA_PriKey(SerializeKeyPath): with open(SerializeKeyPath, "rb" ) as fd: pobj = javaobj.load(fd) privateKey = pobj.array.value.privateKey.encoded.data publicKey = pobj.array.value.publicKey.encoded.data privateKey = ( b"-----BEGIN PRIVATE KEY-----\n" + base64.encodebytes(bytes(map(lambda x: x & 0xFF, privateKey))) + b"-----END PRIVATE KEY-----" ) publicKey = ( b"-----BEGIN PUBLIC KEY-----\n" + base64.encodebytes(bytes(map(lambda x: x & 0xFF, publicKey))) + b"-----END PUBLIC KEY-----" ) privateKey = privateKey.decode() publicKey = publicKey.decode() return publicKey, privateKey def create_PK_Cipher(privateKey): privateKey = RSA.import_key(privateKey.encode()) n_bytes = privateKey.n.bit_length() // 8 cipher = PKCS1_v1_5.new(privateKey) return cipher, n_bytes def private_decrypt(cipher_text, privateKey): cipher, n_bytes = create_PK_Cipher(privateKey) cipher_text = base64.b64decode(cipher_text.encode()) return b'' .join ( cipher.decrypt(cipher_text[i: i + n_bytes], 0) for i in range(0, len(cipher_text), n_bytes) ) def get_AES_HMAC_Key(SerializeKeyPath, rsa_cipher_text): _, privateKey = get_RSA_PriKey(SerializeKeyPath) if not (plain_text := private_decrypt(rsa_cipher_text, privateKey)): print ("[+]: 解密错误, 可能是RSA_Cipher_Text或者密钥有误!" ) exit (-1) raw_aes_keys = plain_text[8:24] raw_aes_hash256 = hashlib.sha256(raw_aes_keys) digest = raw_aes_hash256.digest() aes_key = digest[:16] hmac_key = digest[16:] return aes_key, hmac_key, plain_text if __name__ == '__main__' : args = parse_arguments() SerializeKeyPath = args.f rsa_cipher_text = "U8jm3+oqzYLuUiRd9F3s7xVz7fGnHQYIKF9ch6GRseWfcBSSk+aGhWP3ZUyHIkwRo1/oDCcKV7LYAp022rCm9bC7niOgMlsvgLRolMKIz+Eq5hCyQ0QVScH8jDYsJsCyVw1iaTf5a7gHixIDrSbTp/GiPQIwcTNZBXIJrll540s=" aes_key, hmac_key, plain_text = get_AES_HMAC_Key(SerializeKeyPath, rsa_cipher_text) print (f"AES key: {aes_key.hex()}" ) print (f"HMAC key: {hmac_key.hex()}" ) hexdump.hexdump(plain_text)
1 使用方法: python test.py -f .cobaltstrike.beacon_keys
得到结果 使用得到的key在Beacon_Task_AES_Decrypt.py将load中的data数据解密得到发送的数据 注意:data需要用cyberchef加工一下(From Hex和To Base64) 最后解出flag
wifi流量包解密 用于wifi的流量包一般为file.cap wifi连接认证的重点在于WAP的四次握手过程,就是EAPOL协议的包, 在wireshark过滤栏中输入eapol查看是否存在四次握手 对密码进行爆破 如果已知密码位数,即可构造字典 kali内命令
1 crunch 11 11 -t 1391040%%%% >>file.txt
使用工具aircrack-ng 在bin文件目录下,字典文件及wifi流量包文件都在的情况下 使用命令
1 aircrack-ng -w file.txt file.cap
使用模式3即可爆破。
鼠标流量分析 鼠标流量包内,一般会有该鼠标的型号和名字,或者找mouse也可以,一般为USB类型的流量,随机挑选一组流量进行分析,会发现最下方有一组十六进制数据,例如00002000,这里可以理解成0x00002000,这里将所有数据提取出来
使用tshark命令提取
1 2 tshark -r usb2.pcap -T fields -e usb.capdata | sed '/^\s*$/d' > usbdata.txt
再用python脚本对原始数据进行加工
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 f=open ('usbdata.txt' ,'r' ) fi=open ('out.txt' ,'w' ) while 1 : a=f.readline().strip() if a: if len (a)==8 : out='' for i in range (0 ,len (a),2 ): if i+2 != len (a): out+=a[i]+a[i+1 ]+":" else : out+=a[i]+a[i+1 ] fi.write(out) fi.write('\n' ) else : break fi.close()
最后得到有规律的一行行数据
这里随机抽取两条解释
00:02:04:00,这一条代表意思是鼠标坐标(2,4)
00:05:0a:00,在上一条的基础上坐标移动(7,4)
附上python脚本翻译
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 nums = [] keys = open ('Python\\USBread\\mouse\\out.txt' ,'r' ,encoding="utf_16" ) f = open ('Python\\USBread\\mouse\\xy.txt' ,'w' ,encoding="utf_16" ) posx = 0 posy = 0 for line in keys: x=int (line[3 :5 ],16 ) y=int (line[6 :8 ],16 ) if x>127 : print ("aaa" ) x-=256 if y>127 : print ("bbb" ) y-=256 posx += x posy += y btn_flag = int (line[0 :2 ],16 ) if btn_flag == 0 : print (posx,posy) f.write(str (posx)) f.write(' ' ) f.write(str (posy)) f.write('\n' ) f.close()
根据上述脚本产出,可以将坐标转换成图片
1 2 3 4 5 6 7 8 9 from PIL import Imageimg = Image.new('RGB' ,(2000 ,2000 ),(255 ,255 ,255 )) f =open ('xy.txt' ) for line in f.readlines(): point =line.split() img.putpixel((int (point[0 ]),int (point[1 ])),(0 ,0 ,0 )) f.close() img.show()
wireshark的简单使用 基本使用 Wireshark的基本使用分为数据包筛选、数据包搜索、数据包还原、数据提取四个部分。
筛选ip 1.1源ip筛选
1.2目的ip筛选
1.3 mac地址筛选:
1 2 3 eth.dst ==A0:00:00:04:C5:84 筛选目标mac地址 eth.addr==A0:00:00:04:C5:84 筛选MAC地址
1.4 端口筛选:
1 2 3 4 5 tcp.dstport == 80 筛选tcp协议的目标端口为80 的流量包 tcp.srcport == 80 筛选tcp协议的源端口为80 的流量包 udp.srcport == 80 筛选udp协议的源端口为80 的流量包
1.5 协议筛选:
1 2 3 4 5 tcp 筛选协议为tcp的流量包 udp 筛选协议为udp的流量包 arp/icmp/http/ftp/dns/ip 筛选协议为arp/icmp/http/ftp/dns/ip的流量包
1.5 包长度筛选:
1 2 3 4 5 6 7 udp.length ==20 筛选长度为20的udp流量包 tcp.len >=20 筛选长度大于20的tcp流量包 ip.len ==20 筛选长度为20的IP流量包 frame.len ==20 筛选长度为20的整个流量包
1.6 http请求筛选
1 2 3 4 5 6 7 请求方法为GET:http.request.method==“GET”筛选HTTP请求方法为GET的 流量包 请求方法为POST:http.request.method==“POST”筛选HTTP请求方法为POST的流量包 指定URI:http.request.uri==“/img/logo-edu.gif”筛选HTTP请求的URL为/img/logo-edu.gif的流量包 请求或相应中包含特定内容:http contains “FLAG” 筛选HTTP内容为/FLAG的流量包