Exemple #1
0
    def _open_channel(self, channel_name):
        if channel_name == 'stdio':
            process = self.interaction.process
            if process is None:
                raise ValueError("Can't get stdio for remote process")
            channel = nclib.merge([process.stdout, process.stderr],
                                  sock_send=process.stdin)
        elif ':' in channel_name:
            target = self.interaction.target
            kind, idx = channel_name.split(':', 1)
            if kind in ('tcp', 'tcp6'):
                ipv6 = kind == 'tcp6'
                mapping = target.tcp_ports
                udp = False
            elif kind in ('udp', 'udp6'):
                ipv6 = kind == 'udp6'
                mapping = target.udp_ports
                udp = True
            else:
                raise ValueError("Bad channel", kind)

            address = target.ipv6_address if ipv6 else target.ipv4_address
            # if we run in network_mode=host we don't get an IP
            if not address:
                address = 'localhost'

            try:
                port = mapping[int(idx)]
            except ValueError as e:
                raise ValueError("Channel number is not a number",
                                 channel_name) from e
            except LookupError as e:
                raise ValueError("No mapping for channel number", kind,
                                 idx) from e

            channel = nclib.Netcat((address, port),
                                   udp=udp,
                                   ipv6=ipv6,
                                   retry=30)
        else:
            raise ValueError("Bad channel", channel_name)

        logger = nclib.logger.StandardLogger(
            nclib.simplesock.SimpleLogger('archr.log'))
        channel.add_logger(logger)
        return channel
Exemple #2
0
    def open_channel(self, channel_name):
        if channel_name == 'stdio':
            if self.process is None:
                raise ValueError("Can't get stdio for remote process")
            if channel_name == 'stdio':
                channel = nclib.merge(
                    [self.process.stdout, self.process.stderr],
                    sock_send=self.process.stdin)
        elif ':' in channel_name:
            kind, idx = channel_name.split(':', 1)
            if kind in ('tcp', 'tcp6'):
                ipv6 = kind == 'tcp6'
                mapping = self.target.tcp_ports
                udp = False
            elif kind in ('udp', 'udp6'):
                ipv6 = kind == 'udp6'
                mapping = self.target.udp_ports
                udp = True
            else:
                raise ValueError("Bad channel", kind)

            address = self.target.ipv6_address if ipv6 else self.target.ipv4_address

            try:
                port = mapping[int(idx)]
            except ValueError as e:
                raise ValueError("Channel number is not a number",
                                 channel_name) from e
            except LookupError as e:
                raise ValueError("No mapping for channel number", kind,
                                 idx) from e

            channel = nclib.Netcat((address, port),
                                   udp=udp,
                                   ipv6=ipv6,
                                   retry=30)
        else:
            raise ValueError("Bad channel", channel_name)

        logger = nclib.logger.StandardLogger(
            nclib.simplesock.SimpleLogger('archr.log'))
        channel.add_logger(logger)
        return channel