From 363682949110934ff9e0364ce6229231088cd942 Mon Sep 17 00:00:00 2001 From: Felix Dreissig Date: Tue, 27 Sep 2016 14:17:30 +0200 Subject: [PATCH] Fix argument splitting for multi-word arguments By just splitting at spaces, multi-word arguments are torn apart even if quoted. In case of custom ssh-cmd, this makes it practically impossible to set certian options through `ssh -o`. shlex splits arguments like a shell and e.g. respects quotes. --- sshuttle/methods/pf.py | 3 ++- sshuttle/ssh.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sshuttle/methods/pf.py b/sshuttle/methods/pf.py index fc238f8..05d7492 100644 --- a/sshuttle/methods/pf.py +++ b/sshuttle/methods/pf.py @@ -4,6 +4,7 @@ import socket import struct import subprocess as ssubprocess +import shlex from fcntl import ioctl from ctypes import c_char, c_uint8, c_uint16, c_uint32, Union, Structure, \ sizeof, addressof, memmove @@ -323,7 +324,7 @@ def _get_natlook_port(self, xport): def pfctl(args, stdin=None): - argv = ['pfctl'] + list(args.split(" ")) + argv = ['pfctl'] + shlex.split(args) debug1('>> %s\n' % ' '.join(argv)) p = ssubprocess.Popen(argv, stdin=ssubprocess.PIPE, diff --git a/sshuttle/ssh.py b/sshuttle/ssh.py index 7691c80..fd4946c 100644 --- a/sshuttle/ssh.py +++ b/sshuttle/ssh.py @@ -5,6 +5,7 @@ import zlib import imp import subprocess as ssubprocess +import shlex import sshuttle.helpers as helpers from sshuttle.helpers import debug2 @@ -102,7 +103,7 @@ def connect(ssh_cmd, rhostport, python, stderr, options): argv = [sys.argv[1], '-c', pyscript] else: if ssh_cmd: - sshl = ssh_cmd.split(' ') + sshl = shlex.split(ssh_cmd) else: sshl = ['ssh'] if python: