Exemple #1
0
    async def poll_dnsserver(self, msg):
        await self.log('Polling passthru server at %s!' %
                       (str(self.globalsession.passthru_server), ))
        if self.globalsession.passthru_proto == socket.SOCK_DGRAM:
            if self.globalsession.passthru_ip.version == 4:
                sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
                                     socket.IPPROTO_UDP)
                sock.setblocking(False)
                sock.setsockopt(socket.SOL_SOCKET, 25,
                                self.globalsession.passthru_iface.encode())
                sock.bind((str(self.globalsession.passthru_ip), 0))

            else:
                sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM,
                                     socket.IPPROTO_UDP)
                sock.setblocking(False)
                sock.setsockopt(socket.SOL_SOCKET, 25,
                                self.globalsession.passthru_iface.encode())
                sock.bind((str(self.globalsession.passthru_ip), 0,
                           self.globalsession.passthru_iface_idx))

            client = UDPClient((str(self.globalsession.passthru_server),
                                self.globalsession.passthru_port),
                               sock=sock)
            reader, writer = await asyncio.wait_for(client.run(msg.to_bytes()),
                                                    timeout=1)

        else:
            if self.globalsession.passthru_ip.version == 4:
                sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM,
                                     socket.IPPROTO_TCP)
                sock.setsockopt(socket.SOL_SOCKET, 25,
                                self.globalsession.passthru_iface.encode())
                sock.bind((str(self.globalsession.passthru_ip), 0))
                sock.connect((str(self.globalsession.passthru_server),
                              self.globalsession.passthru_port))

            else:
                sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM,
                                     socket.IPPROTO_TCP)
                sock.setblocking(False)
                sock.setsockopt(socket.SOL_SOCKET, 25,
                                self.globalsession.passthru_iface.encode())
                sock.bind((str(self.globalsession.passthru_ip), 0,
                           self.globalsession.passthru_iface_idx))
                sock.connect((str(self.globalsession.passthru_server),
                              self.globalsession.passthru_port))

            reader, writer = await asyncio.wait_for(
                asyncio.open_connection(sock=sock), timeout=1)

            writer.write(msg.to_bytes())
            await writer.drain()

        passthru_packet = await asyncio.wait_for(DNSPacket.from_streamreader(
            reader, self.globalsession.passthru_proto),
                                                 timeout=1)
        await self.log('Passthru packet recieved!')
        return passthru_packet
Exemple #2
0
    async def udp_proxy(self):
        laddr = (self.creader._addr[0], self.creader._addr[1])
        raddr = (self.remote_host, self.remote_port)
        data = await self.creader.read()

        await self.logger.proxy(data, laddr, raddr)

        client = UDPClient((self.remote_host, self.remote_port))
        self.proxy_reader, self.proxy_writer = await asyncio.wait_for(
            client.run(data), timeout=self.timeout)

        response_data = await self.proxy_reader.read()

        await self.logger.proxy(data, raddr, laddr)
        self.cwriter.write(response_data)
        return
Exemple #3
0
    def udp_proxy(self):
        laddr = '%s:%d' % (self.creader._addr[0], self.creader._addr[1])
        raddr = '%s:%d' % (self.remote_host, self.remote_port)
        data = yield from self.creader.read()

        self.logProxy('original data: %s' % repr(data), laddr, raddr)

        client = UDPClient((self.remote_host, self.remote_port))
        self.proxy_reader, self.proxy_writer = yield from asyncio.wait_for(
            client.run(data), timeout=self.timeout)

        response_data = yield from self.proxy_reader.read()

        self.logProxy('original data: %s' % repr(response_data), raddr, laddr)
        yield from self.cwriter.write(response_data)
        return
Exemple #4
0
	async def resolve(self, ip):
		try:
			ip = ipaddress.ip_address(ip).reverse_pointer
			tid = os.urandom(2)
			question = DNSQuestion.construct(ip, DNSType.PTR, DNSClass.IN, qu = False)
				
						
			if self.server[0]['proto'].upper() == 'TCP':
				packet = DNSPacket.construct(
							TID = tid, 
							flags = DNSFlags.RD,
							response = DNSResponse.REQUEST, 
							opcode = DNSOpcode.QUERY, 
							rcode = DNSResponseCode.NOERR, 
							questions= [question], 
							proto = socket.SOCK_STREAM
						)
				reader, writer = await asyncio.open_connection(self.server[0]['ip'], self.server[0]['port'])
				writer.write(packet.to_bytes())
				await writer.drain()

				data = await DNSPacket.from_streamreader(reader, proto = socket.SOCK_STREAM)
				if data.Rcode == DNSResponseCode.NOERR and len(data.Answers) > 0:
					return str(data.Answers[0].domainname)
				else:
					return 'NA'

				return str(data.Answers[0].domainname)
			else:
				cli = UDPClient((self.server[0]['ip'], self.server[0]['port']))

				packet = DNSPacket.construct(
							TID = tid, 
							flags = DNSFlags.RD,
							response = DNSResponse.REQUEST, 
							opcode = DNSOpcode.QUERY, 
							rcode = DNSResponseCode.NOERR, 
							questions= [question], 
							proto = socket.SOCK_DGRAM
						)
				reader, writer = await cli.run(packet.to_bytes())
				data = await DNSPacket.from_streamreader(reader)
				if data.Rcode == DNSResponseCode.NOERR and len(data.Answers) > 0:
					return str(data.Answers[0].domainname)
				else:
					return 'NA'
		except Exception as e:
			import traceback
			traceback.print_exc()
			return None
Exemple #5
0
    async def resolve(self, ip):
        try:
            ip = ipaddress.ip_address(ip).reverse_pointer
            tid = os.urandom(2)
            question = DNSQuestion.construct(ip,
                                             DNSType.PTR,
                                             DNSClass.IN,
                                             qu=False)

            if self.protocol == 'TCP':
                packet = DNSPacket.construct(TID=tid,
                                             flags=DNSFlags.RD,
                                             response=DNSResponse.REQUEST,
                                             opcode=DNSOpcode.QUERY,
                                             rcode=DNSResponseCode.NOERR,
                                             questions=[question],
                                             proto=socket.SOCK_STREAM)
                reader, writer = await asyncio.open_connection(self.server, 53)
                writer.write(packet.to_bytes())
                await writer.drain()

                data = await DNSPacket.from_streamreader(
                    reader, proto=socket.SOCK_STREAM)
                print(data.Answers[0].domainname)
                return data.Answers[0].domainname
            else:
                cli = UDPClient((self.server, 53))

                packet = DNSPacket.construct(TID=tid,
                                             flags=DNSFlags.RD,
                                             response=DNSResponse.REQUEST,
                                             opcode=DNSOpcode.QUERY,
                                             rcode=DNSResponseCode.NOERR,
                                             questions=[question],
                                             proto=socket.SOCK_DGRAM)

                reader, writer = await cli.run(packet.to_bytes())
                data = await DNSPacket.from_streamreader(reader)
                print(data.Answers[0].domainname)
                return data.Answers[0].domainname

        except Exception as e:
            return None