Skip to content

Instantly share code, notes, and snippets.

@mwpcheung
Created December 21, 2023 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwpcheung/bf8a2c4cc3a8a54a54941d4fa16f3fa6 to your computer and use it in GitHub Desktop.
Save mwpcheung/bf8a2c4cc3a8a54a54941d4fa16f3fa6 to your computer and use it in GitHub Desktop.
golang make amd64 shellcode call any address
package main
import (
"bytes"
"encoding/binary"
"fmt"
"simulator/gapstone"
"testing"
)
func TestAMD64Asm(t *testing.T) {
/*
mov rax,xxxxxxxx ;48 B8 F0 DE BC 9A 78 56 34 12
call rax ;ff d0
nop ;90
nop ;90
nop ;90
nop ;90
*/
addr := uint64(0x123456789abcdef0)
buf := new(bytes.Buffer)
binary.Write(buf, binary.BigEndian, uint16(0x48b8))
binary.Write(buf, binary.LittleEndian, addr)
binary.Write(buf, binary.BigEndian, uint16(0xffd0))
binary.Write(buf, binary.BigEndian, uint32(0x90909090))
engine, _ := gapstone.New(gapstone.CS_ARCH_X86, gapstone.CS_MODE_64)
inss, err := engine.Disasm(buf.Bytes(), 0x20000000, 0)
if err != nil {
fmt.Printf("%s", err.Error())
}
for _, ins := range inss {
fmt.Printf("%x %s %s\n", ins.Address, ins.Mnemonic, ins.OpStr)
}
}
@mwpcheung
Copy link
Author

mwpcheung commented Dec 21, 2023

20000000 movabs rax, 0x123456789abcdef0
2000000a call rax
2000000c nop 
2000000d nop 
2000000e nop 
2000000f nop 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment