wireshark的portal协议的lua插件(mac和win版)

wireshark中没有portal协议,我们在抓包时候在这里输入portal,显示没有插件。我们需要使用wireshark的插件,wireshark的插件是使用lua语言开发的,wireshark并未内置 Portal协议,可解析Portal协议。

话不多说

第一步:将下面的插件脚本复制保存为portal.lua文件

--[[
	code
--]] 
do
     --[[
         创建一个新的协议结构 portal_proto
         第一个参数是协议名称会体现在过滤器中
         第二个参数是协议的描述信息,无关紧要
     --]]
     local portal_proto = Proto("portal", "Portal Protocol")
     local attribute_proto = Proto("attribute", "Portal Attributes:")
     
     --[[
         下面定义字段
     --]]
	 local portal_types = {
		[1]="REQ_CHALLENGE",
		[2]="ACK_CHALLENGE",
		[3]="REQ_AUTH",
		[4]="ACK_AUTH",
		[5]="REQ_LOGOUT", 
		[6]="ACK_LOGOUT",
		[7]="AFF_ACK_AUTH",
		[8]="NTF_LOGOUT",
		[9]="REQ_INFO",
		[10]="ACK_INFO"
	}
	 local version = ProtoField.uint8("portal.version", "Version", base.DEC, {[1]="Version 1", [2]="Version 2"}, 0x00)
	 local code_type = ProtoField.uint8("portal.type", "Type", base.DEC, portal_types)
	 local pap_chap = ProtoField.uint8("portal.papchap", "Pap/Chap", base.DEC, {[0]="CHAP",[1]="PAP"}, 0x00)
	 local reserved = ProtoField.uint8("portal.reserved", "Rsvd", base.DEC)
	 local serial_no = ProtoField.uint16("portal.serialno", "SerialNo", base.HEX)
	 local req_id    = ProtoField.uint16("portal.reqid", "ReqID", base.HEX)
	 local user_ip   = ProtoField.ipv4("portal.userip", "UserIP")
	 local user_port = ProtoField.uint16("portal.userport", "UserPort", base.HEX)
	 local err_code  = ProtoField.uint8("portal.errcode", "ErrCode", base.DEC)
	 local attr_num  = ProtoField.uint8("portal.attrnum", "AttrNum", base.DEC)	 
     local authenticator = ProtoField.bytes("portal.authenticator", "Authenticator")
	 local user_name = ProtoField.string("portal.username", "UserName")
	 local user_password = ProtoField.string("portal.password", "Password")
	 local user_chappasswd = ProtoField.bytes("portal.chappasswd", "ChapPasswd")
	 local challenge = ProtoField.bytes("portal.challenge", "Challenge")
     
     -- 将字段添加都协议中
     portal_proto.fields = {
         version,
         code_type,
         pap_chap,
         reserved,
		 serial_no,
		 req_id,
		 user_ip,
		 user_port,
		 err_code,
		 attr_num,
		 authenticator,
		 user_name,
		 user_password,
		 user_chappasswd,
		 challenge
     }
     
     --[[
         下面定义 portal 解析器的主函数,这个函数由 wireshark调用
         第一个参数是 Tvb 类型,表示的是需要此解析器解析的数据
         第二个参数是 Pinfo 类型,是协议解析树上的信息,包括 UI 上的显示
         第三个参数是 TreeItem 类型,表示上一级解析树
     --]]
     function portal_proto.dissector(tvb, pinfo, treeitem)
         
         -- 设置一些 UI 上面的信息
         pinfo.cols.protocol:set("Portal")
         
         local offset = 0
         local tvb_len = tvb:len()
         
         -- 在上一级解析树上创建 portal 的根节点
         local portal_tree = treeitem:add(portal_proto, tvb:range(offset))
         
         -- 下面是向该根节点上添加子节点,也就是自定义协议的各个字段
         -- 注意 range 这个方法的两个参数的意义,第一个表示此时的偏移量
         -- 第二个参数代表的是字段占用数据的长度
         portal_tree:add(version, tvb:range(offset, 1))
		 local ver_value = tvb(offset, 1):uint()
         offset = offset + 1        
         local req_type = tvb(offset, 1):uint()
         portal_tree:add(code_type, tvb:range(offset, 1))
         if req_type == 1 then
            pinfo.cols.info:set("REQ_CHALLENGE")
         end
         if req_type == 2 then
            pinfo.cols.info:set("ACK_CHALLENGE")
         end
         if req_type == 3 then
            pinfo.cols.info:set("REQ_AUTH")
         end
         if req_type == 4 then
            pinfo.cols.info:set("ACK_AUTH")
         end
         if req_type == 5 then
            pinfo.cols.info:set("REQ_LOGOUT")
         end
         if req_type == 6 then 
            pinfo.cols.info:set("ACK_LOGOUT")
         end
         if req_type == 7 then 
            pinfo.cols.info:set("AFF_ACK_AUTH")
         end
         if req_type == 8 then 
            pinfo.cols.info:set("NTF_LOGOUT")
         end
         if req_type == 9 then 
            pinfo.cols.info:set("REQ_INFO")
         end
         if req_type == 10 then 
            pinfo.cols.info:set("Portal ACK_INFO")
         end
         offset = offset + 1
         portal_tree:add(pap_chap, tvb:range(offset, 1))
         offset = offset + 1
		 portal_tree:add(reserved, tvb:range(offset, 1))
         offset = offset + 1
		 portal_tree:add(serial_no, tvb:range(offset, 2))
         offset = offset + 2
		 portal_tree:add(req_id, tvb:range(offset, 2))
         offset = offset + 2
		 portal_tree:add(user_ip, tvb:range(offset, 4))
         offset = offset + 4
		 portal_tree:add(user_port, tvb:range(offset, 2))
         offset = offset + 2
		 portal_tree:add(err_code, tvb:range(offset, 1))
         offset = offset + 1
		 portal_tree:add(attr_num, tvb:range(offset, 1))
		 local attr_num = tvb(offset, 1):uint()
         offset = offset + 1
		 if ver_value == 0x02 then
		    if tvb_len - offset >= 16 then
			    portal_tree:add(authenticator, tvb:range(offset, 16))
            end
			offset = offset + 16
		 end
         if attr_num > 0 then 
             local attribute_tree = portal_tree:add(attribute_proto, tvb:range(offset)) 
             attribute_tree:set_text("Attributes:")
             local attr_type = tvb(offset, 1):uint()
			 if attr_type == 1 then
			  	 local length = tvb(offset + 1, 1):uint()
			 	 attribute_tree:add(user_name, tvb:range(offset + 2, length - 2))
				 offset = offset + length
				 if tvb_len - offset > 0 then
				 	 attr_type = tvb(offset, 1):uint()
				 end
                 attribute_tree:append_text("User-Name,")
			end
            	if attr_type == 2 then
				local length = tvb(offset + 1, 1):uint()
				attribute_tree:add(user_password, tvb:range(offset + 2, length - 2))
				offset = offset + length
				if tvb_len - offset > 0 then
					attr_type = tvb(offset, 1):uint()
				end
                attribute_tree:append_text("Passowrd")
			end
			if attr_type == 3 then
				local length = tvb(offset + 1, 1):uint()
				attribute_tree:add(challenge, tvb:range(offset + 2, length - 2))
				offset = offset + length
				if tvb_len - offset > 0 then
					attr_type = tvb(offset, 1):uint()
				end
                attribute_tree:append_text("Challenge")
			end
			if attr_type == 4 then
				local length = tvb(offset + 1, 1):uint()
				attribute_tree:add(user_chappasswd, tvb:range(offset + 2, length - 2))
				offset = offset + length
				if tvb_len - offset > 0 then
					attr_type = tvb(offset, 1):uint()
				end
                attribute_tree:append_text("Chap-Password")
			end
         end
		 
