课设报告

发布时间 2023-12-16 21:51:12作者: 20211417黄琪凯
北京电子科技学院
《信息安全工程技术应用》课程设计报告
基于lua的wireshark插件开发

小组成员姓名:
20211410周意凯
20211417黄琪凯
20211421文鑫河

指导教师: 娄嘉鹏

提交时间:2023年12月10日

一、设计方案及可行性分析
该代码是一个用于解析 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()

  1. 面向对象技术可以用UML建模

MyProtocol
+ dissectChangeCipherSpec(buffer, pkt)
+ dissectAlert(buffer, pkt)
+ dissectHandshake(buffer, pkt, tree)
+ dissectRecord(buffer, pkt)
+ MyProtocol.dissector(buffer, pkt, tree)

4.列出测试目的、测试内容、测试结果,并对结果进行分析
测试目的:验证插件对于不同类型的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("hello20211417")
    if handshakeType == 0x01 then
        pkt.cols.info:set("Hello20211417")
    elseif handshakeType == 0x02 then
        pkt.cols.info:set("Hello20211417")
        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)

五、个人报告
1.小组贡献排序及依据(每个人的工作量):

20211410周意凯:项目规划、主体代码编写

20211421文鑫河:代码完善、调试程序、收集实验成果

20211417黄琪凯:资料搜索整理、实验报告撰写、总结实验经验

2.个人报告(20211417黄琪凯):
a)列出自己的贡献
资料搜索整理
实验报告撰写
总结实验经验

b)列出设计中遇到的问题及解决方法
问题:对数据包解析不了解,不知道偏移多少位的某字节代表什么意思。
解决办法:上网查找资料,加上询问gpt学习。

c)列出调试过程中遇到的主要问题,并说明解决方法;
问题:编写的代码很多情况下加载都会报错

解决办法:询问GPT错误情况,但是GPT给的回复也没能解决问题,最后查找资料自己手动改代码解决。

d)设计体会及收获
在设计Lua插件的过程中,我了解到Wireshark的插件机制提供了很大的灵活性,能够为特定协议定制解析规则,使得我们可以更好地查看和理解特定数据包的内容。通过此次编写,我深入了解了SSL协议的结构和解析原理,以及Wireshark插件的编写方式。我学会了如何根据SSL协议的不同类型,解析出不同的子协议,并在Wireshark中展现出来。这需要对SSL协议的结构有一定的了解,也需要熟练掌握Lua编程语言。另外,我学到了如何注册特定的端口,使Wireshark能够识别SSL流量并应用相应的解析规则。我更加深入地理解了网络协议的解析原理和Wireshark插件的编写方式,也提升了对SSL协议的理解。
但是在设计的过程中,也遇到了很多问题,刚开始做的题目五,在“D1-应用服务器和用户终端之间的通信数据”中找到证书,但是在数据包里没看到SSL协议的数据包,后面转变了设计思路,转变为设计SSL握手协议、密码规格变更协议、报警协议、记录层协议这几个协议。

e)参考资料(图书、网址…)

https://blog.csdn.net/qq_38643642/article/details/105441044?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522170273182616800182783880%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=170273182616800182783880&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduend~default-1-105441044-null-null.142^v96^pc_search_result_base2&utm_term=lua%20wireshark&spm=1018.2226.3001.4187

https://blog.csdn.net/Little_Eyelash/article/details/115242195?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522170273182616800182783880%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=170273182616800182783880&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~baidu_landing_v2~default-4-115242195-null-null.142^v96^pc_search_result_base2&utm_term=lua%20wireshark&spm=1018.2226.3001.4187

https://blog.csdn.net/quniyade0/article/details/115266774?ops_request_misc=&request_id=&biz_id=102&utm_term=lua%20wireshark&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-7-115266774.142^v96^pc_search_result_base2&spm=1018.2226.3001.4187