是TC

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

一、本周计划完成的任务

由于下周就要进行实验验收,所以本周我们决定将该插件完成。

在lua代码的学习上,已经基本可以满足插件代码的框架设计,再配合chatgpt的修改和与其他同学的探讨,能够完成插件设计。

在国密算法的了解上做了很多学习,对课题有了清晰的认知,对通信过程中哪个部分用了怎样的加密有了了解。

二、实际完成情况

完成了插件的设计,实现了解析在wireshark中所抓的包的功能。

以下为代码:

local function dissect_tls_record_content_type(tvb, pktinfo, root)
    if tvb:len() < 1 then
        return
    end

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

    -- 将第一个记录层的子协议名称设置为协议名称
    if content_type == 0x14 then
        pktinfo.cols.protocol:set("Change Cipher Spec")
    elseif content_type == 0x15 then
        pktinfo.cols.protocol:set("Alert")
    elseif content_type == 0x16 then
        pktinfo.cols.protocol:set("Handshake")
    elseif content_type == 0x17 then
        pktinfo.cols.protocol:set("Application Data")
    else
        pktinfo.cols.protocol:set("Other TLS Content Type")
    end
end

local function dissect_tls_record(tvb, pktinfo, root)
    -- 记录层的content_type字段位于偏移量为0的位置
    local content_type_offset = 0

    -- 创建一个树节点来表示记录层
    local record_item = root:add("TLS Record Layer")

    -- 提取记录层的content_type字段
    local content_type = tvb(content_type_offset, 1):uint()
    record_item:add("Content Type: " .. tostring(content_type))

    -- 调用函数根据content_type字段设置协议名称
    dissect_tls_record_content_type(tvb(content_type_offset, 1), pktinfo, record_item)

    -- 解析tls.record.version字段
    local version_offset = content_type_offset + 1  -- 偏移量为1
    local version = tvb(version_offset, 2):uint()

    -- 根据版本字段值向信息列添加特定的文本信息
    if version == 0x0101 then
        pktinfo.cols.info:append(" Version: TLCP")
    elseif version == 0x0303 then
        pktinfo.cols.info:append(" Version: TLS 1.2")
    elseif version == 0x0301 then
        pktinfo.cols.info:append(" Version: TLS 1.0")
    else
        pktinfo.cols.info:append(" Version: Unknown")
    end
end

local function ssl_vpn_protocol_init()
    local ssl_vpn_proto = Proto("ssl_vpn", "SSL VPN Protocol")

    function ssl_vpn_proto.dissector(tvb, pktinfo, root)
        local tree = root:add(ssl_vpn_proto, tvb())

        -- 调用记录层解析函数
        dissect_tls_record(tvb, pktinfo, tree)
    end

    -- 关联到默认的SSL VPN端口(443)
    local tcp_table = DissectorTable.get("tcp.port")
    tcp_table:add(443, ssl_vpn_proto)
end

-- 开始SSL VPN协议解析
ssl_vpn_protocol_init()

以下为运行后的实际效果

 

 可以看到实现了解析https协议中的不同子协议并显示出来的功能。识别到了handshake、application data、change cipher spec等不同的子协议。

三、问题与解决过程

最开始在撰写过程中没有理解题目要求。我们的想法是做一个能够识别tcp三次握手过程中第一次握手的插件。

我们的识别标准就是当syn值为0时,即为第一次握手,以下为代码

-- 定义新协议
local course_protocol = Proto("CourseDesign", "课程设计: Seq=0即通信建立")

-- 定义协议字段
local seq_number = ProtoField.uint32("CourseDesign.SeqNumber", "Sequence Number")

-- 将字段添加到协议中
course_protocol.fields = {seq_number}

-- 定义协议解析函数
function course_protocol.dissector(tvb, pinfo, tree)
    pinfo.cols.protocol = "CourseDesign"

    local subtree = tree:add(course_protocol, tvb(0))

    -- 从TCP头中提取Seq字段
    local seq_value = tvb(4, 4):uint()

    -- 添加Seq字段到协议树中
    subtree:add(seq_number, tvb(4, 4)):set_text("Seq Number: " .. seq_value)

    -- 如果Seq等于0,则显示通信建立的提示信息
    if seq_value == 0 then
        pinfo.cols.info = "Communication Establishment: Seq=0"
    end
end

-- 注册协议
DissectorTable.get("tcp.port"):add(0, course_protocol)

但是在该代码运行后,发现不仅无法识别到第一次握手并显示该子协议的名字,反而会屏蔽掉这些tcp连接过程中的包。随后代码修改也没有成功。

后来对课题做了更多研究后发现我们想实现的功能太狭隘了,应该是可以通过https协议建立连接过程中加密后数据包的特殊字段,来识别这个数据包是什么类型。而我们识别syn=0这种方式太局限,仅能找到那一个类型的包。而真正正确的方式才需要我们进行国密加密算法的学习,因为需要了解加密过程以及特殊字段的不同含义。

最后经过国密算法的学习和代码的修改,完成了本插件。

posted on 2023-12-10 16:15  是TC  阅读(32)  评论(0)    收藏  举报