用于HTTP的Lua解析器,无法找到字符串结尾

时间:2019-03-05 22:50:49

标签: string http lua wireshark-dissector

我正在尝试使用lua在Wireshark的HTTP协议中分离字符串数据,但我没有成功找到字符串的结尾,这是我目前拥有的

HTTP_protocol = Proto("ourHTTP", "HTTPProtocol")

first =ProtoField.string("HTTP_protocol.first", "first", base.ASCII)
second =ProtoField.string("HTTP_protocol.second", "second", base.ASCII)
HTTP_protocol.fields = {first}

function HTTP_protocol.dissector(buffer, pinfo, tree)
 length = buffer:len()

 if length ==0 then return end
pinfo.cols.protocol = HTTP_protocol.name
local subtree = tree:add(HTTP_protocol, buffer(), "HTTPProtocol data ")
local string_length

for i = 0, length - 1, 1 do
  if (buffer(i,1):uint() == '\r') then
    string_length = i - 0
    break
  end
end
subtree:add(first, buffer(0,string_length))

end
porttable = DissectorTable.get("tcp.port")
porttable:add(80, HTTP_protocol)

我尝试搜索“ \ r”,“ \ 0”和“ \ n”,但是无论如何我仍然将所有输入的字符串作为一个输入。我在做错什么吗?

1 个答案:

答案 0 :(得分:1)

您可以改用0x0D。那是\r的ASCII码。所以最终会变成

if (buffer(i,1):uint() == 0x0D) then

在Wireshark中:

Picture of Wireshark with proper lineshift