hacktricks/windows-hardening/ntlm/psexec-and-winexec.md

70 lines
4.3 KiB
Markdown
Raw Normal View History

2022-08-13 23:06:40 +00:00
# PsExec/Winexec/ScExec
2022-04-28 16:01:33 +00:00
2024-07-19 09:06:54 +00:00
{% hint style="success" %}
Learn & practice AWS Hacking:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
Learn & practice GCP Hacking: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
2022-04-28 16:01:33 +00:00
2024-07-19 09:06:54 +00:00
<details>
2022-04-28 16:01:33 +00:00
2024-07-19 09:06:54 +00:00
<summary>Support HackTricks</summary>
2024-01-02 18:28:04 +00:00
2024-07-19 09:06:54 +00:00
* Check the [**subscription plans**](https://github.com/sponsors/carlospolop)!
* **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2022-04-28 16:01:33 +00:00
</details>
2024-07-19 09:06:54 +00:00
{% endhint %}
2022-04-28 16:01:33 +00:00
2022-08-13 23:06:40 +00:00
## How do they work
2024-02-04 16:10:29 +00:00
The process is outlined in the steps below, illustrating how service binaries are manipulated to achieve remote execution on a target machine via SMB:
2024-02-04 16:10:29 +00:00
1. **Copying of a service binary to the ADMIN$ share over SMB** is performed.
2. **Creation of a service on the remote machine** is done by pointing to the binary.
3. The service is **started remotely**.
4. Upon exit, the service is **stopped, and the binary is deleted**.
2024-02-04 16:10:29 +00:00
### **Process of Manually Executing PsExec**
2024-02-04 16:10:29 +00:00
Assuming there is an executable payload (created with msfvenom and obfuscated using Veil to evade antivirus detection), named 'met8888.exe', representing a meterpreter reverse_http payload, the following steps are taken:
2024-02-04 16:10:29 +00:00
- **Copying the binary**: The executable is copied to the ADMIN$ share from a command prompt, though it may be placed anywhere on the filesystem to remain concealed.
2024-02-04 16:10:29 +00:00
- **Creating a service**: Utilizing the Windows `sc` command, which allows for querying, creating, and deleting Windows services remotely, a service named "meterpreter" is created to point to the uploaded binary.
2024-02-04 16:10:29 +00:00
- **Starting the service**: The final step involves starting the service, which will likely result in a "time-out" error due to the binary not being a genuine service binary and failing to return the expected response code. This error is inconsequential as the primary goal is the binary's execution.
2024-02-04 16:10:29 +00:00
Observation of the Metasploit listener will reveal that the session has been initiated successfully.
2024-02-04 16:10:29 +00:00
[Learn more about the `sc` command](https://technet.microsoft.com/en-us/library/bb490995.aspx).
2024-02-04 16:10:29 +00:00
Find moe detailed steps in: [https://blog.ropnop.com/using-credentials-to-own-windows-boxes-part-2-psexec-and-services/](https://blog.ropnop.com/using-credentials-to-own-windows-boxes-part-2-psexec-and-services/)
**You could also use the Windows Sysinternals binary PsExec.exe:**
![](<../../.gitbook/assets/image (165).png>)
You could also use [**SharpLateral**](https://github.com/mertdas/SharpLateral):
2022-04-28 16:01:33 +00:00
{% code overflow="wrap" %}
```
SharpLateral.exe redexec HOSTNAME C:\\Users\\Administrator\\Desktop\\malware.exe.exe malware.exe ServiceName
```
{% endcode %}
2022-04-28 16:01:33 +00:00
2024-07-19 09:06:54 +00:00
{% hint style="success" %}
Learn & practice AWS Hacking:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
Learn & practice GCP Hacking: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
2022-04-28 16:01:33 +00:00
2024-07-19 09:06:54 +00:00
<details>
2022-04-28 16:01:33 +00:00
2024-07-19 09:06:54 +00:00
<summary>Support HackTricks</summary>
2024-01-02 18:28:04 +00:00
2024-07-19 09:06:54 +00:00
* Check the [**subscription plans**](https://github.com/sponsors/carlospolop)!
* **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2022-04-28 16:01:33 +00:00
</details>
2024-07-19 09:06:54 +00:00
{% endhint %}