Skip to content

Commit

Permalink
Enhance tubes.ssh bytes handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Arusekk committed Jul 7, 2020
1 parent ca06098 commit 0459eff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ The table below shows which release corresponds to each branch, and what date th
- [#1592][1592] Fix over-verbose logging of process() environment
- [#1593][1593] Colorize output of `pwn template`
- [#1601][1601] Add `pwn version` command line tool
- [#1602][1602] Fix bytes handling in ssh tubes
- [#1605][1605] Add to `fiddling.hexdump` a way to suppress the total at the end
- [#1613][1613] Permit `--password` for `pwn template`
- [#1564][1564] Fix `asm()` and `disasm()` for PowerPC64, MIPS64, Sparc64
Expand All @@ -75,6 +76,7 @@ The table below shows which release corresponds to each branch, and what date th
[1592]: https://github.com/Gallopsled/pwntools/pull/1592
[1593]: https://github.com/Gallopsled/pwntools/pull/1593
[1601]: https://github.com/Gallopsled/pwntools/pull/1601
[1602]: https://github.com/Gallopsled/pwntools/pull/1602
[1605]: https://github.com/Gallopsled/pwntools/pull/1605
[1613]: https://github.com/Gallopsled/pwntools/pull/1613
[1564]: https://github.com/Gallopsled/pwntools/pull/1564
Expand Down
17 changes: 8 additions & 9 deletions pwnlib/tubes/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,25 @@ def __init__(self, parent, process = None, tty = False, wd = None, env = None, r
self.process = process
self.cwd = wd or '.'
if isinstance(wd, six.text_type):
wd = wd.encode('utf-8')
wd = context._encode(wd)

env = env or {}
msg = 'Opening new channel: %r' % (process or 'shell')

if isinstance(process, (list, tuple)):
process = b' '.join((lambda x:x.encode('utf-8') if isinstance(x, six.text_type) else x)(sh_string(s)) for s in process)
process = b' '.join(context._encode(sh_string(s)) for s in process)
if isinstance(process, six.text_type):
process = process.encode('utf-8')
process = context._encode(process)

if process and wd:
process = b'cd ' + sh_string(wd) + b' >/dev/null 2>&1;' + process

if process and env:
for name, value in env.items():
if not re.match('^[a-zA-Z_][a-zA-Z0-9_]*$', name):
nameb = context._encode(name)
if not re.match(b'^[a-zA-Z_][a-zA-Z0-9_]*$', nameb):
self.error('run(): Invalid environment key %r' % name)
export = 'export %s=%s;' % (name, sh_string(value))
if isinstance(export, six.text_type):
export = export.encode('utf-8')
export = b'export %s=%s;' % (nameb, sh_string(context._encode(value)))
process = export + process

if process and tty:
Expand Down Expand Up @@ -264,11 +263,11 @@ def recv_thread(event):
if not data:
event.set()
else:
data = [six.byte2int(data)]
data = bytearray(data)

if data:
try:
self.send(b''.join(six.int2byte(c) for c in data))
self.send(bytes(bytearray(data)))
except EOFError:
event.set()
self.info('Got EOF while sending in interactive')
Expand Down

0 comments on commit 0459eff

Please sign in to comment.