Advertisement
opexxx

dnssnarf.py

May 27th, 2014
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. #!/usr/bin/python
  2. from scapy import *
  3. import time
  4.  
  5. def dns_callback(pkt):
  6.   if DNSQR in pkt and pkt.dport == 53:
  7.     print str(time.asctime( time.localtime(time.time()) )) + \
  8.       " session-id: " + str(pkt[DNS].id) + \
  9.       " UDP client: " + pkt[IP].src + ":" + str(pkt.sport) + \
  10.       " server: " + pkt[IP].dst + ":" + str(pkt.dport) + \
  11.       " query: " + pkt[DNSQR].qname + \
  12.       " class: " + pkt[DNSQR].sprintf("%qclass%") + \
  13.       " type: " + pkt[DNSQR].sprintf("%qtype%")
  14.   elif DNSRR in pkt and pkt.sport == 53:
  15.     print str(time.asctime( time.localtime(time.time()) )) + \
  16.       " session-id: " + str(pkt[DNS].id) + \
  17.       " UDP server: " + str(pkt[IP].src) + ":" + str(pkt.sport) + \
  18.       " response: " + pkt[DNSRR].rdata + \
  19.       " class: " + pkt[DNSRR].sprintf("%rclass%") + \
  20.       " type: " + pkt[DNSRR].sprintf("%type%") + \
  21.       " ttl: " + str(pkt[DNSRR].ttl) + \
  22.       " len: " + str(pkt[DNSRR].rdlen)
  23.  
  24. sniff(prn=dns_callback, filter="udp and port 53", store=0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement