Gallopsled/pwntools — pull request #53 by zachriggle (2014-08-02 21:39:04+00:00)
Title: Ssh working dir

Introduce the notion of a remote working directory. The use-case for this is that, for challenges which require/permit SSH access, generally don't allow read-write to the default (home) directory. This creates a convenient method to auto-generate a unique directory, and perform future commands within it.

API: `pwn.ssh.ssh.set_working_directory`

### Example script

```python
from pwn import *
shell = ssh(host='vortex.labs.overthewire.org',user='vortex1',password='Gq#qu3bF3')

wd = shell.set_working_directory()
print shell.run_to_end('pwd')
print wd

shell.run('mkdir /tmp/for_example')
shell.set_working_directory('/tmp/for_example')
print shell.run_to_end('pwd')

shell.set_working_directory('/does_not_exist')
print shell.run_to_end('pwd')
print shell.run_to_end('pwd', wd=None)

shell.set_working_directory()
shell.upload_file('/bin/ls')
shell.download_file("ls")

assert file('./ls').read() == file('/bin/ls').read()
```

### Example output

```
[+] Connecting to vortex.labs.overthewire.org on port 22: OK
[*] Working directory: '/tmp/tmp.3LQjNtSWA1'
('/tmp/tmp.3LQjNtSWA1\n', 0)
/tmp/tmp.3LQjNtSWA1
[+] Opening new channel: 'mkdir /tmp/for_example': OK
[*] Working directory: '/tmp/for_example'
('/tmp/for_example\n', 0)
[*] Working directory: '/does_not_exist'
('/home/vortex1\n', 0)
('/home/vortex1\n', 0)
[*] Working directory: '/tmp/tmp.7ZNLyiKY3Y'
[*] Uploading '/bin/ls' to '/tmp/tmp.7ZNLyiKY3Y/ls'
[+] Found '/tmp/tmp.7ZNLyiKY3Y/ls' in ssh cache
```