😎
Intruder
  • About Shantanu Khandelwal
  • Reporting
    • Excel Sheet to Word Report by PowerShell
    • Ghostwriter - Add report type
  • Red Team
    • HTTPS C2 Done Right NGINX
    • Domain Front
      • Firebase Domain Front - Hiding C2 as App traffic
    • GoLang
      • Red Team: How to embed Golang tools in C#
      • Red Team: Using SharpChisel to exfil internal network
      • Converting your GO bins to Shellcode and Using them in C#
    • ShellCode Injection
      • magic_mz_x86 and magic_mz_x64
      • Process Hollowing DInvoke
      • Shellcode Formatter
      • DLL Sideloading
      • InMemory Shellcode Encryption and Decryption using SystemFunction033
    • PowerShell
      • Enable Restricted Admin using powershell and use mimikatz for RDP
      • Powershell Custom Runspace
      • Using Reflection for AMSI Bypass
    • Database
      • Extract MSSQL Link Password
      • MSSQL Link Crawl - OpenQuery Quotes Calculator
    • DLL Sideloading
      • DLL Koppeling
      • DLL Sideloading not by DLLMain
    • Walking with Docker
      • Self-Hosting Havoc C2 / or any other C2 in Docker
    • Breach Attack Simulation - Starting With OpenBAS
  • Dealing with the Errors
    • Setting Up OPENVAS in KALI 2020.3
    • Page
      • Page 1
  • Phishing
    • Connecting GoPhish with Office365
    • SharpLoginPrompt - Success and a Curious Case
    • Gophish MODs
    • Long Live DMARC - Email Spoof issues
    • Error Solves (Random)
      • Rust OPENSSL install issues
  • Mobile Application Testing
    • How to Download APK from Huawei App Store
  • Talks I Like
  • Talks Worth Checking Out
  • Web Application Penetration Testing
    • Parsing Certificate Transparency Logs
Powered by GitBook
On this page
  • Building Go Binary
  • Converting Binary to Shellcode
  • Using DonutTest
  • Credits:

Was this helpful?

  1. Red Team
  2. GoLang

Converting your GO bins to Shellcode and Using them in C#

How to convert binaries compiled in golang to shellcode

With release of Go1.15 a new "buildmode" flag has been released. -buildmode=pie

Lets do a simple demo of converting a go binary to shellcode and injecting it to other processes

Building Go Binary

I am going to build a simple golang program which launches calc

calc.go
package main

import(
    "fmt"
    "os/exec"
)

func main(){    
    c := exec.Command("calc.exe")

    if err := c.Run(); err != nil { 
        fmt.Println("Error: ", err)
    }   
}

Now lets build the program. I am using Windows 10 amd64 machine. You may need to specify other parameters if you are cross compiling

go build -buildmode=pie -o calc.exe calc.go

The command will generate a static binary calc.exe.

Converting Binary to Shellcode

donut.exe calc.exe -o calc.bin

Using DonutTest

To use our calc.bin inside donut test we need to convert it into base64

[Convert]::ToBase64String([IO.File]::ReadAllBytes("./calc.bin")) | clip

Now paste the shellcode in DonutTest and compile. Your program should run as expected and you should see a calc pop

DonutTest.exe <pid> 

Credits:

PreviousRed Team: Using SharpChisel to exfil internal networkNextShellCode Injection

Last updated 4 years ago

Was this helpful?

Here we will use TheWover's to convert the calc.exe to shellcode. The command is quite simple

is a subproject of Donut repo. DonutTest provides a test harness to test your generated Shellcode.

Donut
DonutTest
https://twitter.com/rkervell