Dimensione: 1866
Commento: converted to 1.6 markup
|
Dimensione: 1931
Commento:
|
Le cancellazioni sono segnalate in questo modo. | Le aggiunte sono segnalate in questo modo. |
Linea 1: | Linea 1: |
# # ATTENTION: See dnsmasq --address=/#/1.2.3.4 before!!!!! # |
# # ATTENTION: See dnsmasq --address=/#/1.2.3.4 before!!!!! # #FORMAT python #! /usr/bin/env python
# Fake dns multithread
from SocketServer import *
FAKEADDRESS="111.111.111.111" PORT=53 #udp
class DNSQuery:
#da http://preachermm.blogspot.com/2006/04/servidor-fake-dns-en-python.html (single thread) def init(self, data):
- self.data=data
self.dominio= tipo = (ord(data[2]) >> 3) & 15 # Opcode bits if tipo == 0: # Standard query
- ini=12 lon=ord(data[ini]) while lon != 0:
- self.dominio+=data[ini+1:ini+lon+1]+'.' ini+=lon+1 lon=ord(data[ini])
- ini=12 lon=ord(data[ini]) while lon != 0:
packet= if self.dominio:
- packet+=self.data[:2] + "\x81\x80" packet+=self.data[4:6] + self.data[4:6] + '\x00\x00\x00\x00' # Questions and Answers Counts packet+=self.data[12:] # Original Domain Name Question packet+='\xc0\x0c' # Pointer to domain name
packet+='\x00\x01\x00\x01\x00\x00\x00\x3c\x00\x04' # Response type, ttl and resource data length -> 4 bytes packet+=str.join(,map(lambda x: chr(int(x)), ip.split('.'))) # 4bytes of IP
- packet+=self.data[:2] + "\x81\x80" packet+=self.data[4:6] + self.data[4:6] + '\x00\x00\x00\x00' # Questions and Answers Counts packet+=self.data[12:] # Original Domain Name Question packet+='\xc0\x0c' # Pointer to domain name
- self.data=data
#DNSQuery
class DNSRequestHandler (DatagramRequestHandler):
- def handle(self):
- DNSRequest=self.rfile.read() q=DNSQuery(DNSRequest) DNSDatagram=q.respuesta(FAKEADDRESS) self.wfile.write(DNSDatagram)
#DNSRequestHandler
#crea una classe di server udp threadizzato class FakeDNSServer (ThreadingMixIn, UDPServer): pass
dummyDNS=FakeDNSServer((,PORT),DNSRequestHandler)
#per prevenire attacchi, l'unico modo x fermare il server e' killarlo (SIGTERM, SIGKILL) o premere ctrl-C going=True while going:
- try:
- dummyDNS.serve_forever()
except KeyboardInterrupt:
- going=False
- pass