Beispiel #1
0
    async def run(self):
        """
		
		"""
        try:
            wrap_ssl = False
            if self.target.proto == LDAPProtocol.SSL:
                wrap_ssl = True
            self.out_queue = asyncio.Queue()
            self.in_queue = asyncio.Queue()

            self.proxy_in_queue = asyncio.Queue()
            comms = SocksQueueComms(self.out_queue,
                                    self.proxy_in_queue,
                                    wrap_ssl=wrap_ssl)

            self.target.proxy.target[
                -1].endpoint_ip = self.target.host if self.target.serverip is None else self.target.serverip
            self.target.proxy.target[-1].endpoint_port = int(self.target.port)
            self.target.proxy.target[
                -1].endpoint_timeout = None  #TODO: maybe implement endpoint timeout?
            self.target.proxy.target[-1].timeout = self.target.timeout
            self.client = SOCKSClient(comms, self.target.proxy.target)
            proxy_coro = await self.client.run(True)
            self.proxy_task = asyncio.create_task(proxy_coro)
            await self.client.proxy_running_evt.wait()
            self.handle_in_task = asyncio.create_task(self.handle_in_q())
            return True, None
        except Exception as e:
            traceback.print_exc()
            return False, e
Beispiel #2
0
    async def __gen_targets(self):
        try:
            for port_gen in self.port_gens:
                ports = port_gen.run()
                for port in ports:
                    self.ports[port] = 1

            while True:
                addr = await self.__addr_queue.get()
                if addr is None:
                    break
                print(addr)
                for port in self.ports:
                    self.__total_targets += 1
                    credential = self.connection_url.get_creds()
                    target = self.connection_url.get_target()
                    target.endpoint_ip = addr
                    target.endpoint_port = port
                    target.timeout = None
                    target.only_open = True

                    in_q = asyncio.Queue()
                    out_q = asyncio.Queue()

                    comms = SocksQueueComms(in_q, out_q)

                    client = SOCKSClient(comms, target, credential)

                    await self.__target_queue.put((addr, port, client))

            self.__target_gen_finished_evt.set()

        except Exception as e:
            print(e)
Beispiel #3
0
	async def connect(self):
		try:	
			self.out_queue = asyncio.Queue()
			self.in_queue = asyncio.Queue()
			comms = SocksQueueComms(self.out_queue, self.in_queue)

			self.target.proxy.target[-1].endpoint_ip = self.target.ip
			self.target.proxy.target[-1].endpoint_port = int(self.target.port)
			self.target.proxy.target[-1].endpoint_timeout = None #int(self.target.timeout)
			self.target.proxy.target[-1].timeout = int(self.target.timeout) if self.target.timeout is not None else None

			self.client = SOCKSClient(comms, self.target.proxy.target)
			proxy_coro = await self.client.run(True)
			self.proxy_task = asyncio.create_task(proxy_coro)
			await self.client.proxy_running_evt.wait()



			return True, None
		except Exception as e:
			return False, e

			

			


			
Beispiel #4
0
    async def connect(self):
        self.out_queue = asyncio.Queue()
        self.in_queue = asyncio.Queue()
        comms = SocksQueueComms(self.out_queue, self.in_queue)

        self.target.proxy.target.endpoint_ip = self.target.ip
        self.target.proxy.target.endpoint_port = int(self.target.port)

        self.client = SOCKSClient(comms, self.target.proxy.target,
                                  self.target.proxy.auth)
        self.proxy_task = asyncio.create_task(self.client.run())
        return
Beispiel #5
0
	async def setup(self):
		try:
			if self.proxy is None:
				# no need for additional setup
				return None, None
			
			self.in_q = asyncio.Queue()
			self.out_q = asyncio.Queue()
			comms = SocksQueueComms(self.in_q, self.out_q)
			proxies = SocksClientURL.from_urls(self.proxy, self.server, self.port)
			self.proxyobj = SOCKSClient(comms, proxies)
			self.proxy_task = asyncio.create_task(self.proxyobj.run())
			return None, None
		except Exception as e:
			return None, e
