> For the complete documentation index, see [llms.txt](https://blog.hacktive.bebzounette.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://blog.hacktive.bebzounette.com/active-directory/lateral-movement/code-execution/smbexec.md).

# 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
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://blog.hacktive.bebzounette.com/active-directory/lateral-movement/code-execution/smbexec.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.
