简体   繁体   English

在其他交互式程序中禁用 Bash 命令

[英]Disabling Bash Commands in, Other Interactive Programs

I was using Kali Linux, And I don't want bash Commands to be run it other Interactive programs, Like if you run msfconsole in Meterpreter you can still do ls , In Metasploit that's not a problem, but I am trying to learn PowerShell.我使用的是 Kali Linux,并且我不希望 bash 命令在其他交互式程序中运行,就像在 Meterpreter 中运行msfconsole一样,您仍然可以执行ls ,在 Metasploit 中这不是问题,但我正在尝试学习 PowerShell。 When I do pwsh I can still use bash commands -- that's kinda odd.当我执行pwsh我仍然可以使用 bash 命令——这有点奇怪。 Help me with disabling the bash commands in PowerShell.帮助我在 PowerShell 中禁用 bash 命令。

Copy and Paste of what I have done:复制并粘贴我所做的:

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

In Powershell, It should not run ls command.在 Powershell 中,它不应该运行ls命令。 But as I am using it in bash, I am able to run that command, And I want to Stop it但是当我在 bash 中使用它时,我能够运行该命令,并且我想停止它

Contents of $PATH $PATH内容

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

I have tried looking for some flags like --no-bash but couldn't find anything.我试过寻找一些标志,如--no-bash但找不到任何东西。

I do not think you can disable OS commands in PowerShell.我认为您不能在 PowerShell 中禁用操作系统命令。

By definition, PowerShell is first trying its own commands or aliases, and if not found, it is searching in underlying OS for executable.根据定义,PowerShell 首先尝试自己的命令或别名,如果没有找到,它会在底层操作系统中搜索可执行文件。 But, I would say that is the same for other shells also.但是,我想说其他外壳也是如此。 Even bash.甚至猛击。 In your example, command ls is not builtin command in bash, but located within your $PATH .在您的示例中,命令ls不是 bash 中的内置命令,而是位于您的$PATH On the other hand, times is built in command.另一方面, times是内置的。

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

Notice that above I refer to the underlying OS and not the previous shell.请注意,上面我指的是底层操作系统,而不是之前的 shell。 PowerShell will not execute built-in commands from bash. PowerShell不会从 bash 执行内置命令。 If you try eval , unset , times or others , you will get the error CommandNotFoundException如果您尝试evalunsettimes其他,您将收到错误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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM