Add new dns modules
This commit is contained in:
51
modules/dev/dns-ns.lua
Normal file
51
modules/dev/dns-ns.lua
Normal file
@@ -0,0 +1,51 @@
|
||||
-- Description: Add a domains NS records to scope
|
||||
-- Version: 0.1.0
|
||||
-- License: GPL-3.0
|
||||
-- Source: domains
|
||||
|
||||
function strip_root_dot(name)
|
||||
local m = regex_find("(.+)\\.$", name)
|
||||
if last_err() then return end
|
||||
|
||||
if m == nil then
|
||||
return name
|
||||
else
|
||||
return m[2]
|
||||
end
|
||||
end
|
||||
|
||||
function each(r)
|
||||
local name = strip_root_dot(r)
|
||||
local domain = psl_domain_from_dns_name(name)
|
||||
if last_err() then return end
|
||||
|
||||
-- add domain
|
||||
local domain_id = db_add('domain', {
|
||||
value=domain,
|
||||
})
|
||||
if last_err() then return end
|
||||
if domain_id == nil then return end
|
||||
|
||||
-- add subdomain
|
||||
local subdomain_id = db_add('subdomain', {
|
||||
domain_id=domain_id,
|
||||
value=name,
|
||||
})
|
||||
if last_err() then return end
|
||||
end
|
||||
|
||||
function run(arg)
|
||||
local records = dns(arg['value'], {
|
||||
record='NS',
|
||||
})
|
||||
if last_err() then return end
|
||||
if records['error'] ~= nil then return end
|
||||
records = records['answers']
|
||||
|
||||
for i=1, #records do
|
||||
local r = records[i][2]
|
||||
debug(r)
|
||||
each(r['NS'])
|
||||
if last_err() then return end
|
||||
end
|
||||
end
|
||||
46
modules/dev/tld-scan.lua
Normal file
46
modules/dev/tld-scan.lua
Normal file
@@ -0,0 +1,46 @@
|
||||
-- Description: Search for the same domain base on all TLDs
|
||||
-- Version: 0.1.0
|
||||
-- License: GPL-3.0
|
||||
-- Source: domains
|
||||
|
||||
function run(arg)
|
||||
local m = regex_find('^([^\\.]+)\\.', arg['value'])
|
||||
local base = m[2]
|
||||
|
||||
-- TODO: we need a way to cache this
|
||||
-- TODO: .co.uk is missing
|
||||
local url = 'https://data.iana.org/TLD/tlds-alpha-by-domain.txt'
|
||||
|
||||
local session = http_mksession()
|
||||
local req = http_request(session, 'GET', url, {})
|
||||
local resp = http_send(req)
|
||||
if last_err() then return end
|
||||
if resp['status'] ~= 200 then
|
||||
return 'http error: ' .. resp['status']
|
||||
end
|
||||
|
||||
local tlds = regex_find_all('([^\n]+)', resp['text'])
|
||||
|
||||
for i=1, #tlds do
|
||||
local tld = tlds[i][1]:lower()
|
||||
|
||||
if not tld:match('^#') then
|
||||
local domain = base .. '.' .. tld
|
||||
|
||||
debug(domain)
|
||||
records = dns(domain, {
|
||||
record='NS',
|
||||
})
|
||||
if last_err() then
|
||||
clear_err()
|
||||
else
|
||||
if records['error'] == nil and records['answers'][1] then
|
||||
debug(records)
|
||||
db_add('domain', {
|
||||
value=domain,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user