1. Post-dissector

post-dissector和dissector不同,它会在所有dissectors都执行过后再被执行,这也就post前缀的由来。post-dissector的构建方式和dissector差不多,主要一个区别是注册的方式,post-dissector调用的是register_postdissetor接口。下面给出两个示例。

1.1 最简单的Post-dissector

这个示例主要是演示post-dissector脚本的骨架,它的功能是在packet list的所有info列加上了一个字符串"hello world"。

-- @brief A simple post-dissector, just append string to info column
-- @author zzq
-- @date 2015.08.13 local myproto = Proto("hello","Dummy proto to edit info column") -- the dissector function callback
function myproto.dissector(tvb,pinfo,tree)
pinfo.cols.info:append(" hello world")
end -- register our new dummy protocol for post-dissection
register_postdissector(myproto)

此插件运行效果如下图:

1.2 识别协议特征

这个示例简单地演示了如何使用post-dissector来识别协议特征。例子中,通过识别tcp载荷中是否含有字符串”weibo“来判断报文是否为weibo报文,如果是,则在packet list的protocol列标出,并在proto tree添加树节点,给出滑动特征在TCP载荷中的位置。

代码如下,其中有好多小问题,但这不是重点,重点是了解如何编写Lua插件。

-- @brief A post-dissector, to indentify pattern in payload
-- @author zzq
-- @date 2015.08.26 local weibo = Proto("weibo", "Weibo Service") local function get_payload_offset(data, proto_type)
local mac_len = ;
local total_len;
local ip_len = (data(, ):uint() - ) * ;
if (proto_type == 0x06) then
local tcp_len = (data(, ):uint()/) * ;
total_len = mac_len + ip_len + tcp_len;
elseif (proto_type == 0x11) then
local udp_len = ;
total_len = mac_len + ip_len + udp_len;
end
return total_len
end -- the dissector function callback
function weibo.dissector(tvb, pinfo, tree)
local proto_type = tvb(, ):uint();
if(proto_type ~= 0x06) then
return
end local offset = get_payload_offset(tvb, proto_type)
local data = tvb(offset):string();
local i, j = string.find(data, "weibo")
if(i) then
pinfo.cols.protocol = weibo.name
local subtree = tree:add(weibo, tvb(offset+i-))
subtree:append_text(", ptn_pos: " .. i .. "-" .. j)
end
end -- register our plugin for post-dissection
register_postdissector(weibo)

运行效果如下图。

2. Listener

Listner用来设置一个监听条件,当这个条件发生时,执行事先定义的动作。

实现一个Listner插件至少要实现以下接口:

  • 创建Listener
    listener = Listener.new([tap], [filter]),其中tap, filter分别是tap和过滤条件
  • listener.packet
    在条件命中时调用
  • listener.draw
    在每次需要重绘GUI时调用
  • listener.reset
    清理时调用

以上实现代码一般都包在一个封装函数中,最后把这个函数注册到GUI菜单:

register_menu(name, action, [group])

下面的示例代码对pcap文件中的http报文进行了简单的计数统计:

-- @brief a simple Listener plugin
-- @author zzq
-- @date 2015.08.13 local function zzq_listener()
local pkts =
local win = TextWindow.new("zzq Listener")
local tap = Listener.new(nil, "http") win:set_atclose(function() tap:remove() end) function tap.packet (pinfo, tvb, tapinfo)
pkts = pkts +
end function tap.draw()
win:set("http pkts: " .. pkts)
end function tap.reset()
pkts =
end -- Rescan all packets and just run taps - don’t reconstruct the display.
retap_packets()
end register_menu("freeland/zzq Listener", zzq_listener, MENU_STAT_GENERIC)

要查看运行结果,要选择”Statistics“菜单中的freeland/zzq Listerner子菜单来触发。此插件的运行效果如下图:

