-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrebinding.lua
30 lines (27 loc) · 1.08 KB
/
rebinding.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
pdnslog("pdns-recursor Lua script starting!", pdns.loglevels.Warning)
rfc1918 = newNMG()
rfc1918:addMask("0.0.0.0/8")
rfc1918:addMask("10.0.0.0/8")
rfc1918:addMask("127.0.0.0/8")
rfc1918:addMask("172.16.0.0/12")
rfc1918:addMask("192.168.0.0/16")
whitelistDomain = newDS()
whitelistDomain:add("domain1.com")
whitelistDomain:add("domain2.com")
function postresolve(dq)
local records = dq:getRecords()
for k,v in pairs(records) do
if whitelistDomain:check(dq.qname) then
pdnslog("Not blocking whitelisted domain: "..dq.qname:toString())
return true
end
if v.type == pdns.A and rfc1918:match(newCA(v:getContent()))
then
pdnslog("Blocking possible rebind on "..dq.qname:toString().." because of "..v:getContent().." request from "..dq.localaddr:toString())
dq.appliedPolicy.policyKind = pdns.policykinds.NODATA
v.ttl=1
end
end
dq:setRecords(records)
return true
end