kosuke_

adblock/db_backend

Jan 9th, 2016
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #!/usr/bin/python
  2. from sys import stdin, stdout,stderr
  3. from dns import resolver
  4. f=open('/etc/powerdns/domains')
  5. content = f.readlines()
  6. f.close
  7. hs=stdin.readline()
  8. stdout.write("OK\tbanner\n")
  9. stdout.flush();
  10. while True:
  11. f=0
  12. b=0
  13. s=0
  14. query=stdin.readline().strip();
  15. sp = query.split()
  16. if(sp[0]=="AXFR" or sp[0]=="PING"):
  17. s=1
  18.  
  19.  
  20. else:
  21. for domain in content:
  22. domain=domain.strip()
  23. if(sp[1]==domain or sp[1].endswith("."+domain)):
  24. print "FAIL"
  25. f=1
  26. b=1
  27. break
  28. if b==0 and s==0:
  29. res = resolver.Resolver()
  30. res.nameservers = ['8.8.8.8']
  31. try:
  32. if (sp[3]!="SOA"):
  33. if sp[3]=="ANY":
  34. sp[3]="A"
  35. answers = res.query(sp[1],sp[3])
  36. for record in answers.rrset:
  37. print "DATA\t" + sp[1] + "\t" + sp[2] + "\t"+sp[3]+"\t60\t-1\t"+str(record)
  38. else:
  39. # print "DATA\t" + sp[1] + "\t" + sp[2] + "\t"+sp[3]+"\t60\t-1\tlocalhost 2008080300 1800 3600 604800 3600"
  40. raise Exception("SOA alert")
  41. except:
  42. try:
  43. answers = res.query(sp[1], 'SOA')
  44. for record in answers.rrset:
  45. print "DATA\t" + sp[1] + "\t" + sp[2] + "\tSOA\t60\t1\t"+str(record)
  46. except:
  47. pass
  48.  
  49.  
  50. stdout.flush()
  51. if f==0:
  52. print "END"
  53. stdout.flush();
Add Comment
Please, Sign In to add comment