Ask Your Question
0

proto_new there cannot be two protocols with the same name

asked 2021-10-19 12:45:20 +0000

rneustad gravatar image

updated 2021-10-19 13:27:01 +0000

grahamb gravatar image

Hi there!

I am using Wireshark Version 3.0.2 .

I created new protocol dissector and get the same error msg: proto_new there cannot be two protocols with the same name.

I tried with:

MQTTPROTO = Proto.new("mqtt_new", "MQ Telemetry Transport New")

and

MQTTPROTO = Proto("mqtt_new", "MQ Telemetry Transport New")

both options throw exception.

edit retag flag offensive close merge delete

Comments

This works fine for me. Do you have more than one .lua file with the same "mqtt_new" name?

cmaynard gravatar imagecmaynard ( 2021-10-19 14:21:05 +0000 )edit

Any reason why you try to add a disssector to an old version?

hugo.vanderkooij gravatar imagehugo.vanderkooij ( 2021-10-19 14:21:24 +0000 )edit

@cmaynard I have a single file with this name. Maybe Wireshark use cheche somewhere? I reopen the app but no success

rneustad gravatar imagerneustad ( 2021-10-19 14:47:23 +0000 )edit

@hugo.vanderkooij I don't understand what do you mean by "add a dissector to an old version". What do you mean? I want that in case of specific code in the packet to process the rest of the packet with costumed MQTT protocol.

if buffer(0,1):uint() == 0x1 then dofile([[path_to_lua_dissector_file]])

What I did wrong?

rneustad gravatar imagerneustad ( 2021-10-19 14:49:20 +0000 )edit

You're working with Wireshark 3.0.2, which went EOL last year (See https://gitlab.com/wireshark/wireshar...), so @hugo.vanderkooij is wondering why you're not working with a newer version of Wireshark such as 3.4.9, which is currently the latest stable version of Wireshark.

cmaynard gravatar imagecmaynard ( 2021-10-19 15:03:25 +0000 )edit

I think we need to see more of the code to check if this is being called in a second pass.
To generate the error message manually, copy to the Tools->Lua->Evaluate window and Evaluate twice.

Chuckc gravatar imageChuckc ( 2021-10-19 15:14:10 +0000 )edit
    -- Create a new dissector 
    MQTTPROTO = Proto.new("mqtt_new", "New implementation for MQTT protocol!")

    -- Fix header: 6 bytes
    local X = ProtoField.uint16("mqtt_new.x", "X", base.DEC)
    local Y = ProtoField.uint32("mqtt_new.y", "Y", base.DEC)

    -- register fields
    MQTTPROTO.fields = {X, Y}

    -- callback function for the dissector
    function MQTTPROTO.dissector(buffer, pinfo, tree)
        -- Debug msg
        dprint2("MQTTPROTO.dissector called")

        -- set the protocol column to show protocol name
        pinfo.cols.protocol:set("MQTTPROTO")

        -- length of the packet buffer (Tvb).
        local pktlen = buffer:reported_length_remaining()

        local proto_tree = tree:add(MQTTPROTO, buffer:range(40, pktlen))
        proto_tree:add_packet_field(X, buffer(0, 2), ENC_LITTLE_ENDIAN)
        proto_tree:add_packet_field(Y, buffer(2, 4), ENC_LITTLE_ENDIAN)
    end

    -- Register the dissector
    udp_port_table = DissectorTable.get("tcp.port")
    udp_port_table:add_for_decode_as(MQTTPROTO)

--[[ Evaluated --]]

@Chuckc the script works fine in the manual evaluation. B.T.W I update Wireshark to 3.4.9

rneustad gravatar imagerneustad ( 2021-10-19 15:48:39 +0000 )edit

If you're on Windows, what output do you get when you run:

findstr /r /s /m "Proto.*\"mqtt_new\"" %APPDATA%\Wireshark\plugins\*.lua

Or run something like so if you're on *nix:

grep -rl 'Proto.*"mqtt_new"' /path/to/Wireshark/plugins/
cmaynard gravatar imagecmaynard ( 2021-10-19 16:10:36 +0000 )edit

FINDSTR: No search strings

rneustad gravatar imagerneustad ( 2021-10-19 16:14:44 +0000 )edit

I don't think you entered the command properly.

cmaynard gravatar imagecmaynard ( 2021-10-19 16:18:26 +0000 )edit

PS C:\Users\XXXXX\AppData\Roaming\Wireshark> findstr /r /s /m "Proto.*\"mqtt_new\"" plugins*.lua FINDSTR: No search strings

I just used your command

rneustad gravatar imagerneustad ( 2021-10-19 16:21:38 +0000 )edit

Commented out the dprint2 and changed the range to (0, pktlen) and works.
@cmaynard might be on to something with the check to see if the function exists in other files.
The udp_port_table variable for the tcp.port table is really messing with my OCD. :-)

-- https://ask.wireshark.org/question/24883/proto_new-there-cannot-be-two-protocols-with-the-same-name
-- Create a new dissector 
MQTTPROTO = Proto.new("mqtt_new", "New implementation for MQTT protocol!")

