使用lua给wireshark编写uTP的Dissector
- xx_protocol.dissector = function(buffer,pinfo,tree)
- --定义这个协议的解析函数,最后会将这个函数注册到wireshark用来解析数据的表中。这个函数的三个参数很重要,是wireshark引擎在调用该函数是会传入,
- --buffer就是我们要分析的数据,
- --pinfo记录了前面分析过协议留下的信息,
- --tree是用来在详细框中添加我们信息的结构。
- do
- -- Desc: uTP Protocol lua version
- -- Author: WangYao, ipconfigme@gmail.com
- -- Date: 2011/10/19
- -- protol name
- local p_utp = Proto("utp", "Micro Transport Protocol");
- -- protocol fields
- local f_version = ProtoField.uint8("utp.version", "Version", base.DEC,
- {[1]="V1"}, 0x0F)
- local f_type = ProtoField.uint8("utp.type", "Type", base.DEC,
- {[0]="ST_DATA", [1]="ST_FIN", [2]="ST_STATE", [3]="ST_RESET", [4]="ST_SYN"}, 0xF0)
- local f_next_extension_type = ProtoField.uint8("utp.next_extension_type", "Next Extension Type", base.DEC,
- {[0]="No Extension", [1]="Selective acks", [2]="Extension bits"})
- local f_extension_len = ProtoField.uint8("utp.extension_len", "Extension Length", base.DEC)
- local f_extension_bitmask = ProtoField.bytes("utp.extension_bitmask", "Extension Bitmask", base.NONE)
- local f_connection_id = ProtoField.uint16("utp.connection_id", "Connection_ID", base.DEC)
- local f_timestamp_microseconds = ProtoField.uint32("utp.timestamp_microseconds", "timestamp_microseconds", base.DEC)
- local f_timestamp_difference_microseconds = ProtoField.uint32("utp.timestamp_difference_microseconds", "timestamp_difference_microseconds", base.DEC)
- local f_wnd_size = ProtoField.uint32("utp.wnd_size", "wnd_size", base.DEC)
- local f_seq_nr = ProtoField.uint16("utp.seq_nr", "seq_nr", base.DEC)
- local f_ack_nr = ProtoField.uint16("utp.ack_nr", "ack_nr", base.DEC)
- p_utp.fields = {f_version, f_type, f_next_extension_type, f_extension_len, f_extension_bitmask, f_connection_id, f_timestamp_microseconds, f_timestamp_difference_microseconds, f_wnd_size, f_seq_nr, f_ack_nr}
- -- other dissector
- local data_dis = Dissector.get("data")
- local bittorrent_dissector = Dissector.get("bittorrent.tcp")
- -- utp dissector, return OFFSET
- local function utp_dissector(buf,pkt,root)
- local buf_len = buf:len()
- local offset = 0
- -- check pack len
- if buf_len < 20 then return 0 end
- -- get fields
- local v_version = buf(offset, 1)
- local v_type = buf(offset, 1)
- offset = offset + 1
- local v_next_extension_type = buf(offset, 1)
- offset = offset + 1
- local v_connection_id = buf(offset, 2)
- offset = offset + 2
- local v_timestamp_microseconds = buf(offset, 4)
- offset = offset + 4
- local v_timestamp_difference_microseconds = buf(offset, 4)
- offset = offset + 4
- local v_wnd_size = buf(offset, 4)
- offset = offset + 4
- local v_seq_nr = buf(offset, 2)
- offset = offset + 2
- local v_ack_nr = buf(offset, 2)
- offset = offset + 2
- -- check uTP
- local i_version = bit.band(v_version:uint(), 0x0F)
- -- local i_type = bit.band(bit.rshift(v_type:uint(), 4), 0x0F)
- local i_type = bit.rshift(bit.band(v_type:uint(), 0xF0), 4)
- if( (i_version~=1) or (i_type~=0 and i_type~=1 and i_type~=2 and i_type~=3 and i_type~=4))
- then return 0 end
- local subtree = root:add(p_utp, buf(),"Micro Transport Protocol")
- -- just add header
- subtree:add(buf(0,0),"uTP Header: ")
- subtree:add(f_version, v_version)
- subtree:add(f_type, v_type)
- subtree:add(f_next_extension_type, v_next_extension_type)
- subtree:add(f_connection_id, v_connection_id)
- subtree:add(f_timestamp_microseconds, v_timestamp_microseconds)
- subtree:add(f_timestamp_difference_microseconds, v_timestamp_difference_microseconds)
- subtree:add(f_wnd_size, v_wnd_size)
- subtree:add(f_seq_nr, v_seq_nr)
- subtree:add(f_ack_nr, v_ack_nr)
- -- add pkt info
- pkt.cols.protocol = "uTP"
- if(i_type==0) then
- pkt.cols.info = "uTP ST_DATA"
- elseif(i_type==1) then
- pkt.cols.info = "uTP ST_FIN"
- elseif(i_type==2) then
- pkt.cols.info = "uTP ST_STATE"
- elseif(i_type==3) then
- pkt.cols.info = "uTP ST_RESET"
- elseif(i_type==4) then
- pkt.cols.info = "uTP ST_SYN"
- else
- pkt.cols.info = "uTP UNKNOW"
- end
- while(v_next_extension_type:uint()~=0) do
- -- add extension tree
- local extendtree = subtree:add(p_utp, buf(offset, buf_len-offset):tvb(),"Extension")
- if(v_next_extension_type:uint()==0) then
- extendtree:append_text(": NO Extension")
- elseif(v_next_extension_type:uint()==1) then
- extendtree:append_text(": Selective acks")
- elseif(v_next_extension_type:uint()==2) then
- extendtree:append_text(": Extension bits")
- end
- v_next_extension_type = buf(offset, 1)
- offset = offset + 1
- extendtree:add(f_next_extension_type, v_next_extension_type)
- local v_extension_len = buf(offset, 1)
- offset = offset + 1
- extendtree:add(f_extension_len, v_extension_len)
- local i_extension_len = v_extension_len:int()
- local v_extension_bitmask = buf(offset, i_extension_len)
- offset = offset + i_extension_len
- extendtree:add(f_extension_bitmask, v_extension_bitmask)
- end
- return offset
- end
- -- check packet is bittorrent? header legal
- local function check_bittorrent(buf)
- local len = buf:len()
- local pack_len = buf(0,4)
- local pack_type
- if(len<4) then
- return false
- elseif(buf(0,1):uint()==19 and len==68) then --handshake
- return true
- elseif(len==4) then --keepalive
- if(pack_len:uint()==0) then return true
- else return false
- end
- else
- pack_type = buf(4,1)
- --choke, unchoke, interested, not interested, have all, have none
- if(pack_type:uint()==0 or pack_type:uint()==1 or pack_type:uint()==2 or pack_type:uint()==3 or pack_type:uint()==0x0E or pack_type:uint()==0x0F) then
- if(pack_len:uint()==1) then return true
- else return false
- end
- --request, cancel, reject
- elseif(pack_type:uint()==6 or pack_type:uint()==8 or pack_type:uint()==0x10) then
- if(pack_len:uint()==13) then return true
- else return false
- end
- --port
- elseif(pack_type:uint()==9) then
- if(pack_len:uint()==3) then return true
- else return false
- end
- --have, suggest, allowed fast
- elseif(pack_type:uint()==4 or pack_type:uint()==0x0D or pack_type:uint()==0x11) then
- if(pack_len:uint()==5) then return true
- else return false
- end
- --bitfield, extend
- elseif(pack_type:uint()==5 or pack_type:uint()==0x14) then
- if(pack_len:uint()<1024) then return true
- else return false
- end
- --piece, max than 16K
- elseif(pack_type:uint()==7) then
- if(pack_len:uint()>=16384) then return true
- else return false
- end
- else
- return false
- end
- end
- return false
- end
- -- protocol dissector, include bittorrent
- function p_utp.dissector(buf,pkt,root)
- local len = buf:len()
- local offset = utp_dissector(buf, pkt, root)
- if len>offset and offset>0 then
- -- call bittorrent dissector
- -- pass split PIECE pack
- if check_bittorrent(buf(offset, len-offset)) then
- bittorrent_dissector:call(buf(offset, len-offset):tvb(), pkt, root)
- else
- data_dis:call(buf(offset,len-offset):tvb(), pkt, root)
- end
- elseif offset==0 then
- -- call data dissector
- data_dis:call(buf,pkt,root)
- end
- end
- -- add to DissectorTable
- local udp_table = DissectorTable.get("udp.port")
- -- udp_table:add(4135, p_utp)
- udp_table:add(10000, p_utp)
- end
使用lua给wireshark编写uTP的Dissector的更多相关文章
- Lua 学习 chapter30 编写c函数的技巧 - Jow的博客
目录 数组操作 字符串操作 在c函数中保存状态 生活总需要一点仪式感,然后慢慢的像那个趋向完美的自己靠近. 数组操作 Lua中的数组就是以特殊的方式使用边.像lua_setttable and lua ...
- FCEUX金手指加强版 - 使用Lua脚本语言编写FC/NES金手指脚本
一直觉得大部分的FC/NES模拟器的作弊码金手指不是那么方便使用, 比如魂斗罗1代, 玩家的武器可以通过修改0xAA的值来改变: 0x11为M弹(重机枪),0x12为F弹(圈圈),0x13为S弹(散弹 ...
- Lua编写wireshark插件初探——解析Websocket上的MQTT协议
一.背景 最近在做物联网流量分析时发现, App在使用MQTT协议时往往通过SSL+WebSocket+MQTT这种方式与服务器通信,在使用SSL中间人截获数据后,Wireshark不能自动解析出MQ ...
- Wireshark lua dissector 对TCP消息包合并分析
应用程序发送的数据报都是流式的,IP不保证同一个一个应用数据包会被抓包后在同一个IP数据包中,因此对于使用自制dissector的时候需要考虑这种情况. Lua Dissector相关资料可以见:ht ...
- 【wireshark】插件开发(二):Lua插件开发介绍
1. Wireshark对Lua的支持 本节相关内容可参考Wireshark开发指南第10章”Lua Support in Wireshark”. Wireshark集成了Lua解释器,以支持Lua脚 ...
- Lua语言在Wireshark中使用(转)
1. 检查Wireshark的版本是否支持Lua 打开Wireshark,点击“HelpàAbout Wireshark”菜单,查看弹出的对话框,如果有“with Lua 5.1”表示支持 ...
- Wireshark使用drcom_2011.lua插件协助分析drcom协议
drcom_2011.lua是来源于Google code上的一个开源项目中的一个插件,感谢网络大神的分享 需要使用drcom_2011.lua分析drcom协议的话,需要把drcom_2011.lu ...
- 【wireshark】Wireshark原理分析与二次开发系列
1.版权声明 本系列文章是本人花了很多心血写成,wireshark本是开源软件,本人也乐于技术知识和经验的分享,更是欣赏和推崇开源精神,因此任何看到本文的人都可以随意转载,但只有一个要求: 在大段甚至 ...
- 采访 Lua 发明人的一篇文章
采访 Lua 发明人的一篇文章 来源 https://blog.codingnow.com/2010/06/masterminds_of_programming_7_lua.html <Mast ...
随机推荐
- HttpWebRequest提高效率之连接数,代理,自动跳转,gzip请求等设置问题
先设置4个: [csharp] webrequest.ServicePoint.Expect100Continue = false; //是否使用 Nagle 不使用 提高效率 webrequest. ...
- NCPC 2012 Galactic Warlords
湖南大学的oj上有这套比赛: 这题是个简单的计算几何,首先去掉重复的边,然后判断是否全部平行: 代码: #include<cstdio> #define maxn 105 using na ...
- leetcode面试准备: CountPrimes
1 题目 Description: Count the number of prime numbers less than a non-negative number, n. 接口:public in ...
- ASP.NET MVC 解决LINQ表达式中的SqlMethods 未找到命名空间问题
右键项目属性下的引用: 添加引用: 搜索寻找——System.Data.Linq,然后添加成功,即可解决LINQ表达式中的SqlMethods 未找到命名空间问题
- ELK之nginx日志分析图表创建
一.kibana面板介绍 Discover:查询数据Visualize:统计图表Dashboard:显示面板,添加相应的图表在面板中Settings:创建索引 二.图表创建 1.饼图创建 以创建一个状 ...
- Firebug控制台详解
转自:http://www.ruanyifeng.com/blog/2011/03/firebug_console_tutorial.html 作者: 阮一峰 日期: 2011年3月26日 Fireb ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(1)-前言与目录(持续更新中...)
转自:http://www.cnblogs.com/ymnets/p/3424309.html 曾几何时我想写一个系列的文章,但是由于工作很忙,一直没有时间更新博客.博客园园龄都1年了,却一直都是空空 ...
- C#/PHP Compatible Encryption (AES256) ZZ
Finding a way to encrypt messages in C# and decrypting them in PHP or vice versa seems to be a " ...
- 《C语言程序设计现代方法》第4章 表达式
C语言的一个特点就是它更多地强调表达式而不是语句,表达式是表示如何计算值的公式. 当表达式包含两个或更多个相同优先级的运算符时,运算符的结合性(associativity)开始发挥作用.如果运算符是从 ...
- CLR Profiler 性能分析工具 (转)
原文地址:http://www.cnblogs.com/kevinlzf/archive/2010/11/12/1876066.html 下载地址:http://www.microsoft.com/e ...