Created
March 13, 2015 17:06
-
-
Save weissi/def5dc0fa89f9256e461 to your computer and use it in GitHub Desktop.
Python DNS server using recursive DNS name compression pointers and always resolving to 127.0.0.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SocketServer | |
class MyPyDNSWithLoops(SocketServer.BaseRequestHandler): | |
def handle(self): | |
data = self.request[0].strip() | |
socket = self.request[1] | |
print "<-- [%s] %r" % (self.client_address[0], data) | |
res = data[0] + data[1] + '\x81\x80\x00\x01\x00\x02\x00\x00\x00\x00' + \ | |
'\x04mail\x03aYa\x03com\x00\x00\x01\x00\x01\xc0\x0c\x00\x05' + \ | |
'\x00\x01\x00\x00\x0e\x0e\x00\x02\xc0\x11\xc0*\x00\x01\x00' + \ | |
'\x01\x00\x00\x0e\x0e\x00\x04\x7f\x00\x00\x01' | |
print "--> [%s] %r" % (self.client_address[0], res) | |
socket.sendto(res, self.client_address) | |
if __name__ == "__main__": | |
HOST, PORT = "127.0.0.1", 53 | |
server = SocketServer.UDPServer((HOST, PORT), MyPyDNSWithLoops) | |
server.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment