第三周进展
心得体会:
实在是不方便调试,也不知道哪里错了。说实话学会写最简单的lua了之后,这个项目就变成了wireshark数据分析,因为难得做不来,只能基于抓包数据来写代码。
分析密码套件和tls上层协议都写了,代码本质区别不大,一个是在协议树中添加子树节点,添加字段来显示;一个是更改协议protocol和信息info来反馈。
学习笔记+代码
密码套件(微软资料)
分别是:密钥交换 签名 主体加密 消息身份验证 椭圆曲线
由此小结一下 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256的含义
1)TLS:Transport Layer Security (TLS),表明了密钥套件的协议
2)ECHDE:Elliptic Curve Diffie-Hellman Ephemeral (ECDHE),表明了密钥交换的算法
3)RSA:Rivest Shamir Adleman algorithm (RSA),表明了签名加密算法、握手期间的身份认证机制。
ECHDE_RSA,用于决定客户端与服务器之间在握手时如何身份验证。
当服务器配置ECC证书时,加密套件只能选择XXX_ECDSA_XXX或者ECDH_XXX。
当服务器配置RSA证书时,只能选择RSA_XXX或者ECDHE_RSA_XXX形式的加密套件。
ECDHE_RSA,表明了证书必须是RSA签名的,证书里的公钥必须是RSA的公钥。
4)AES_128_GCM,用于加密消息流。上面的ciphersuite.info原话直译是:在 Galois/Counter 模式下具有 128 位密钥的高级加密标准 (AES 128 GCM)。其中,
AES:Advanced Encryption Standard,AES,会话加密算法。用于加密消息流
128:会话加密密钥的大小(128位)
GCM:GCM ( Galois/Counter Mode) 指的是该对称加密采用Counter模式,并带有GMAC消息认证码。二者分别保证了加密算法的保密性、完整性。
5)SHAR256,Secure Hash Algorithm 256 (SHA256),消息认证码算法 使用SHA算法,长度是256位,用于创建消息摘要,消息流每个数据块的加密散列。
6)整体上,显然这是TLS握手过程中Server Hello里面携带的信息,由两个字节表示。我们可以从TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256分析出,从数据交换身份验证到会话加密、消息加密都有算法约定
原文链接:https://blog.csdn.net/H_O_W_E/article/details/125247938
GCM和CBC都是AES的分组模式之一
详见:https://zhuanlan.zhihu.com/p/558881344
抓包数据中:
Server Hello,Certificate
82、83字节是00 3c
TLS_RSA_WITH_AES_128_CBC_SHA256
306~30e字节是2a 86 48 86 f7 0d 01 01 0b
Algorithm Id: 1.2.840.113549.1.1.11 (sha256WithRSAEncryption)
-- 创建一个 Wireshark Lua 插件,用于检查TLS Server Hello消息中的算法套件是否使用RSA算法、AES加密算法和SHA-256完整性保护算法
-- 注册新的协议
local my_protocol = Proto("MyProtocol", "My Protocol")
-- 创建字段
local rsaAuthField = ProtoField.string("my_protocol.rsa_algorithm", "RSA Authentication Algorithm")
local aesEncryptionField = ProtoField.string("my_protocol.aes_algorithm", "AES Encryption Algorithm")
local sha256IntegrityField = ProtoField.string("my_protocol.sha256_integrity", "SHA-256 Integrity Protection Algorithm")
-- 将字段添加到协议中
my_protocol.fields = {rsaAuthField, aesEncryptionField, sha256IntegrityField}
local data_fis = Dissector.get("data")
-- 分析器函数
function my_protocol.dissector(buffer, pkt, tree)
-- 从TLS Server Hello数据中提取算法套件
local cipherSuites = buffer(0x4c, 2):uint() -- 以0x36为起始偏移量来解析TLS数据,这里假设数据包中TLS数据部分的起始偏移量是0x36
-- 检查算法套件是否为 RSA、AES、SHA-256
if cipherSuites == 0x003c then
-- 在协议树中创建一个子树节点
local tls_subtree = tree:add(my_protocol, buffer(), "TLS Data")
-- 添加字段数据到子树
tls_subtree:add(rsaAuthField, "RSA Authentication Algorithm Used")
tls_subtree:add(aesEncryptionField, "AES Encryption Algorithm Used")
tls_subtree:add(sha256IntegrityField, "SHA-256 Integrity Protection Algorithm Used")
data_fis:call(buffer(0x4e):tvb(), pkt, tls_subtree)
end
end
-- 将协议绑定到数据端口上
local tcp_table = DissectorTable.get("tcp.port")
tcp_table:add(443, my_protocol) -- 假设TLS加密的标准端口是443
运行截图:
其余密码套件对应的数据:
在Lua语言中,do ... end
被用来创建一个局部作用域,以控制变量的可见性和生命周期。在Wireshark的Lua插件中,使用 do ... end
可以确保在插件中定义的变量不会影响到其他部分的代码,并且可以避免命名冲突。
实现代码
-- 注册新的协议
local my_protocol = Proto("MyProtocol", "My Protocol")
-- 分析器函数
function my_protocol.dissector(buffer, pkt, tree)
-- 获取记录类型
local typer = buffer(0, 1):uint() -- 假设记录类型在数据包的开头
local sh_ty = buffer(5, 1):uint()
local dsc = buffer(6, 1):uint()
-- 设置协议列信息
if typer == 0x14 then
pkt.cols.protocol:set("TLS-change cipher spec")
elseif typer == 0x15 then
pkt.cols.protocol:set("TLS-Alert")
if sh_ty == 0x02 then
pkt.cols.info:set("Level:Fatal")
if dsc == 0x46 then
pkt.cols.info:append(" - Description:Protocol Version")
end
end
elseif typer == 0x16 then
pkt.cols.protocol:set("TLS-Handshake")
if sh_ty == 0x01 then
pkt.cols.info:set("Client Hello")
elseif sh_ty == 0x02 then
pkt.cols.info:set("Server Hello")
local is_cer = buffer(0x5c,1):uint()
if is_cer == 0x0b then
pkt.cols.info:append(" - Certificate")
end
elseif sh_ty == 0x10 then
pkt.cols.info:set("Key Exchange")
local is_cc = buffer(0x010b,1):uint()
if is_cc == 0x14 then
pkt.cols.info:append(" - Change Cipher Spec")
end
end
elseif typer == 0x17 then
pkt.cols.protocol:set("TLS-Application Data")
end
end
-- 将协议绑定到数据端口上
local tcp_table = DissectorTable.get("tcp.port")
tcp_table:add(443, my_protocol) -- 假设TLS加密的标准端口是443