2019-04-16 05:52 AM
Good afternoon,
I am working on LUA script on top of proxy parsers to extract ports from url's among other things.
I have an issue working with integers, while strings are extracted properly.
Not to post full script here are the main parts, which work fine in LUA IDE, but have issues with integers in SA:
-Sample target, need to extract 8080:
example.com:8080/path/file
-I define target metakey:
nwlanguagekey.create("ip.dstport")
-Then I extract it as string (just a sample from code to get the idea):
ip_dstport= string.sub(fullpath, firstColon + 1, firstSlash - 1)
-Then I assign to nwdb metakey and do some checks:
if ip_dstport and not (ip_dstport == nil or ip_dstport == "") then
nw.createMeta(self.keys["ip.dstport"], tonumber(ip_dstport))
end
- Type check returns number:
print(type(tonumber(ip_dstport)))
number
- When I deploy this in SA I get the following:
Invalid registered lua key 'ip.dstport' type specified for parser XXX. Got 'Text' expected 'Uint16'
- table-map.xml:
<mapping envisionName="dport" nwName="ip.dstport" flags="None" format="UInt16" envisionDisplayName="ForeignPort|DestinationPort" nullTokens="-|(null)|null"/>
While other string based extractions are working in SA fine in same parser. So how do you work with integers in LUA-NWDB setup? Why is it treating number as integer and how to convert from LUA number/string to NWDB UInt16?
I can of course use string based metakeys instead for port extraction, but it would be nice to unify LUA extraction with existing meta model and to put ip.dstport to ip.dstport not to ip.dstport.string or something.
Maybe I can convert string to ip.dstport via some table map or index magic?
2019-04-16 09:00 AM
In your key declaration in setKeys specify the format of the key if it isn't Text.
For a UInt16 format key, e.g.
nwlanguagekey.create("ip.dstport", nwtypes.UInt16)
The full list of nwtypes is in nw-api.lua (included with the parsers book).
2019-04-16 09:00 AM
In your key declaration in setKeys specify the format of the key if it isn't Text.
For a UInt16 format key, e.g.
nwlanguagekey.create("ip.dstport", nwtypes.UInt16)
The full list of nwtypes is in nw-api.lua (included with the parsers book).
2019-05-13 05:06 AM
Hello William,
Thanks for the tip, did some modifications now the destination ports are extracted from url's properly. Handy for ftp over http extractions for example.
Definition:
nwlanguagekey.create("ip.dstport", nwtypes.UInt16)
And additional check + assignment:if ip_dstport and tonumber(ip_dstport) ~= nil then
nw.createMeta(self.keys["ip.dstport"], ip_dstport)
And thanks a lot for the book, very helpful for LUA development!