Italiano English
Modifica History Actions

Differenze per "fakeDNS.py"

Differenze tra le versioni 5 e 6
Versione 5 del 2008-03-18 17:27:47
Dimensione: 1866
Autore: localhost
Commento: converted to 1.6 markup
Versione 6 del 2009-10-16 21:55:26
Dimensione: 1931
Autore: 93-40-118-16
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])
    def respuesta(self, ip):
    • 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

      return packet

#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: