From 92cb5a3defa8b7dfc233b7e7d5f73d2f9e75839a Mon Sep 17 00:00:00 2001 From: patrik Date: Tue, 10 Jan 2012 21:08:20 +0000 Subject: [PATCH] Fixed bug that would fail to calculate a PADI host unique value in the pppoe library under certain circumstances. Fixed bug that would fail to terminate script properly if no response was received from pppoe server. [Patrik] --- nselib/pppoe.lua | 11 +++++++++-- scripts/broadcast-pppoe-discover.nse | 4 +++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/nselib/pppoe.lua b/nselib/pppoe.lua index 72c526b67..d5576c9bb 100644 --- a/nselib/pppoe.lua +++ b/nselib/pppoe.lua @@ -434,12 +434,19 @@ PPPoE = { -- @param value string/number containing the tag value -- @return o instance of ConfigNak new = function(self, tags) + local c = tostring(coroutine.running()) + c = c:match("^thread: 0x(.*)"):sub(1, 8) + + math.randomseed(os.time()) + while ( #c < 8 ) do + c = c .. stdnse.tohex(math.random(255)) + end + local o = { header = PPPoE.Header:new(PPPoE.Code.PADI), tags = tags or { PPPoE.Tag:new(PPPoE.TagType.SERVICE_NAME), - PPPoE.Tag:new(PPPoE.TagType.HOST_UNIQUE, bin.pack("H", - tostring(coroutine.running()):match("^thread: 0x(........)"))) + PPPoE.Tag:new(PPPoE.TagType.HOST_UNIQUE, bin.pack("H", c)) } } setmetatable(o, self) diff --git a/scripts/broadcast-pppoe-discover.nse b/scripts/broadcast-pppoe-discover.nse index 20f81ea95..2c4164871 100644 --- a/scripts/broadcast-pppoe-discover.nse +++ b/scripts/broadcast-pppoe-discover.nse @@ -32,7 +32,9 @@ require 'pppoe' prerule = function() return true end local function fail(err) - return ("\n ERROR: %s"):format(err) + if ( err ) then + return ("\n ERROR: %s"):format(err) + end end local function mac_tostr(mac)