首页 > 解决方案 > 在其他交互式程序中禁用 Bash 命令

问题描述

我使用的是 Kali Linux,我不希望 bash 命令在其他交互式程序中运行,就像msfconsole在 Meterpreter 中运行一样,你仍然可以这样做ls,在 Metasploit 中这不是问题,但我正在尝试学习 PowerShell。当我这样做时,pwsh我仍然可以使用 bash 命令——这有点奇怪。帮助我禁用 PowerShell 中的 bash 命令。

复制并粘贴我所做的:

root@kali:~# pwsh
PowerShell 6.2.3
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/pscore6-docs
Type 'help' to get help.
PS /root/Documents/tmp> ls
chall  john  peda-session-chall.txt

在 Powershell 中,它不应该运行ls命令。但是当我在 bash 中使用它时,我能够运行该命令,并且我想停止它

的内容$PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

我曾尝试寻找一些标志,--no-bash但找不到任何东西。

标签: linuxbashpowershellshellkali-linux

解决方案


我认为您不能在 PowerShell 中禁用操作系统命令。

根据定义,PowerShell 首先尝试自己的命令或别名,如果找不到,它会在底层操作系统中搜索可执行文件。但是,我会说其他贝壳也是如此。甚至猛击。在您的示例中,命令ls不是 bash 中的内置命令,而是位于您的$PATH. 另一方面,times是内置命令。

igor@pc:~$ which times
igor@pc:~$ which ls
/bin/ls

请注意,上面我指的是底层操作系统,而不是之前的 shell。PowerShell不会执行来自 bash 的内置命令。如果你尝试eval, unset,times其他, 你会得到错误CommandNotFoundException

PS /home/igor> times
times : The term 'times' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ times
+ ~~~~~
+ CategoryInfo          : ObjectNotFound: (times:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

PS /home/igor> exit
igor@pc:~$ times
0m0.078s 0m0.141s
0m36.063s 0m29.406s

推荐阅读