实验报告(小组+个人)

发布时间 2023-12-14 17:08:46作者: 周意凯

 

 

 

北京电子科技学院

《信息安全工程技术应用》课程设计报告

基于lua的wireshark插件开发

 

 

 

 

 

 

 

小组成员姓名:20211410周意凯

20211417黄琪凯

20211421文鑫河

   

指导教师: 娄嘉鹏

   

提交时间:20231210   

 

 

一、设计方案及可行性分析

该代码是一个用于解析 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()     |

--------------------------------

 

3. 面向对象技术可以用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("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)

 

 

 

 

五、个人报告

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

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

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

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

  1. 个人报告(20211410周意凯):

a) 列出自己的贡献

密码套件识别插件编写

TLS上层协议识别插件编写

b) 列出设计中遇到的问题及解决方法

1、如何使用码云https://www.cnblogs.com/dkyzhouyikai/p/17838175.html

2、密码套件不懂

解决方法:在参考资料中学习了一番后略微懂得

3、对于协议树的概念不够清晰,对wireshark数据理解不够导致的关键识别函数不会写

解决方法:学习得知tlsIPTCP协议上层,数据在TCP数据包内,解析是从TCP上层开始解析,也就是TCP的报头之后,偏移量也就是从那之后开始。

c) 列出调试过程中遇到的主要问题,并说明解决方法;

第一个问题就是调试不方便。后来就把plugin建了个快捷方式,和代码一起放桌面上,改完一遍就ctrlC,ctrlV进文件夹里然后wireshark里ctrl+shift+L加载插件,调试愈发熟练。

d) 设计体会及收获

 实在是不方便调试,也不知道哪里错了。说实话学会写最简单的lua了之后,这个项目就变成了wireshark数据分析,因为难得做不来,只能基于抓包数据来写代码。

分析密码套件和tls上层协议都写了,代码本质区别不大,一个是在协议树中添加子树节点,添加字段来显示;一个是更改协议protocol和信息info来反馈。

最大的收获就是基本会用lua写一个简单的wireshark插件了,这整个项目的过程中也总结了许多学习经验,又有总结如何去高效的学习方法。

 

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

学习lua的参考资料链接:

https://blog.csdn.net/qq_40421919/article/details/103516694

https://www.runoob.com/lua/lua-miscellaneous-operator.html

https://zhuanlan.zhihu.com/p/659794500

学习密码算法的参考资料链接:

密码套件的含义

原文链接:https://blog.csdn.net/H_O_W_E/article/details/125247938

GCM和CBC都是AES的分组模式之一

详见:https://zhuanlan.zhihu.com/p/558881344