-- Fix header: 6 bytes
local X = ProtoField.uint16("mqtt_new.x", "X", base.DEC)
local Y = ProtoField.uint32("mqtt_new.y", "Y", base.DEC)

-- register fields
MQTTPROTO.fields = {X, Y}

-- callback function for the dissector
function MQTTPROTO.dissector(buffer, pinfo, tree)
    -- Debug msg
--    dprint2("MQTTPROTO.dissector called")

    -- set the protocol column to show protocol name
    pinfo.cols.protocol:set("MQTTPROTO")

    -- length of the packet buffer (Tvb).
    local pktlen = buffer:reported_length_remaining()

    local proto_tree = tree:add(MQTTPROTO, buffer:range(0, pktlen))
    proto_tree:add_packet_field(X, buffer(0, 2), ENC_LITTLE_ENDIAN)
    proto_tree ...
(more)
Chuckc gravatar imageChuckc ( 2021-10-19 16:22:00 +0000 )edit

Can you try running the findstr command from a command prompt instead of from Powershell?

cmaynard gravatar imagecmaynard ( 2021-10-19 16:25:25 +0000 )edit

@Chuckc I made the changes you mention. Thanks but it didn't help. i still get: bad argument #1 to 'new' (Proto_new:there cannot be two protocols with the same name)) (The mistakes you displayed are after the first line. and the error occurs there...)

rneustad gravatar imagerneustad ( 2021-10-19 16:29:52 +0000 )edit

@cmaynard Actually I run this cmmand from both terminals, CMD and Powershell. I got the same empty result

rneustad gravatar imagerneustad ( 2021-10-19 16:31:27 +0000 )edit

You should at least get a match for the file containing the code you pasted above. Where is your mqtt_new.lua file stored if not in %APPDATA%\Wireshark\plugins\?

BTW, here's a Powershell command you can run instead if you prefer, but of course replace the path with the path to your Lua plugin:

Get-ChildItem -Path $Env:APPDATA\Wireshark\plugins -Recurse | Select-String -Pattern "Proto.*mqtt_new" -List
cmaynard gravatar imagecmaynard ( 2021-10-19 16:39:39 +0000 )edit

(If Wireshark program directory not in PATH, will need to use full path to run it)

C:\>tshark -G folders | findstr /I lua
Personal Lua Plugins:   C:\Users\admin\AppData\Roaming\Wireshark\plugins
Global Lua Plugins:     C:\Program Files\Wireshark\plugins

C:\>tshark -G plugins | findstr /I lua
mqtt_new.lua            lua script      C:\Users\admin\AppData\Roaming\Wireshark\plugins\mqtt_new.lua
Chuckc gravatar imageChuckc ( 2021-10-19 16:43:53 +0000 )edit

Now I got:

Get-ChildItem -Path . -Recurse | Select-String -Pattern "Proto.*mqtt*" -List

20 Applications\mqtt_new.lua:4: MQTTPROTO = Proto.new("mqtt_new", "New implementation for MQTT protocol!")
rneustad gravatar imagerneustad ( 2021-10-19 16:47:02 +0000 )edit

And you searched in both the "Personal Lua Plugins" folder and the "Global Lua Plugins" folder?

cmaynard gravatar imagecmaynard ( 2021-10-19 16:49:09 +0000 )edit

Yes, I searched also in the global. I don't think this is the issue, because I tried several protocol names that couldn't exists before. I saw in the googling that Wireshark loads some scripts twice in the init. lua file/ Does it make sense? How should I prevent this behavior?

rneustad gravatar imagerneustad ( 2021-10-19 17:09:58 +0000 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-10-19 17:59:59 +0000

cmaynard gravatar image

Where is this being called from?

if buffer(0,1):uint() == 0x1 then dofile([[path_to_lua_dissector_file]])

Because I think that is likely the source of your problem. Your "mqtt_new" dissector is already registered but here you seem to be explicitly loading it again. Don't do that.

edit flag offensive delete link more

Comments

Ho! That makes sense! so I should I call this file? The line appears in another protocol which works fine! (All the header is processed as expected, but when the it should load the new mqtt protocol there is an error)

rneustad gravatar imagerneustad ( 2021-10-19 18:15:57 +0000 )edit

Maybe something like this?

if buffer(0,1):uint() == 0x1 then
    Dissector.get("mqtt_new"):call(tvb, pinfo, tree)
end
cmaynard gravatar imagecmaynard ( 2021-10-19 18:22:36 +0000 )edit

tvb is just the typical "testy virtual buffer" name. You need to create the actual tvb from your buffer, i.e., the part of the buffer that gets passed to your "mqtt_new" dissector.

cmaynard gravatar imagecmaynard ( 2021-10-19 18:41:54 +0000 )edit
1

Thank you very much! It works!!!

rneustad gravatar imagerneustad ( 2021-10-19 18:43:18 +0000 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-10-19 12:45:20 +0000

Seen: 1,753 times

Last updated: Oct 19 '21