Created
December 21, 2023 17:08
-
-
Save mwpcheung/bf8a2c4cc3a8a54a54941d4fa16f3fa6 to your computer and use it in GitHub Desktop.
golang make amd64 shellcode call any address
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
Author
mwpcheung
commented
Dec 21, 2023
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment