Skip to content

Commit

Permalink
Add cname harvester
Browse files Browse the repository at this point in the history
  • Loading branch information
kpcyrd committed Nov 26, 2018
1 parent d495fc4 commit 56b914b
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions modules/dev/cname-harvest.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
-- Description: Query for CNAMES to find subdomains
-- Version: 0.1.0
-- Source: subdomains
-- License: GPL-3.0

function iter(r)
if r == nil then
return
end

m = regex_find("(.+)\\.$", r)
if last_err() then return end

if m == nil then
return
end
r = m[2]

domain = psl_domain_from_dns_name(r)
if last_err() then return end

domain_id = db_add('domain', {
value=domain,
})
if last_err() then return end

if domain_id ~= nil then
db_add('subdomain', {
domain_id=domain_id,
value=r,
})
if last_err() then return end
end
end

function run(arg)
records = dns(arg['value'], 'CNAME')
if last_err() then return end

if records['success'] == nil then return end
records = records['success']

-- there is a bug in struct -> lua that causes tables to be zero indexed
-- this checks if there's something at index 0 but uses index 1 if this is fixed
i = 0
if records[i] == nil then i = 1 end

while records[i] ~= nil do
r = records[i]['CNAME']
iter(r)
if last_err() then return end
i = i+1
end
end

0 comments on commit 56b914b

Please sign in to comment.