# SMBExec

{% hint style="warning" %}
Administrator rights on the target machine are mandatory.
{% endhint %}

SMBExec is part of the Impacket collection. It executes commands on a remote system by:

* Not downloading service binaries to the target (stealthier than psexec).
* By default, it creates a service named "BTOBTO". The name can be changed in smbexec.py under the variable SERVICE\_NAME=..., or entered as a command line parameter to smbexec.py.
* For each given command, smbexec transfers the commands from the attacker's machine to the target machine via SMB in the form of a batch file in %TEMP%/execute.bat.
* A new service named "BTOBO" is created, copying the command to execute into a batch script, and redirecting the output to stdout and stderror to a Temp file. It then executes the .bat script and deletes it.
* The Python script then extracts the output file via SMB and displays its content in our "pseudo-shell".

For each command we type in this shell, a new service is created, and the process is repeated. Hence, there is no need to drop a binary onto the victim machine's disk.

The service is launched with the highest possible privileges, including *NT\System* privileges, which is why this "pseudo-shell" is opened as *NT\System*.

```python
python3 smbexec.py <DOMAIN>/<USERNAME:<PASSWORD>@<IP>
```

## References

{% embed url="<https://book.hacktricks.xyz/windows-hardening/ntlm/smbexec>" %}


---

# Agent Instructions: 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:

```
GET https://blog.hacktive.bebzounette.com/active-directory/lateral-movement/code-execution/smbexec.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
