1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-10 17:59:04 +00:00

Factor out some clutter in dnsbl.lua

The constructor for DNS blacklist service objects was identical in every
case. Factoring it out will reduce errors and complexity.
This commit is contained in:
dmiller
2014-02-10 19:39:07 +00:00
parent 4ea4977a37
commit 4e7e7c04f0

View File

@@ -29,6 +29,20 @@ local table = require "table"
_ENV = stdnse.module("dnsbl", stdnse.seeall) _ENV = stdnse.module("dnsbl", stdnse.seeall)
-- Creates a new Service instance
-- @param ip host that needs to be checked
-- @param mode string (short|long) specifying whether short or long
-- results are to be returned
-- @param config service configuration in case this service provider
-- needs user supplied configuration
-- @return o instance of Helper
local function service_new (self, ip, mode, config)
local o = { ip = ip, mode = mode, config = config }
setmetatable(o, self)
self.__index = self
return o
end
-- The services table contains a list of valid DNSBL providers -- The services table contains a list of valid DNSBL providers
-- Providers are categorized in categories that should contain services that -- Providers are categorized in categories that should contain services that
-- do DNS blacklist checks for that particular category. -- do DNS blacklist checks for that particular category.
@@ -80,19 +94,7 @@ SERVICES = {
["short"] = "A", ["short"] = "A",
["long"] = "TXT", ["long"] = "TXT",
}, },
-- Creates a new Service instance new = service_new,
-- @param ip host that needs to be checked
-- @param mode string (short|long) specifying whether short or long
-- results are to be returned
-- @param config service configuration in case this service provider
-- needs user supplied configuration
-- @return o instance of Helper
new = function(self, ip, mode, config)
local o = { ip = ip, mode = mode, config = config }
setmetatable(o, self)
self.__index = self
return o
end,
-- Sample fmt_query function, if no function is specified, the library -- Sample fmt_query function, if no function is specified, the library
-- will assume that the IP should be reversed add suffixed with the -- will assume that the IP should be reversed add suffixed with the
-- service name. -- service name.
@@ -118,24 +120,14 @@ SERVICES = {
ns_type = { ns_type = {
["short"] = "A" ["short"] = "A"
}, },
new = function(self, ip, mode, config) new = service_new,
local o = { ip = ip, mode = mode, config = config }
setmetatable(o, self)
self.__index = self
return o
end,
resp_parser = function(self, r) resp_parser = function(self, r)
return ( r[1] == "127.0.0.6" and { state = "SPAM" } ) return ( r[1] == "127.0.0.6" and { state = "SPAM" } )
end, end,
}, },
["bl.nszones.com"] = { ["bl.nszones.com"] = {
new = function(self, ip, mode, config) new = service_new,
local o = { ip = ip, mode = mode, config = config }
setmetatable(o, self)
self.__index = self
return o
end,
resp_parser = function(self, r) resp_parser = function(self, r)
local responses = { local responses = {
["127.0.0.2"] = "SPAM", ["127.0.0.2"] = "SPAM",
@@ -146,12 +138,7 @@ SERVICES = {
}, },
["all.spamrats.com"] = { ["all.spamrats.com"] = {
new = function(self, ip, mode, config) new = service_new,
local o = { ip = ip, mode = mode, config = config }
setmetatable(o, self)
self.__index = self
return o
end,
resp_parser = function(self, r) resp_parser = function(self, r)
local responses = { local responses = {
["127.0.0.36"] = "DYNAMIC", ["127.0.0.36"] = "DYNAMIC",
@@ -162,12 +149,7 @@ SERVICES = {
}, },
["list.quorum.to"] = { ["list.quorum.to"] = {
new = function(self, ip, mode, config) new = service_new,
local o = { ip = ip, mode = mode, config = config }
setmetatable(o, self)
self.__index = self
return o
end,
resp_parser = function(self, r) resp_parser = function(self, r)
-- this service appears to return 127.0.0.0 when the service is -- this service appears to return 127.0.0.0 when the service is
-- "blocked because it has never been seen to send mail". -- "blocked because it has never been seen to send mail".
@@ -178,12 +160,7 @@ SERVICES = {
}, },
["sbl.spamhaus.org"] = { ["sbl.spamhaus.org"] = {
new = function(self, ip, mode, config) new = service_new,
local o = { ip = ip, mode = mode, config = config }
setmetatable(o, self)
self.__index = self
return o
end,
resp_parser = function(self, r) resp_parser = function(self, r)
local responses = { local responses = {
["127.0.0.2"] = "SPAM", ["127.0.0.2"] = "SPAM",
@@ -194,12 +171,7 @@ SERVICES = {
}, },
["bl.spamcop.net"] = { ["bl.spamcop.net"] = {
new = function(self, ip, mode, config) new = service_new,
local o = { ip = ip, mode = mode, config = config }
setmetatable(o, self)
self.__index = self
return o
end,
resp_parser = function(self, r) resp_parser = function(self, r)
local responses = { local responses = {
["127.0.0.2"] = "SPAM", ["127.0.0.2"] = "SPAM",
@@ -209,12 +181,7 @@ SERVICES = {
}, },
["dnsbl.ahbl.org"] = { ["dnsbl.ahbl.org"] = {
new = function(self, ip, mode, config) new = service_new,
local o = { ip = ip, mode = mode, config = config }
setmetatable(o, self)
self.__index = self
return o
end,
resp_parser = function(self, r) resp_parser = function(self, r)
local responses = { local responses = {
["127.0.0.4"] = "SPAM", ["127.0.0.4"] = "SPAM",
@@ -228,12 +195,7 @@ SERVICES = {
}, },
["l2.apews.org"] = { ["l2.apews.org"] = {
new = function(self, ip, mode, config) new = service_new,
local o = { ip = ip, mode = mode, config = config }
setmetatable(o, self)
self.__index = self
return o
end,
resp_parser = function(self, r) resp_parser = function(self, r)
local responses = { local responses = {
["127.0.0.2"] = "SPAM", ["127.0.0.2"] = "SPAM",
@@ -247,12 +209,7 @@ SERVICES = {
PROXY = { PROXY = {
["dnsbl.tornevall.org"] = { ["dnsbl.tornevall.org"] = {
new = function(self, ip, mode, config) new = service_new,
local o = { ip = ip, mode = mode, config = config }
setmetatable(o, self)
self.__index = self
return o
end,
resp_parser = function(self, r) resp_parser = function(self, r)
if ( "short" == self.mode and r[1] ) then if ( "short" == self.mode and r[1] ) then
return { state = "PROXY" } return { state = "PROXY" }
@@ -286,12 +243,7 @@ SERVICES = {
["port"] = "the port to which the target can relay to", ["port"] = "the port to which the target can relay to",
["ip"] = "the IP address to which the target can relay to" ["ip"] = "the IP address to which the target can relay to"
}, },
new = function(self, ip, mode, config) new = service_new,
local o = { ip = ip, mode = mode, config = config }
setmetatable(o, self)
self.__index = self
return o
end,
fmt_query = function(self) fmt_query = function(self)
if ( not(self.config.port) or not(self.config.ip) ) then if ( not(self.config.port) or not(self.config.ip) ) then
return return
@@ -314,12 +266,7 @@ SERVICES = {
["short"] = "A", ["short"] = "A",
["long"] = "TXT", ["long"] = "TXT",
}, },
new = function(self, ip, mode, config) new = service_new,
local o = { ip = ip, mode = mode, config = config }
setmetatable(o, self)
self.__index = self
return o
end,
resp_parser = function(self, r) resp_parser = function(self, r)
local responses = { local responses = {
["127.0.0.100"] = "PROXY", ["127.0.0.100"] = "PROXY",
@@ -366,12 +313,7 @@ SERVICES = {
}, },
["dnsbl.ahbl.org"] = { ["dnsbl.ahbl.org"] = {
new = function(self, ip, mode, config) new = service_new,
local o = { ip = ip, mode = mode, config = config }
setmetatable(o, self)
self.__index = self
return o
end,
resp_parser = function(self, r) resp_parser = function(self, r)
local responses = { local responses = {
["127.0.0.3"] = "PROXY", ["127.0.0.3"] = "PROXY",
@@ -381,12 +323,7 @@ SERVICES = {
}, },
["http.dnsbl.sorbs.net"] = { ["http.dnsbl.sorbs.net"] = {
new = function(self, ip, mode, config) new = service_new,
local o = { ip = ip, mode = mode, config = config }
setmetatable(o, self)
self.__index = self
return o
end,
resp_parser = function(self, r) resp_parser = function(self, r)
local responses = { local responses = {
["127.0.0.2"] = "PROXY", ["127.0.0.2"] = "PROXY",
@@ -396,12 +333,7 @@ SERVICES = {
}, },
["socks.dnsbl.sorbs.net"] = { ["socks.dnsbl.sorbs.net"] = {
new = function(self, ip, mode, config) new = service_new,
local o = { ip = ip, mode = mode, config = config }
setmetatable(o, self)
self.__index = self
return o
end,
resp_parser = function(self, r) resp_parser = function(self, r)
local responses = { local responses = {
["127.0.0.3"] = "PROXY", ["127.0.0.3"] = "PROXY",
@@ -411,12 +343,7 @@ SERVICES = {
}, },
["misc.dnsbl.sorbs.net"] = { ["misc.dnsbl.sorbs.net"] = {
new = function(self, ip, mode, config) new = service_new,
local o = { ip = ip, mode = mode, config = config }
setmetatable(o, self)
self.__index = self
return o
end,
resp_parser = function(self, r) resp_parser = function(self, r)
local responses = { local responses = {
["127.0.0.4"] = "PROXY", ["127.0.0.4"] = "PROXY",
@@ -432,12 +359,7 @@ SERVICES = {
configuration = { configuration = {
["apikey"] = "the http:BL API key" ["apikey"] = "the http:BL API key"
}, },
new = function(self, ip, mode, config) new = service_new,
local o = { ip = ip, mode = mode, config = config }
setmetatable(o, self)
self.__index = self
return o
end,
fmt_query = function(self) fmt_query = function(self)
if ( not(self.config.apikey) ) then if ( not(self.config.apikey) ) then
return return
@@ -522,12 +444,7 @@ SERVICES = {
}, },
["all.bl.blocklist.de"] = { ["all.bl.blocklist.de"] = {
new = function(self, ip, mode, config) new = service_new,
local o = { ip = ip, mode = mode, config = config }
setmetatable(o, self)
self.__index = self
return o
end,
resp_parser = function(self, r) resp_parser = function(self, r)
local responses = { local responses = {
["127.0.0.2"] = "Amavis", ["127.0.0.2"] = "Amavis",