wireshark.lua 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. -- declare our protocol
  2. gwlan_proto = Proto("gnunet","Gnunet Layer")
  3. -- create a function to dissect it
  4. local f = gwlan_proto.fields
  5. f.len = ProtoField.uint16 ("gnunet.len", "Gnunet Message Len")
  6. f.type = ProtoField.uint16 ("gnunet.type", "Gnunet Message Type")
  7. -- rhs_proto.fields.sequence = ProtoField.uint16("rhs.sequence","Sequence number")
  8. f_proto = DissectorTable.new("gnunet.proto", "Gnunet Protocoll", FT_UINT16, BASE_DEC)
  9. --gwlan_proto.fields = {f_len, f_type}
  10. function gwlan_proto.dissector(buffer,pinfo,tree)
  11. pinfo.cols.protocol = "Gnunet Packet"
  12. gnunet_packet_disector(buffer,pinfo,tree)
  13. end
  14. function gwlan_proto.init()
  15. end
  16. function gnunet_packet_disector(buffer,pinfo,tree)
  17. if (buffer:len() > 4) then
  18. local len = buffer(0,2):uint()
  19. local type = buffer(2,2):uint()
  20. if (len <= buffer:len()) then
  21. local dissect = f_proto:get_dissector(type)
  22. if dissect ~= nil then
  23. dissect:call(buffer(0, len):tvb(), pinfo, tree)
  24. else
  25. local subtree = tree:add(fragmentack, buffer(),"Gnunet Packet Type: " .. buffer(2,2):uint() .. "(" .. buffer:len() .. ")")
  26. gnunet_message_header(buffer, pinfo, subtree)
  27. end
  28. end
  29. --if (len < buffer:len()) then
  30. -- gwlan_proto.dissector(buffer(len, buffer:len() - len):tvb(), pinfo, tree)
  31. --end
  32. else
  33. if (buffer:len() == 4) then
  34. local subtree = tree:add(fragmentack, buffer(),"Gnunet Packet (" .. buffer:len() .. ")")
  35. gnunet_message_header(buffer, pinfo, subtree)
  36. end
  37. end
  38. end
  39. function gnunet_message_header(buffer, pinfo, tree)
  40. if (buffer:len() >= 4) then
  41. local len = buffer(0,2)
  42. local type = buffer(2,2)
  43. tree:add(buffer(0,2), "Message Len: " .. buffer(0,2):uint())
  44. tree:add(buffer(2,2), "Message Type: " .. buffer(2,2):uint())
  45. end
  46. end
  47. -- load the udp.port table
  48. llc_table = DissectorTable.get("llc.dsap")
  49. -- register our protocol to handle llc.dsap 0x1e
  50. llc_table:add(31,gwlan_proto)
  51. fragmentack = Proto("gnunet.fragmentack","Gnunet Fragment Ack")
  52. function fragmentack.dissector(buffer,pinfo,tree)
  53. pinfo.cols.protocol = "Gnunet Fragment Ack"
  54. local subtree = tree:add(fragmentack, buffer(),"Gnunet Data ack (" .. buffer:len() .. ")")
  55. gnunet_message_header(buffer, pinfo, subtree)
  56. if buffer:len() >= 16 then
  57. subtree:add(buffer(4,4),"Fragment Id: " .. buffer(4,4):uint())
  58. subtree:add(buffer(8,8),"Bits: " .. buffer(8,8))
  59. end
  60. end
  61. fragment = Proto("gnunet.fragment","Gnunet Fragment")
  62. function fragment.dissector(buffer,pinfo,tree)
  63. pinfo.cols.protocol = "Gnunet Fragment"
  64. local subtree = tree:add(fragment, buffer(),"Gnunet Fragment (" .. buffer:len() .. ")")
  65. gnunet_message_header(buffer, pinfo, subtree)
  66. if buffer:len() >= 13 then
  67. subtree:add(buffer(4,4),"Fragment Id: " .. buffer(4,4):uint())
  68. subtree:add(buffer(8,2),"Total Size: " .. buffer(8,2):uint())
  69. subtree:add(buffer(10,2),"Offset: " .. buffer(10,2):uint())
  70. if buffer(10,2):uint() == 0 then
  71. if (buffer(8,2):uint() <= buffer:len() - 12) then
  72. gnunet_packet_disector(buffer(12):tvb(),pinfo,tree)
  73. end
  74. else
  75. subtree:add(buffer(12), "Data: " .. buffer(12))
  76. end
  77. end
  78. end
  79. hello = Proto("gnunet.hello","Gnunet Hello Message")
  80. function hello.dissector(buffer,pinfo,tree)
  81. pinfo.cols.protocol = "Gnunet Hello Message"
  82. local subtree = tree:add(hello, buffer(),"Gnunet Hello Message (" .. buffer:len() .. ")")
  83. gnunet_message_header(buffer, pinfo, subtree)
  84. if buffer:len() > (264 + 8) then
  85. subtree:add(buffer(4,4),"Reserved: " .. buffer(4,4):uint())
  86. RsaPublicKeyBinaryEncoded(buffer(8 , 264):tvb(),pinfo, subtree)
  87. else
  88. subtree:add(buffer(4), "SIZE WRONG (< 272)")
  89. end
  90. end
  91. wlan = Proto("gnunet.wlan","Gnunet WLAN Message")
  92. function wlan.dissector(buffer,pinfo,tree)
  93. pinfo.cols.protocol = "Gnunet WLAN Message"
  94. local subtree = tree:add(wlan, buffer(),"Gnunet WLAN Message (" .. buffer:len() .. ")")
  95. gnunet_message_header(buffer, pinfo, subtree)
  96. if buffer:len() > (4 + 4 + 2*64) then
  97. subtree:add(buffer(4,4),"CRC: " .. buffer(4,4):uint())
  98. local peer = GNUNET_PeerIdentity(buffer(8,64), pinfo, subtree)
  99. peer:append_text(" Traget")
  100. peer = GNUNET_PeerIdentity(buffer(8 + 64,64), pinfo, subtree)
  101. peer:append_text(" Source")
  102. else
  103. subtree:add(buffer(8), "SIZE WRONG (< 4 + 4 + 2*64)")
  104. end
  105. if (buffer:len() - (4 + 4 + 2*64) > 0) then
  106. gnunet_packet_disector(buffer(4 + 4 + 2*64):tvb(),pinfo,tree)
  107. end
  108. end
  109. function RsaPublicKeyBinaryEncoded(buffer,pinfo,tree)
  110. local subtree = tree:add(gwlan_proto,buffer(),"Gnunet RsaPublicKeyBinaryEncoded(" .. buffer:len() .. ")")
  111. subtree:add(buffer(0,2),"Len: " .. buffer(0,2):uint())
  112. subtree:add(buffer(2,2),"Sizen: " .. buffer(2,2):uint())
  113. subtree:add(buffer(4,258),"Pub Key: " .. buffer(4,258))
  114. subtree:add(buffer(262,2),"Padding: " .. buffer(262,2):uint())
  115. end
  116. function GNUNET_PeerIdentity(buffer,pinfo,tree)
  117. local subtree = tree:add(gwlan_proto,buffer(),"Gnunet PeerIdentity(" .. buffer:len() .. ")")
  118. subtree:add(buffer(0),"hashPubKey: " .. buffer(0))
  119. return subtree
  120. end
  121. transport_session_keepalive = Proto("gnunet.transport_session_keepalive","Gnunet transport session keepalive")
  122. function transport_session_keepalive.dissector(buffer,pinfo,tree)
  123. pinfo.cols.protocol = "Gnunet transport session keepalive"
  124. local subtree = tree:add(transport_session_keepalive, buffer(),"Gnunet transport session keepalive (" .. buffer:len() .. ")")
  125. gnunet_message_header(buffer, pinfo, subtree)
  126. end
  127. f_proto:add(43,wlan)
  128. f_proto:add(39,transport_session_keepalive)
  129. f_proto:add(19,fragmentack)
  130. f_proto:add(18,fragment)
  131. f_proto:add(16,hello)