diff --git a/_posts/2024-04-29-The PowerShell CLI.md b/_posts/2024-04-29-The PowerShell CLI.md new file mode 100644 index 0000000..a3274c2 --- /dev/null +++ b/_posts/2024-04-29-The PowerShell CLI.md @@ -0,0 +1,991 @@ +--- +layout: post +title: "The PowerShell CLI" +date: "2024-04-29" +author: "r3kind1e" +header-img: "img/post-bg-Penetration Testing Student.png" +catalog: true +tags: + - Penetration Testing Professional + - Resource Development & Initial Access + - PowerShell for Pentesters +--- + +# The PowerShell CLI +## 2.1 The PowerShell CLI ++ For our first task, we should become familiar with the [PowerShell Command Line Interface](http://radar.oreilly.com/2013/06/powershell-command-line-introduction.html) (CLI). + ++ The PowerShell CLI provides us with access to built-in cmdlets, modules, functions, features, and provides a way to create tasks, functions, variables interactively and more, directly from the CLI. + ++ In most cases, accessing the CLI is as simple as just typing “powershell” in the Windows search field from the Start Menu. + ++ Alternatively, the shortcut to PowerShell can be found within the “%appdata%\Microsoft\Windows\Start Menu\Programs\Windows PowerShell” directory. + ++ In this case, the shortcuts are unavailable; the PowerShell executable itself can found in the “C:\Windows\System32\WindowsPowerShell\v1.0” directory. + ++ If other versions are available on the system, they can be found in their corresponding version paths. + +**A note regarding 32-bit and 64-bit PowerShell executables:** + ++ If you’re operating on a 64-bit system, the location of the 64-bit PowerShell executable can be found in C:\windows\system32\WindowsPowerShell. + ++ While the 32-bit version being located in the C:\windows\SysWOW64\WindowsPowerShell directory. + ++ This can be a bit confusing considering the directory naming convention. + +**A note regarding 32-bit and 64-bit PowerShell executables:** + ++ Nonetheless, we can determine whether we’re running in a 32-bit or 64-bit PowerShell environment from the CLI with the following command: + +```powershell +PS C:\> [Environment]::Is64BitProcess +``` + ++ Which should return “True” if the current PowerShell process is 64-bit: + +```powershell +PS C:\> [Environment]::Is64BitProcess +True +``` + +**A note regarding 32-bit and 64-bit PowerShell executables:** + ++ On a 32-bit system, the executable will be in its usual location of + +``` +C:\Windows\System32\WindowsPowerShell\* +``` + +# PowerShell 命令行界面 +## 2.1 PowerShell 命令行界面 ++ 对于我们的第一个任务,我们应该熟悉 [PowerShell 命令行界面](http://radar.oreilly.com/2013/06/powershell-command-line-introduction.html)(CLI)。 + ++ PowerShell CLI 为我们提供了访问内置 cmdlets、模块、功能、特性的途径,并提供了一种方式,可以直接从 CLI 交互式地创建任务、功能、变量等。 + ++ 在大多数情况下,访问 CLI 只需在开始菜单的 Windows 搜索字段中输入“powershell”。 + ++ 另外,PowerShell 的快捷方式可以在“%appdata%\Microsoft\Windows\Start Menu\Programs\Windows PowerShell”目录中找到。 + ++ 如果在这种情况下找不到快捷方式;PowerShell 可执行文件本身可以在“C:\Windows\System32\WindowsPowerShell\v1.0”目录中找到。 + ++ 如果系统上有其他版本可用,它们可以在相应的版本路径中找到。 + +**关于 32 位和 64 位 PowerShell 可执行文件的说明:** + ++ 如果您在 64 位系统上操作,64 位 PowerShell 可执行文件的位置可以在 C:\windows\system32\WindowsPowerShell 找到。 + ++ 而 32 位版本位于 C:\windows\SysWOW64\WindowsPowerShell 目录。 + ++ 考虑到目录命名约定,这可能会有些混淆。 + +**关于 32 位和 64 位 PowerShell 可执行文件的说明:** + ++ 尽管如此,我们可以使用以下命令在 CLI 中确定我们是在 32 位还是 64 位 PowerShell 环境中运行: + +```powershell +PS C:\> [Environment]::Is64BitProcess +``` + ++ 如果当前的 PowerShell 进程是 64 位的,应该返回“True”: + +```powershell +PS C:\> [Environment]::Is64BitProcess +True +``` + +**关于 32 位和 64 位 PowerShell 可执行文件的说明:** + ++ 在 32 位系统上,可执行文件将位于其通常位置 + +``` +C:\Windows\System32\WindowsPowerShell\* +``` + ++ When possible, we should try and launch PowerShell as the Administrator user as this will give us access to functions which we would be otherwise unable to access as a Lower-Privileged user. + ++ We can right-click on the Shortcut or Executable and select “Run As Administrator.” + +NOTE: ++ Although our examples are shown on Windows 10, all of the steps will be similar for Windows 7 and other versions of Windows, unless otherwise noted. + ++ Once we launch PowerShell, we’re presented with the familiar blue console. + +### 2.1.1 Basic Usage + ++ Like most other programs found on Windows, the PowerShell executable has its own set of command line options. We can view these options with the usual “/?” help parameter: + ++ 尽可能地,我们应该尝试以管理员身份启动 PowerShell,这将使我们能够访问一些作为低权限用户无法访问的功能。 + ++ 我们可以右键点击快捷方式或可执行文件并选择“以管理员身份运行”。 + +注意: ++ 虽然我们的示例显示在 Windows 10 上,但所有步骤对于 Windows 7 和其他版本的 Windows 都是相似的,除非另有说明。 + ++ 一旦我们启动 PowerShell,我们会看到熟悉的蓝色控制台。 + +### 2.1.1 基本使用 + ++ 像 Windows 上的大多数其他程序一样,PowerShell 可执行文件有自己的一套命令行选项。我们可以用常见的“/?”帮助参数来查看这些选项: + +``` +PS C:\windows\system32> powershell /? + +• PowerShell[.exe] [-PSConsoleFile | -Version ] + [-NoLogo] [-NoExit] [-Sta] [-Mta] [-NoProfile] [-NonInteractive] + [-InputFormat {Text | XML}] [-OutputFormat {Text | XML}] + [-WindowStyle