Beispiel #6
0
	async def socks5_test_port(self, username = None, password = None, timeout = None, retries = -1):
		"""
		Tests if port binding is supported by the socks server
		"""
		try:
			while retries != 0:
				retries -= 1
				target = SocksTarget()
				target.version = SocksServerVersion.SOCKS5
				target.server_ip = self.server_ip
				target.server_port = self.server_port
				target.is_bind = False
				target.timeout = 10
				target.buffer_size = 4096
				target.ssl_ctx = self.server_sslctx
				target.endpoint_ip = self.verify_host
				target.endpoint_port = self.verify_port #random.randint(35000, 50000)
				target.endpoint_timeout = None
				target.only_open = True

				credential = SocksCredential()
				credential.username = username
				credential.password = password

				in_q = asyncio.Queue()
				out_q = asyncio.Queue()

				comms = SocksQueueComms(in_q, out_q)
				channel_open_evt = asyncio.Event()
				
				client = SOCKSClient(comms, target, credential, bind_evt = channel_open_evt)
				#client_task = asyncio.create_task(client.run())

				res, err = await client.handle_queue()
				if err is not None:
					if isinstance(err, SOCKS5ServerErrorReply):
						if err.reply in [SOCKS5ReplyType.TTL_EXPIRED, SOCKS5ReplyType.CONN_REFUSED, SOCKS5ReplyType.HOST_UNREACHABLE, SOCKS5ReplyType.CONN_NOT_ALLOWED]:
							return False, err

						elif err.reply in [SOCKS5ReplyType.ADDRESS_TYPE_NOT_SUPPORTED]:
							return None, err
					
					continue

				return True, None
			return None, Exception('Max retries reached!')
		except Exception as e:
			return None, e
    async def sendrecv(self, data):
        self.out_queue = asyncio.Queue()
        self.in_queue = asyncio.Queue()
        comms = SocksQueueComms(self.out_queue, self.in_queue)

        self.client = SOCKSClient(comms, self.target.proxy.target)
        proxy_coro = await self.client.run(True)
        self.proxy_task = asyncio.create_task(proxy_coro)
        await self.client.proxy_running_evt.wait()
        #self.proxy_task = asyncio.create_task(self.client.run())

        length = len(data).to_bytes(4, byteorder='big', signed=False)
        await self.out_queue.put(length + data)

        resp_data = b''
        resp_data_len = -1
        while True:
            data, err = await self.in_queue.get()
            if data is None:
                break
            if err is not None:
                raise err
            resp_data += data
            if resp_data_len == -1:
                if len(resp_data) > 4:
                    resp_data_len = int.from_bytes(resp_data[:4],
                                                   byteorder='big',
                                                   signed=False)
                    if resp_data_len == 0:
                        raise Exception(
                            'Returned data length is 0! This means the server did not understand our message'
                        )

            if resp_data_len != -1:
                if len(resp_data) == resp_data_len + 4:
                    resp_data = resp_data[4:]
                    break
                elif len(resp_data) > resp_data_len + 4:
                    raise Exception('Got too much data somehow')
                else:
                    continue

        await self.out_queue.put(None)
        if resp_data == b'':
            raise Exception('Connection returned no data!')

        krb_message = KerberosResponse.load(resp_data)
        return krb_message
Beispiel #8
0
    async def connect(self):
        try:
            self.out_queue = asyncio.Queue()
            self.in_queue = asyncio.Queue()
            comms = SocksQueueComms(self.out_queue, self.in_queue)

            self.target.proxy.target[-1].endpoint_ip = self.target.ip
            self.target.proxy.target[-1].endpoint_port = int(self.target.port)
            self.target.proxy.target[-1].endpoint_timeout = int(
                self.target.timeout)
            self.target.proxy.target[-1].timeout = int(self.target.timeout)

            self.client = SOCKSClient(comms, self.target.proxy.target)
            self.proxy_task = asyncio.create_task(self.client.run())
            return True, None
        except Exception as e:
            return False, e
Beispiel #9
0
    async def setup(self):
        try:
            try:
                ipaddress.ip_address(self.server)
                return None, None
            except:
                pass

            self.in_q = asyncio.Queue()
            self.out_q = asyncio.Queue()
            su = SocksClientURL.from_params(self.server)
            comms = SocksQueueComms(self.in_q, self.out_q)
            self.proxy = SOCKSClient(comms, su)
            self.proxy_task = asyncio.create_task(self.proxy.run())
            return None, None
        except Exception as e:
            return None, e
Beispiel #10
0
	async def run(self):
		"""
		
		"""
		try:
			self.out_queue = asyncio.Queue()
			self.in_queue = asyncio.Queue()

			self.proxy_in_queue = asyncio.Queue()
			comms = SocksQueueComms(self.out_queue, self.proxy_in_queue)

			self.target.proxy.target.endpoint_ip = self.target.host
			self.target.proxy.target.endpoint_port = int(self.target.port)

			self.client = SOCKSClient(comms, self.target.proxy.target, self.target.proxy.auth)
			self.proxy_task = asyncio.create_task(self.client.run())
			self.handle_in_task = asyncio.create_task(self.handle_in_q())
			return True, None
		except Exception as e:
			return False, e