--			for i =1,attr_num do 
				
--			end
     end
     
     -- 向 wireshark 注册协议插件被调用的条件
     local upd_port_table = DissectorTable.get("udp.port")
     upd_port_table:add(2000, portal_proto)
 end

第二部:然后放到wireshark安装的目录下

  1. (macOS)路径为/Applications/Wireshark.app/Contents/Resources/share/wireshark
  2. (win)路径为安装盘符/wireshark

第三部:找见init.lua文件,末尾添加dofile("portal.lua")

注意:

要保证最上面的disable_lua = false不能是true,否则wireshark就不支持加载lua插件了

(macos如下图,如果是enable_lua=true则不需要改动。)

 第四步:重启wireshark

portal协议可用

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 非常感谢您的问题。我了解到您对于wireshark lua插件 ProtoField.uint32的使用有疑问。 首先,ProtoField.uint32是wireshark lua插件中的一个函数,用于指定字段的类型为32位的无符号整数。它的使用方法是在wireshark的脚本中调用该函数,并传递相关参数,如字段名称、描述、偏移量等,以便wireshark能够正确地解析协议中的数据。 如果您在使用ProtoField.uint32时遇到问题,建议您查看wireshark官方文档或相关的开发者社区,以获取更详细的帮助和支持。如果您需要更具体的技术指导或解决方案,可以向相关专业人士或开发者咨询,或者寻找更详细的教程和示例。 再次感谢您的提问,希望我的回答能够对您有所帮助。如果您有其他问题或需要进一步的帮助,请随时联系我。 ### 回答2: Wireshark是一款开源的网络协议分析工具,可以用于抓取和分析网络数据包。它支持使用Lua语言编写插件来扩展其功能。 Wireshark提供了一个名为ProtoField.uint32的函数,它用于创建一个新的网络协议字段,该字段的类型为无符号32位整数。ProtoField.uint32函数的语法如下: ```lua ProtoField.uint32(name, abbreviation, base, mask, [display]) ``` 其中参数的含义如下: - name:字段的名称,用于在显示过滤器和面板中标识该字段。 - abbreviation:字段的缩写,用于在协议分析结果中显示。 - base:字段的进制表示方式,可以为2、10、16之一,分别代表二进制、十进制和十六进制。 - mask:字段的掩码,用于提取关键信息。可以留空或者设置为nil,表示不使用掩码。 - display:字段的显示格式,可选参数。 使用ProtoField.uint32创建的字段可以在协议解析器脚本中使用,通过访问协议分析树中的相应字段对象获取字段的值。例如,可以通过以下方式获取字段值: ```lua local field = ProtoField.uint32("my_protocol.field_name", "My Field", base.DEC) -- ... function my_protocol.dissector(buffer, pinfo, tree) -- ... local field_value = buffer(0, 4):uint() local field_item = tree:add(field, buffer(0, 4)) -- ... end ``` 在上述例子中,我们定义了一个名为"my_protocol.field_name"的字段,缩写为"My Field",进制表示方式为十进制。然后在协议解析器的dissector函数中,使用buffer(0, 4):uint()获取前4个字节的无符号32位整数值,并将其添加到协议分析树中。 通过WiresharkLua插件和ProtoField.uint32函数,我们可以轻松地创建和使用自定义的网络协议字段,以满足特定协议的分析需求。 ### 回答3: Wireshark是一款开源的网络协议分析工具,它支持使用Lua编写插件来扩展其功能。在Wireshark中,ProtoField.uint32是一种用于表示无符号32位整数的数据类型,可以在Lua插件中使用它来定义和访问协议字段。 使用ProtoField.uint32,我们可以在Lua插件中定义一个协议字段,并指定其名称、显示的标题、描述等属性。例如,下面是一个使用ProtoField.uint32定义的示例: local my_protocol_field = ProtoField.uint32("myprotocol.field", "My Protocol Field", "This is an example protocol field") 在上面的示例中,我们定义了一个名为"myprotocol.field"的协议字段,显示标题为"My Protocol Field",描述为"This is an example protocol field"。 我们还可以通过ProtoField.uint32创建的字段来访问和解析捕获的数据包。 当我们使用ProtoField.uint32定义协议字段后,我们可以通过调用Field对象的相应方法来访问和解析数据包中的该字段的值。例如,我们可以使用"my_protocol_field"字段对象的方法来访问和解析数据包中的协议字段: local my_protocol_field_extractor = my_protocol_field() 在上面的示例中,我们创建了一个名为"my_protocol_field_extractor"的字段提取器,它可以用于从捕获的数据包中提取和解析"my_protocol_field"字段的值。 通过使用ProtoField.uint32和相应的字段提取器,我们可以在Wireshark中编写更复杂的Lua插件,用于解析和分析各种不同的网络协议。这使得我们能够更好地理解和调试网络通信,并从中获取有用的信息。 总结起来,Wireshark Lua插件中的ProtoField.uint32可以让我们定义和访问无符号32位整数类型的协议字段,并通过字段提取器提取和解析数据包中的该字段的值。这为我们分析网络通信提供了便利,同时也为定位和解决网络问题提供了有力的工具。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值