Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add symlink option for ssh.set_working_directory to simplify exploits #862

Merged
merged 2 commits into from
Jan 20, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion pwnlib/tubes/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -1587,7 +1587,7 @@ def interactive(self, shell=None):
s.interactive()
s.close()

def set_working_directory(self, wd = None):
def set_working_directory(self, wd = None, symlink=False):
"""Sets the working directory in which future commands will
be run (via ssh.run) and to which files will be uploaded/downloaded
from if no path is provided
Expand All @@ -1602,6 +1602,8 @@ def set_working_directory(self, wd = None):
Arguments:
wd(string): Working directory. Default is to auto-generate a directory
based on the result of running 'mktemp -d' on the remote machine.
symlink(bool): Whether to symlink all files / directories in the
original directory. Default is ``False``.

Examples:
>>> s = ssh(host='example.pwnme',
Expand All @@ -1615,6 +1617,9 @@ def set_working_directory(self, wd = None):
"""
status = 0

if symlink:
oldwd = self.pwd()

if not wd:
wd, status = self.run_to_end('x=$(mktemp -d) && cd $x && chmod +x . && echo $PWD', wd='.')
wd = wd.strip()
Expand All @@ -1631,6 +1636,10 @@ def set_working_directory(self, wd = None):

self.info("Working directory: %r" % wd)
self.cwd = wd

if symlink:
self.ln('-s', os.path.join(oldwd, '*'), '.')

return self.cwd

def write(self, path, data):
Expand Down