【wireshark】插件开发(四):Lua插件Post-dissector和Listener的更多相关文章

  1. Wireshark使用drcom_2011.lua插件协助分析drcom协议

    drcom_2011.lua是来源于Google code上的一个开源项目中的一个插件,感谢网络大神的分享 需要使用drcom_2011.lua分析drcom协议的话,需要把drcom_2011.lu ...

  2. 基于Lua插件化的Pcap流量监听代理

    1.前言 我们在实际工作中,遇到了一个这样的用例,在每天例行扫描活动中,发现有些应用系统不定期的被扫挂,因为我们不是服务的制造者,没有办法在不同的系统里打印日志,所以我们就想用一个工具来获取特定服务的 ...

  3. word插件开发 运行时,插件不启动.

      word插件开发 运行时,插件不启动. 查看插件信息时. 在禁用的应用程序加载项中.   启动禁用的插件: 点击转到.  选择你要启动的插件就可以了.

  4. Visual Studio2012 Lua插件--BabeLua

    之前,找了好久VS2012的Lua插件,没有找到. 今天在http://www.cocoachina.com/bbs/read.php? tid-205043.html 看到了.cocos2dx-qu ...

  5. Lua IDE工具-Intellij IDEA+lua插件配置教程(Chianr出品)

    Lua 编译工具IDE-Intellij IDEA 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Ch ...

  6. 【eclipse插件开发实战】 Eclipse插件开发5——时间插件Timer开发实例详解

    Eclipse插件开发5--时间插件Timer开发实例详解 这里做的TimeHelper插件设定为在菜单栏.工具栏提供快捷方式,需要在相应地方设置扩展点,最后弹出窗体显示时间. 在上一篇文章里创建好了 ...

  7. 【wireshark】插件开发(三):Lua插件 Dissector

    // TODO: 部分内容需要修改 1. 骨架 首先新建一个文件,命名为foo.lua,注意此文件的编码方式不能是带BOM的UTF8,否则wireshark加载它时会出错(不识别BOM): -- @b ...

  8. Jenkins插件开发(四)-- 插件发布

    上一篇blog介绍了插件开发中要注意的一些问题, 我们再来介绍插件开发完成后,如何上传到jenkins的插件中心(这里假设你的代码是放在github上的,使用svn或其他版本管理工具的请参考其他文章) ...

  9. jQuery插件开发,jquery插件

    关于jQuery插件的开发自己也做了少许研究,自己也写过多个插件,在自己的团队了也分享过一次关于插件的课.开始的时候整觉的很复杂的代码,现在再次看的时候就清晰了许多.这里我把我自己总结出来的东西分享出 ...

随机推荐

  1. 客户端、服务器端中JSON字符串与对象的转换

    客户端: 字符串转为对象:$.parseJSON(json); 对象转为字符串:JSON.stringify(_pasteDataItem) 服务器端(c#): 对象: [DataContract(N ...

  2. NSNotificationCenter 注意

    成对出现 意思很简单,NSNotificationCenter消息的接受线程是基于发送消息的线程的.也就是同步的,因此,有时候,你发送的消息可能不在主线程,而大家都知道操作UI必须在主线程,不然会出现 ...

  3. 2018.09.16 bzoj3626: [LNOI2014]LCA(树链剖分)

    传送门 树链剖分好题. 对于每个点维护一个值vi" role="presentation" style="position: relative;"&g ...

  4. xampp虚拟主机的配置

     ps:来源 https://blog.csdn.net/qq_17335153/article/details/52091869 一.修改httpd.conf   文件目录 xampp => ...

  5. MySQL优化Timeout: Pool empty. Unable to fetch a connection in 30 seconds, none available

    //查看所有进程 show processlist; //查询是否锁表 show OPEN TABLES where In_use > 0; //查看被锁住的 SELECT * FROM INF ...

  6. UVaLive 3353 Optimal Bus Route Design (最小费用流)

    题意:给定一个 n 个点的有向带权图,让你找若干个圈,使得每个结点恰好属于一个圈,并且总长度尽量小. 析:一开始想的是先缩点,先用DP,来求... 题解给的是最小费用流或者是最佳完全匹配,其实都是一样 ...

  7. Python之Pandas中Series、DataFrame

    Python之Pandas中Series.DataFrame实践 1. pandas的数据结构Series 1.1 Series是一种类似于一维数组的对象,它由一组数据(各种NumPy数据类型)以及一 ...

  8. Spring3.x错误----Bean named "txAdvice" must be of type[org.aopallibance.aop.Advice

    Spring3.x错误: 解决方法: aopalliance-1.0.jar 和 aopalliance-alpha1.jar之间的冲突.

  9. web service 项目 和 普通 web项目 的 区别

    web service 面向的是开发者(需要再次开发) 普通web 面向的是用户(直接使用)

  10. not allowed to access to crontab because of pam configuration

    如果运行crontab如遇下面这样的错误: $ crontab -l You (zhangsan) are not allowed to access to (crontab) because of ...