20211406张顺扬

导航

IS课程设计-小组报告

北京电子科技学院

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

基于Wireshark插件的国密标准检测工具的设计与实现

小组成员姓名:

  • 20211406 张顺扬
  • 20211312 徐元琦
  • 20211322 肖权城

指导教师: 娄嘉鹏

提交时间: 2023年12月16日

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

设计方案

  1. 插件架构
    • 国密标准检测模块

  • 用户界面模块
  1. 国密标准检测模块实现
    • 协议解析
    • 国密标准识别
    • 结果输出

可行性分析

  1. Wireshark插件开发框架

    • 优势:插件化架构、多语言支持
    • 劣势:学习曲线较陡峭
  2. 协议解析复杂性

    • 优势:SSL VPN协议公开且有详细文档
    • 劣势:多版本和变种需要考虑
  3. 用户界面交互

    • 优势:Wireshark提供丰富的用户界面组件
    • 劣势:需要符合Wireshark的风格和规范

二、详细设计思路

1. 系统体系结构与技术选择

**系统体系结构:

  • 采用插件化架构,利用Wireshark的插件开发框架进行开发。
  • 主要模块包括SSL/TLS握手协议解析、CipherSpec Change协议解析、Record Layer协议解析、Alert Protocol协议解析等。
  • 使用Lua语言编写Wireshark插件,通过DissectorTable将插件注册到指定的TCP端口。

**技术选择:

  • 编程语言: Lua,Wireshark插件的主要开发语言。
  • Wireshark插件框架: 利用Wireshark提供的Dissector API和相关函数。
  • UML建模工具: 使用UML建模工具(如PlantUML)绘制关键程序的流程图和调用关系图。

2. 关键数据类型定义与流程图

关键数据类型定义:

  • Lua中无显式数据类型定义,但需要注意Wireshark API返回的数据类型如TvbRange和Proto。

流程图和调用关系图:

  • 绘制流程图,包括主处理函数dissect_ssl_tls、握手协议解析函数等的关系。

3. UML建模

类图:

  1. ssl_tls_proto类
    • 方法:dissector(tvb, pktinfo, root)
  2. DissectorTable类
    • 方法:get("tcp.port"), add(443, ssl_tls_proto)

时序图:

  • 加载插件时序、解析SSL/TLS时序的关系图

主要时序操作:

  1. 加载插件时序:

    • DissectorTable的get方法。
    • DissectorTable的add方法。
  2. 解析SSL/TLS时序:

    • ssl_tls_proto的dissector方法。
    • 调用相应的解析函数,如dissect_ssl_handshake、dissect_cipher_spec_change等。

4. 测试目的、内容、结果及分析

测试目的:

  • 验证插件能够正确解析SSL/TLS协议,包括握手协议、CipherSpec Change协议、Record Layer协议、Alert Protocol协议。

测试内容:

  1. 通过Wireshark捕获包含SSL/TLS流量的数据包。
  2. 分析Wireshark插件的解析结果,检查是否正确解析协议类型、握手类型、加密算法等信息。

测试结果及分析:

  • 结果:插件能够正确解析SSL/TLS协议,显示相应的信息。
  • 分析:检查Wireshark的解析树,确保插件输出的信息与预期一致。调试和修复插件代码,确保准确性。

通过以上设计思路,可以更好地理解和实现Wireshark插件的SSL/TLS协议解析功能,确保插件的可靠性和准确性。

三、设计特色

插件化架构和模块化设计

设计采用了插件化架构,充分利用Wireshark插件开发框架,将SSL/TLS协议解析功能模块化,包括握手协议解析、CipherSpec Change协议解析、Record Layer协议解析、Alert Protocol协议解析和GateToGate协议等。每个模块负责特定协议的解析,使得系统具有更好的可扩展性和维护性。插件注册到指定的TCP端口,实现了对SSL/TLS流量的实时解析。

易读的代码和注释

代码采用Lua语言编写,具有较好的可读性和简洁性。注释清晰,对关键逻辑和功能进行了解释说明,方便理解和修改代码。
基于Wireshark API的开发
设计充分利用Wireshark插件开发框架提供的API,包括DissectorTable、Proto等,通过注册到TCP端口实现了对SSL/TLS流量的捕获和解析。这种基于Wireshark API的开发方式使得插件能够与Wireshark紧密集成,充分发挥Wireshark强大的网络分析能力。

面向对象的设计理念

尽管Lua语言并不是经典的面向对象语言,但通过在设计中使用对象的思想,如ssl_tls_proto类,成功抽象出插件的核心功能,并且模块之间通过对象的方式进行关联。这样的设计理念使得系统更易理解、更具灵活性。

强调测试的重要性

在设计中,强调了测试的重要性,明确了测试目的、内容和预期结果。这有助于保证插件的准确性和稳定性。通过对插件在实际SSL/TLS流量数据上的测试,可以验证其对各种协议类型的正确解析,并及时发现和修复可能存在的问题。

清晰的设计文档

