Skip to content

Commit d10c70f

Browse files
heapcrashpeace-makerArusekk
authored
Allow to add to the existing environment in ssh instead of replacing it (Gallopsled#1764)
* Add env_add to the ssh module * Use ignore_environ like process --------- Co-authored-by: peace-maker <[email protected]> Co-authored-by: Arusekk <[email protected]>
1 parent 65f9d57 commit d10c70f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

pwnlib/tubes/ssh.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ def shell(self, shell = None, tty = True, timeout = Timeout.default):
760760
"""
761761
return self.run(shell, tty, timeout = timeout)
762762

763-
def process(self, argv=None, executable=None, tty=True, cwd=None, env=None, timeout=Timeout.default, run=True,
763+
def process(self, argv=None, executable=None, tty=True, cwd=None, env=None, ignore_environ=None, timeout=Timeout.default, run=True,
764764
stdin=0, stdout=1, stderr=2, preexec_fn=None, preexec_args=(), raw=True, aslr=None, setuid=None,
765765
shell=False):
766766
r"""
@@ -788,8 +788,9 @@ def process(self, argv=None, executable=None, tty=True, cwd=None, env=None, time
788788
Working directory. If :const:`None`, uses the working directory specified
789789
on :attr:`cwd` or set via :meth:`set_working_directory`.
790790
env(dict):
791-
Environment variables to set in the child. If :const:`None`, inherits the
792-
default environment.
791+
Environment variables to add to the environment.
792+
ignore_environ(bool):
793+
Ignore default environment. By default use default environment iff env not specified.
793794
timeout(int):
794795
Timeout to set on the `tube` created to interact with the process.
795796
run(bool):
@@ -909,6 +910,9 @@ def process(self, argv=None, executable=None, tty=True, cwd=None, env=None, time
909910

910911
aslr = aslr if aslr is not None else context.aslr
911912

913+
if ignore_environ is None:
914+
ignore_environ = env is not None # compat
915+
912916
argv, env = misc.normalize_argv_env(argv, env, self)
913917

914918
if shell:
@@ -959,11 +963,12 @@ def func(): pass
959963
960964
os.chdir(%(cwd)r)
961965
966+
if %(ignore_environ)r:
967+
os.environ.clear()
962968
environ = getattr(os, 'environb', os.environ)
963969
964970
if env is not None:
965971
env = OrderedDict((bytes(k), bytes(v)) for k,v in env)
966-
os.environ.clear()
967972
environ.update(env)
968973
else:
969974
env = environ

0 commit comments

Comments
 (0)