Detailed Description: Use Lua to compile the Wireshark Dissector plug-in

Source: Internet
Author: User

UseLuaWriteWiresharkOfDissectorIs the content to be introduced in this article,DissectorIt can be used to analyze and display specific protocols. It is useful when analyzing self-implemented application-layer protocols. DissectorPlug-insGenerally, C is used for implementation. For details, referWiresharkSource code in \ epan \ dissectors under the Code directory and the source code under the plugins directory.

Some simple dissector plug-ins that do not have high performance requirements can also be implemented using Lua. Wireshark has embedded support for Lua.

The following is a simple example:

Defines the Protocol. trivial filtering can be used in wireshark.

 
 
  1. trivial_proto = Proto("trivial","TRIVIAL","Trivial Protocol") 

Dissector Function

 
 
  1. function trivial_proto.dissector(buffer,pinfo,tree) 

For pinfo members, refer to the user manual.

 
 
  1. pinfo.cols.protocol = "TRIVIAL" 
  2. pinfo.cols.info = "TRIVIAL data" 
  3. local subtree = tree:add(trivial_proto,buffer(),"Trivial Protocol") 

Does not correspond to any data

 
 
  1. subtree:add(buffer(0,0),"Message Header: ") 

The version number corresponds to the first byte.

 
 
  1. subtree:add(buffer(0,1),"Version: " .. buffer(0,1):uint()) 

Type corresponds to the second byte

 
 
  1. type = buffer(1,1):uint()  
  2. type_str = "Unknown" 
  3. if type == 1 then  
  4.     type_str = "REQUEST" 
  5. elseif type == 2 then  
  6.     type_str = "RESPONSE" 
  7. end  
  8. subtree:add(buffer(1,1), "Type: " .. type_str) 

Data starting from the third byte

 
 
  1.     size = buffer:len()  
  2.     subtree:add(buffer(2,size-2), "Data: ")  
  3. end  
  4. tcp_table = DissectorTable.get("tcp.port") 

Register with tcp port 8888

 
 
  1. tcp_table:add(8888,trivial_proto) 

Plug-insAfter writing the script, keep it as the test. lua file. We can capture the package and test it.

Make sure that your Wireshark supports lua. If the directory contains the init. lua file, it indicates that Lua is supported. Next, you need to start the support for Lua. By default, the support for Lua is not started. Edit init. comment out the line "disable_lua = true;" in the lua file, and add a line of dofile ("test. lua "), so that Wireshark will automatically call test at startup. lua. You can also specify the script file to be executed on the command line, for example,Wireshark-X lua_script: test. lua ".

Summary: Usage DetailsLuaWriteWiresharkOfDissectorI hope this article will help you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.