通过上述设计思路,详细说明了系统体系结构、关键数据类型的定义、程序流程图、UML类图和时序图等方面。这样的设计文档有助于项目的理解和沟通,也为日后的维护和拓展提供了清晰的指导。

四、源代码及注释

-- SSL/TLS握手协议解析函数
local function dissect_ssl_handshake(tvb, pktinfo, root)
    -- 读取握手消息类型
    local handshakeType = tvb(5, 1):uint()

    pktinfo.cols.protocol:set("SSL/TLS - Handshake")

    -- 根据握手消息类型设置信息列
    if handshakeType == 0x01 then
        pktinfo.cols.info:set("Handshake Type: Client Hello")
    elseif handshakeType == 0x02 then
        pktinfo.cols.info:set("Handshake Type: Server Hello")

        -- 检查是否有证书
        local isCertificate = tvb(0x5c, 1):uint()
        if isCertificate == 0x0b then
            pktinfo.cols.info:append(" - Certificate Present")
        end

        -- 读取加密算法和临时密钥
        local cipherSuite = tvb(76, 2):uint()
        local keyExchange = tvb(15, 28):bytes()   -- 偏移调整
        local keyExchangeString = tostring(keyExchange)

        -- 打印加密算法和临时密钥到解析树中
        local treeItem = root:add(my_protocol, tvb(), "Encryption Algorithm and Temporary Key")

        if cipherSuite == 0x003c then
            treeItem:add("Cipher Suite:", "RSA_AES_SHA256")
            treeItem:add("Key Exchange:", keyExchangeString)
        end
    elseif handshakeType == 0x10 then
        pktinfo.cols.info:set("Handshake Type: Key Exchange")

        -- 检查是否为Change Cipher Spec
        local isChangeCipherSpec = tvb(0x010b, 1):uint()
        if isChangeCipherSpec == 0x14 then
            pktinfo.cols.info:append(" - Change Cipher Spec")
        end
    end
end

-- CipherSpec Change协议解析函数
local function dissect_cipher_spec_change(tvb, pktinfo, root)
    local record_type = tvb(0, 1):uint()

    -- 根据记录类型设置信息列
    if record_type == 0x14 then -- SSL/TLS Record Layer: Change Cipher Spec
        pktinfo.cols.protocol:set("SSL/TLS - Cipher Spec Change")
    else
        pktinfo.cols.protocol:set("SSL/TLS - Other Cipher Spec")
    end
end

-- Record Layer协议解析函数
local function dissect_record_layer_protocol(tvb, pktinfo, root)
    if tvb:len() < 1 then
        return
    end

    local record_type = tvb(0, 1):uint()

    pktinfo.cols.protocol:set("SSL/TLS - Record Layer Protocol")

    -- 添加特定于Record Layer Protocol的逻辑
    if record_type == 0x14 then
        pktinfo.cols.info:append(" - Custom Record Layer Logic: Detected Change Cipher Spec!")
    else
        pktinfo.cols.info:append(" - Custom Record Layer Logic: Other Record Type")
    end
end

-- Alert Protocol协议解析函数
local function dissect_alert_protocol(tvb, pktinfo, root)
    local level = tvb(5, 1):uint()
    local description = tvb(6, 1):uint()

    pktinfo.cols.protocol:set("SSL/TLS - Alert")

    -- 根据警告级别和描述设置信息列
    if level == 0x01 then
        pktinfo.cols.info:set("Level: Warning")
        if description == 0x0A then
            pktinfo.cols.info:append(" - Description: Unexpected Message")
        end
    elseif level == 0x02 then
        pktinfo.cols.info:set("Level: Fatal")
        if description == 0x46 then
            pktinfo.cols.info:append(" - Description: Protocol Version")
        end
    else
        pktinfo.cols.info:set("Encrypted Alert")
    end
end

-- 主处理函数
local function dissect_ssl_tls(tvb, pktinfo, root)
    local record_type = tvb(0, 1):uint()

    if record_type == 0x17 then
        -- SSL/TLS Record Layer
        dissect_record_layer_protocol(tvb, pktinfo, root)
    elseif record_type == 0x14 then
        -- CipherSpec Change
        dissect_cipher_spec_change(tvb, pktinfo, root)
    elseif record_type == 0x15 then
        -- Alert Protocol
        dissect_alert_protocol(tvb, pktinfo, root)
    elseif record_type == 0x16 then
        -- SSL/TLS Handshake
        dissect_ssl_handshake(tvb, pktinfo, root)
    end
end

-- 注册协议
local function ssl_tls_protocol_init()
    local ssl_tls_proto = Proto("ssl_tls", "SSL/TLS Protocol")

    function ssl_tls_proto.dissector(tvb, pktinfo, root)
        dissect_ssl_tls(tvb, pktinfo, root)
    end

    -- 注册端口
    local tcp_table = DissectorTable.get("tcp.port")
    tcp_table:add(443, ssl_tls_proto)
end

-- 调用注册函数
ssl_tls_protocol_init()




posted on 2023-12-16 16:19  20211406张顺扬  阅读(13)  评论(0编辑  收藏  举报