Beispiel #11
0
	async def socks5_bind(self, username = None, password = None, timeout = None):
		"""
		Tests if port binding is supported by the socks server
		"""
		try:
			target = SocksTarget()
			target.version = SocksServerVersion.SOCKS5
			target.server_ip = self.server_ip
			target.server_port = self.server_port
			target.is_bind = True
			target.timeout = 10
			target.buffer_size = 4096
			target.ssl_ctx = self.server_sslctx
			target.endpoint_ip = '0.0.0.0'
			target.endpoint_port = random.randint(35000, 50000)
			target.endpoint_timeout = None
			target.only_bind = True

			credential = SocksCredential()
			credential.username = username
			credential.password = password

			in_q = asyncio.Queue()
			out_q = asyncio.Queue()

			comms = SocksQueueComms(in_q, out_q)
			client = SOCKSClient(comms, target, credential)
			
			res, err = await client.handle_queue()
			if err is None:
				return True, None
			
			if isinstance(err, SOCKS5ServerErrorReply):
				if err.reply == SOCKS5ReplyType.COMMAND_NOT_SUPPORTED:
					return False, None

			return res, err
		except Exception as e:
			return None, e
Beispiel #12
0
	async def socks5_local(self, username = None, password = None, timeout = None):
		"""
		Tests if port binding is supported by the socks server
		"""
		try:
			target = SocksTarget()
			target.version = SocksServerVersion.SOCKS5
			target.server_ip = self.server_ip
			target.server_port = self.server_port
			target.is_bind = False
			target.timeout = 10
			target.buffer_size = 4096
			target.ssl_ctx = self.server_sslctx
			target.endpoint_ip = self.server_ip
			target.endpoint_port = self.verify_port if self.verify_port is not None else 22
			target.endpoint_timeout = None

			credential = SocksCredential()
			credential.username = username
			credential.password = password

			in_q = asyncio.Queue()
			out_q = asyncio.Queue()

			comms = SocksQueueComms(in_q, out_q)
			client = SOCKSClient(comms, target, credential)
			
			res, err = await client.handle_queue()
			if err is None:
				return True, None
			
			if isinstance(err, SOCKS5ServerErrorReply):
				if err.reply in [SOCKS5ReplyType.FAILURE, SOCKS5ReplyType.CONN_NOT_ALLOWED]:
					return False, None

			return res, err
		except Exception as e:
			return None, e
Beispiel #13
0
    async def run(self):
        """
		
		"""
        try:
            self.out_queue = asyncio.Queue()
            self.in_queue = asyncio.Queue()

            self.proxy_in_queue = asyncio.Queue()
            comms = SocksQueueComms(self.out_queue, self.proxy_in_queue)

            self.target.proxy.target[
                -1].endpoint_ip = self.target.host if self.target.serverip is None else self.target.serverip
            self.target.proxy.target[-1].endpoint_port = int(self.target.port)
            self.target.proxy.target[
                -1].endpoint_timeout = None  #TODO: maybe implement endpoint timeout?
            self.target.proxy.target[-1].timeout = self.target.timeout
            self.client = SOCKSClient(comms, self.target.proxy.target)
            self.proxy_task = asyncio.create_task(self.client.run())
            self.handle_in_task = asyncio.create_task(self.handle_in_q())
            return True, None
        except Exception as e:
            return False, e
Beispiel #14
0
async def main():
    in_queue = asyncio.Queue()
    out_queue = asyncio.Queue()
    await out_queue.put(b'GET / HTTP/1.1\r\nHost: google.com\r\n\r\n')

    target = SocksTarget()
    #target.version = SocksServerVersion.SOCKS4
    target.version = SocksServerVersion.SOCKS5
    target.server_ip = '127.0.0.1'
    target.server_port = 9050
    target.is_bind = False
    target.proto = SocksProtocol.TCP
    target.timeout = 10
    target.buffer_size = 4096
    target.endpoint_ip = ipaddress.ip_address('216.239.32.117')
    target.endpoint_port = 80

    comms = SocksQueueComms(out_queue, in_queue)
    t = asyncio.create_task(read_q(in_queue))

    client = SOCKSClient(comms, target)
    await client.run()
    print('DONE!')
Beispiel #15
0
    async def __gen_targets(self):
        try:
            while True:
                password = await self.__passwords_queue.get()
                if password is None:
                    break
                self.passwords[password] = 1

            while True:
                user = await self.__users_queue.get()
                if user is None:
                    break

                for password in self.passwords:
                    self.__total_targets += 1
                    credential = SocksCredential()
                    credential.username = user
                    credential.password = password
                    target = self.connection_url.get_target()
                    target.only_open = True
                    target.only_auth = True
                    target.endpoint_ip = self.verify_target
                    target.endpoint_port = self.verify_port

                    in_q = asyncio.Queue()
                    out_q = asyncio.Queue()

                    comms = SocksQueueComms(in_q, out_q)

                    client = SOCKSClient(comms, target, credential)

                    await self.__target_queue.put((user, password, client))

            self.__target_gen_finished_evt.set()

        except Exception as e:
            print(e)