Creates a new ssh connection. Arguments: user(str): The username to log in with host(str): The hostname to connect to port(int): The port to connect to password(str): Try to authenticate using this password key(str): Try to authent
(self, user=None, host=None, port=22, password=None, key=None,
keyfile=None, proxy_command=None, proxy_sock=None, level=None,
cache=True, ssh_agent=False, ignore_config=False, raw=False,
auth_none=False, *a, **kw)
| 572 | _tried_sftp = False |
| 573 | |
| 574 | def __init__(self, user=None, host=None, port=22, password=None, key=None, |
| 575 | keyfile=None, proxy_command=None, proxy_sock=None, level=None, |
| 576 | cache=True, ssh_agent=False, ignore_config=False, raw=False, |
| 577 | auth_none=False, *a, **kw): |
| 578 | """Creates a new ssh connection. |
| 579 | |
| 580 | Arguments: |
| 581 | user(str): The username to log in with |
| 582 | host(str): The hostname to connect to |
| 583 | port(int): The port to connect to |
| 584 | password(str): Try to authenticate using this password |
| 585 | key(str): Try to authenticate using this private key. The string should be the actual private key. |
| 586 | keyfile(str): Try to authenticate using this private key. The string should be a filename. |
| 587 | proxy_command(str): Use this as a proxy command. It has approximately the same semantics as ProxyCommand from ssh(1). |
| 588 | proxy_sock(str): Use this socket instead of connecting to the host. |
| 589 | timeout: Timeout, in seconds |
| 590 | level: Log level |
| 591 | cache(bool): Cache downloaded files (by hash/size/timestamp) |
| 592 | ssh_agent(bool): If :const:`True`, enable usage of keys via ssh-agent |
| 593 | ignore_config(bool): If :const:`True`, disable usage of ~/.ssh/config and ~/.ssh/authorized_keys |
| 594 | raw(bool): If :const:`True`, assume a non-standard shell and don't probe the environment |
| 595 | auth_none(bool): If :const:`True`, try to authenticate with no authentication methods |
| 596 | |
| 597 | NOTE: The proxy_command and proxy_sock arguments is only available if a |
| 598 | fairly new version of paramiko is used. |
| 599 | |
| 600 | Example proxying: |
| 601 | |
| 602 | .. doctest:: |
| 603 | :skipif: True |
| 604 | |
| 605 | >>> s1 = ssh(host='example.pwnme') |
| 606 | >>> r1 = s1.remote('localhost', 22) |
| 607 | >>> s2 = ssh(host='example.pwnme', proxy_sock=r1.sock) |
| 608 | >>> r2 = s2.remote('localhost', 22) # and so on... |
| 609 | >>> for x in r2, s2, r1, s1: x.close() |
| 610 | """ |
| 611 | super(ssh, self).__init__(*a, **kw) |
| 612 | |
| 613 | Logger.__init__(self) |
| 614 | if level is not None: |
| 615 | self.setLevel(level) |
| 616 | |
| 617 | |
| 618 | self.host = host |
| 619 | self.port = port |
| 620 | self.user = user |
| 621 | self.password = password |
| 622 | self.key = key |
| 623 | self.keyfile = keyfile |
| 624 | self._cachedir = os.path.join(tempfile.gettempdir(), 'pwntools-ssh-cache') |
| 625 | self.cache = cache |
| 626 | self.raw = raw |
| 627 | |
| 628 | # Deferred attributes |
| 629 | self._platform_info = {} |
| 630 | self._aslr = None |
| 631 | self._aslr_ulimit = None |