Nmap Development mailing list archives

Re: [NSE] KNX Gateway Discover Script


From: Daniel Miller <bonsaiviking () gmail com>
Date: Mon, 10 Aug 2015 08:20:17 -0500

Niklaus,

Thanks, this is looking better! Since the list keeps dropping your
messages, you may want to just link to your Github repository, in case it
is the attachments that are looking suspicious. We'll try to get it sorted
out soon.

Speaking of sorting, the method you've used will not work to sort the
output table, unfortunately. Lua's table.sort [1] only handles sorting
array-style tables; it won't look at non-integer keys at all. Plus,
stdnse.output_table ensures that the keys are always returned in the order
in which they were created. Here's a better way to do the same thing:

-- whatever process generates your output goes here
ip, result = get_some_results()
-- store the result by ip in a regular table
results = {}
results[ip] = result
-- store the ip in an array-style (integer key) table
ips = {}
ips[#ips+1] = ip

-- at the end, sort the output
table.sort(ips, function_derived_from_ipOps_compare_ip)
output = stdnse.output_table()
-- technically, ipairs doesn't have to yield results in sorted order,
either :(
for i in 1, #ips do
  local ip = ips[i]
  output[ip] = results[ip]
end

Dan

[1] http://www.lua.org/manual/5.2/manual.html#pdf-table.sort

On Sun, Aug 9, 2015 at 7:20 AM, Niklaus Schiess <nschiess () adversec com>
wrote:

Hi,

I just fixed the output ordering in both scripts and attached them. Thanks
for pointing this out, I was struggling with those Lua tables for quite
some time. In the discover version I also added sorting by IP addresses.

Regards,
Niklaus


On 09.08.2015 05:44, Daniel Miller wrote:

Niklaus,

Thanks for taking my suggestions! There's still a bit of a problem
regarding the use of output tables: we need the output of subsequent runs
of the script to be identical in ordering. That's what
stdnse.output_table() provides. A regular Lua table will yield its keys in
an unpredictable order, except for integer keys (array-style tables). This
means that any place where you store result["label"] = value, the result
table should be created as a stdnse.output_table(). Along with this, we
should sort the gateways by address. The ipOps library has some useful
comparison functions for sorting IP addresses.

I'm sorry that your messages to the list keep getting spam-filtered. We
will try to sort that out when Fyodor gets back from DEF CON. I'm really
looking forward to testing your unicast script soon!

Dan

On Sat, Aug 8, 2015 at 10:09 AM, Niklaus Schiess <nschiess () adversec com> <nschiess () adversec com>
wrote:


Hi,

thanks a lot for the feedback! I implemented all the suggestions and
attached the new version of the script.

Also, I already started to implement a unicast version which uses a
different message type to reliably detect gateways based on the suggestion
by Michael.

Regards,
Niklaus





_______________________________________________
Sent through the dev mailing listhttps://nmap.org/mailman/listinfo/dev
Archived at http://seclists.org/nmap-dev/


--
PGP FP: CB84 8C68 ADDB 6C50 7DF1 4227 F2A6 056A A799 76DA


_______________________________________________
Sent through the dev mailing list
https://nmap.org/mailman/listinfo/dev
Archived at http://seclists.org/nmap-dev/

Current thread: