
一、設計方案及可行性分析
該代碼是一個用于解析 TLS(Transport Layer Security)協議的 Lua 插件,可以作為 Wireshark 的一個解析器。通過解析不同類型的 TLS 協議記錄,包括 Change Cipher Spec 協議、Alert 協議、Handshake 協議和 Record 協議,為每個記錄設置相應的協議類型。這個插件主要用于網絡數據包的分析和監控,可以增加 Wireshark 對于 TLS 協議的解析能力。
二、詳細設計思路
1.系統體系結構,技術選擇
該插件基于 Lua 語言編寫,作為 Wireshark 的 Lua 插件,用于解析 TLS 協議記錄。Wireshark 是一個廣泛使用的網絡協議分析工具,而Lua作為一種腳本語言,能夠很好地擴展Wireshark的功能。基于Wireshark的插件機制,Lua語言被用來實現對TLS協議記錄的解析。
2.說明程序中用到的關鍵數據類型的定義,繪制關鍵程序的流程圖,以及各子模塊間 的調用關系圖
| MyProtocol |
|---|
| - dissectChangeCipherSpec() |
| - dissectAlert() |
| - dissectHandshake() |
| - dissectRecord() |
| - MyProtocol.dissector() |
- 面向對象技術可以用UML建模
| MyProtocol |
|---|
| + dissectChangeCipherSpec(buffer, pkt) |
| + dissectAlert(buffer, pkt) |
| + dissectHandshake(buffer, pkt, tree) |
| + dissectRecord(buffer, pkt) |
| + MyProtocol.dissector(buffer, pkt, tree) |
- 列出測試目的、測試內容、測試結果,并對結果進行分析
測試目的:驗證插件對于不同類型的TLS協議記錄的解析準確性。
測試內容:輸入不同類型的TLS協議記錄數據包,檢查插件解析出的協議類型和信息是否準確。
測試結果分析:分析每種類型的TLS協議記錄數據包解析的結果,確認是否滿足預期,并進行結果分析。
三、設計特色
該插件通過解析不同類型的 TLS 協議記錄,提供了對 Change Cipher Spec、Alert、Handshake 和 Record 協議的解析。主要設計特色包括提供準確的協議解析結果,能夠幫助網絡管理員或安全分析人員更好地理解和分析 TLS 協議相關的數據包。
四、源代碼及注釋
local my_protocol = Proto("MyProtocol", "My Protocol")
-- 子函數:處理TLS Change Cipher Spec Protocol
local function dissectChangeCipherSpec(buffer, pkt)
pkt.cols.protocol:set("TLS-Change Cipher Spec")
end
-- 子函數:處理TLS Alert Protocol
local function dissectAlert(buffer, pkt)
local level = buffer(5, 1):uint()
local description = buffer(6, 1):uint()
pkt.cols.protocol:set("TLS-Alert")
if level == 0x01 then
pkt.cols.info:set("Level: Warning")
if description == 0x0A then
pkt.cols.info:append(" - Description: Unexpected Message")
end
elseif level == 0x02 then
pkt.cols.info:set("Level: Fatal")
if description == 0x46 then
pkt.cols.info:append(" - Description: Protocol Version")
end
else
pkt.cols.info:set("Encrypted Alert")
end
end
local function dissectHandshake(buffer, pkt, tree)
local handshakeType = buffer(5, 1):uint()
pkt.cols.protocol:set("TLS-Handshake")
if handshakeType == 0x01 then
pkt.cols.info:set("Client Hello")
elseif handshakeType == 0x02 then
pkt.cols.info:set("Server Hello")
local isCertificate = buffer(0x5c, 1):uint()
if isCertificate == 0x0b then
pkt.cols.info:append(" - Certificate")
end
-- 讀取加密算法和臨時密鑰
local cipherSuite = buffer(76, 2):uint()
local keyExchange = buffer(15, 28):bytes() -- 偏移調整
local keyExchangeString = tostring(keyExchange)
-- 打印加密算法和臨時密鑰到解析樹中
local treeItem = tree:add(my_protocol, buffer(), "Encryption Algorithm and Temporary Key")
if cipherSuite == 0x003c then
treeItem:add("RSA Authentication Algorithm:", "RSA Authentication Algorithm Used")
treeItem:add("AES Encryption Algorithm:", "AES Encryption Algorithm Used")
treeItem:add("SHA-256 Integrity Protection Algorithm:", "SHA-256 Integrity Protection Algorithm Used")
treeItem:add("Key Exchange:", keyExchangeString)
end
elseif handshakeType == 0x10 then
pkt.cols.info:set("Key Exchange")
local isChangeCipherSpec = buffer(0x010b, 1):uint()
if isChangeCipherSpec == 0x14 then
pkt.cols.info:append(" - Change Cipher Spec")
end
end
end
-- 子函數:處理TLS Record Protocol
local function dissectRecord(buffer, pkt)
pkt.cols.protocol:set("TLS-Record Data")
end
-- 主函數
function my_protocol.dissector(buffer, pkt, tree)
local typer = buffer(0, 1):uint()
if typer == 0x14 then
dissectChangeCipherSpec(buffer, pkt)
elseif typer == 0x15 then
dissectAlert(buffer, pkt)
elseif typer == 0x16 then
dissectHandshake(buffer, pkt, tree)
elseif typer == 0x17 then
dissectRecord(buffer, pkt)
end
end
-- 注冊端口
local tcp_table = DissectorTable.get("tcp.port")
tcp_table:add(443, my_protocol)
五、個人報告
- 小組貢獻排序及依據(每個人的工作量):
20211410周意凱:項目規劃、主體代碼編寫
20211421文鑫河:代碼完善、調試程序、收集實驗成果
20211417黃琪凱:資料搜索整理、實驗報告撰寫、總結實驗經驗 - 個人報告(20211421文鑫河):
1)、列出自己的貢獻
代碼完善
調試程序
收集實驗成果
2)、列出設計中遇到的問題及解決方法
問題:對wireshark抓包分析不熟練,不理解為什么TLS數據偏移量直接從0開始,忽略前面的TCP和IP頭
解決辦法:上網查找資料,加上詢問gpt學習,如果TLS考慮了底層協議頭的偏移,可能會增加實現的復雜性,并引入潛在的安全風險。通過從0開始的偏移,TLS可以更簡潔地處理數據。通過不依賴于底層協議頭的偏移,TLS可以更靈活地與不同的網絡協議棧集成。
問題:不清楚相關加密算法在TLS協議數據中的體現
解決辦法:通過查閱相關資料,可以得知加密算法說明在TLS中占兩個字節,如Cipher Suite: TLS_RSA_WITH_AES_128_CBC_SHA256 (0x003c)
3)、列出調試過程中遇到的主要問題,并說明解決方法;
問題:從TLS數據中提取的字節無法正常進行比較
解決辦法:詢問GPT得知,需將提取到的數據轉化為uint無符號類型才可以進行比較
問題:提取到的臨時密鑰數據顯示為亂碼
解決辦法:詢問GPT錯誤情況得知,臨時密鑰字節數相對較多,需轉化為string類型即可正常顯示
4)、設計體會及收獲
通過這次課程設計,我首先對lua語言有了一定了解。Lua語言確實相對來說比較簡單,只需要閱讀幾篇文章就可以上手編寫。通過對lua與wireshark的綜合學習,我學會了使用lua提取wireshark數據包中的特定字節信息并進行轉化,還可以隨意修改wireshark中的protocol、info以及tree中的相關內容。其次,我還對TLS協議以及加密算法有了一些了解。我知道了TLS協議包含的四種子協議:告警協議,握手協議,密鑰規格變更協議,記錄層協議。同時對相關加密算法在TLS中的字節體現有了認識,如本次課設中的Cipher Suite: TLS_RSA_WITH_AES_128_CBC_SHA256 (0x003c),還有其他諸如臨時密鑰,證書等TLS數據中的內容。但是這次課設一開始并不順利,起初沒有弄明白具體要做啥,在D1解析數據中瘋狂尋找證書信息,但D1里面并沒有TLS/SSL協議。后面弄清楚了目的,編寫代碼就非常簡單了,只需要提取數據,進行比對,然后更改信息就行了。
總得來說,通過這次課設,我學到了很多課外的但是專業相關的知識,這對我以后的信息安全工作有一定的助力。
5)、參考資料
https://blog.csdn.net/ryanzzzzz/article/details/129934536
https://baijiahao.baidu.com/s?id=1758641807495130037&wfr=spider&for=pc&searchword=ssl tls協議的記錄層字段
https://blog.csdn.net/thlzjfefe/article/details/133041339?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522170182462516800222886460%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=170182462516800222886460&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allfirst_rank_ecpm_v1~rank_v31_ecpm-1-133041339-null-null.142v96pc_search_result_base3&utm_term=wireshark%E6%AF%8F%E4%B8%AA%E6%95%B0%E6%8D%AE%E5%8C%85%E5%88%86%E6%9E%90TLS%2FSSL%E5%8D%8F%E8%AE%AE%E7%B1%BB%E5%9E%8B&spm=1018.2226.3001.4187
浙公網安備 33010602011771號