-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Stop using cmd.exe to keep current directory #2488
Conversation
pwnlib/util/misc.py
Outdated
@@ -367,13 +367,13 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr | |||
with open('/proc/sys/kernel/osrelease', 'rb') as f: | |||
is_wsl = b'icrosoft' in f.read() | |||
if is_wsl and which('cmd.exe') and which('wsl.exe') and which('bash.exe'): | |||
terminal = 'cmd.exe' | |||
args = ['/c', 'start'] | |||
terminal = 'wt.exe' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot use wt.exe if the user does not have it installed. Also, the problem is not cmd.exe but start
(which probably can take an extra cwd argument? not sure, I personally do not have any Windows machine thankfully, but you can run start /?
in cmd to get some idea of whether it is possible). Otherwise, we could run wt.exe without start and the native terminal with start.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can use powershell
(yes , it can prase the file path of WSL ), but it will cost much more resources than cmd
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I think I have a way to deal with cmd
:
else:
is_wsl = False
if os.path.exists('/proc/sys/kernel/osrelease'):
with open('/proc/sys/kernel/osrelease', 'rb') as f:
is_wsl = b'icrosoft' in f.read()
if is_wsl and which('cmd.exe') and which('wsl.exe') and which('bash.exe'):
terminal = 'cmd.exe'
args = ['/c', 'start']
distro_name = os.getenv('WSL_DISTRO_NAME')
current_dir = os.getcwd()
# Split pane in Windows Terminal
if 'WT_SESSION' in os.environ and which('wt.exe'):
args.extend(['wt.exe', '-w', '0', 'split-pane'])
if distro_name:
args.extend(['wsl.exe', '-d', distro_name, '--cd', current_dir, 'bash', '-c'])
else:
args.extend(['bash.exe', '-c'])
A similar patch is included in #2470. Did I miss something? The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can switch to launch wsl.exe
without -d
if the distro_name is unknown instead of bash.exe
and use --cd
there too. But the other change of cd cwd;realcommand
is still here too.
Thanks for the contribution and we can clean this up further later.
* Stop using cmd.exe to keep current directory * Update misc.py * Update misc.py, deal with cmd.exe * Update misc.py
Because
cmd.exe
can't parse the file path ofWSL
, it automatically drop the current directory to/mnt/c/Windows
.We can call
wt.exe
directly to keep the current directory. Because some CTF challenges needs patching run path of the binary to.
, so keeping exactly the current directory is convenient for debugging.