-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
48 lines (40 loc) · 1.09 KB
/
main.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
package main
import (
"fmt"
"log"
"os"
peparser "github.com/saferwall/pe"
)
func main() {
if len(os.Args) < 3 {
fmt.Printf("pe2shellcode pe.exe shellcode.bin\n")
return
}
pe, err := peparser.New(os.Args[1], &peparser.Options{})
if err != nil {
log.Fatalf("Error while opening file: %s, reason: %v", os.Args[1], err)
}
defer pe.Close()
outfile, err := os.Create(os.Args[2])
if err != nil {
log.Fatalf("Error while opening file: %s, reason: %v", os.Args[2], err.Error())
}
defer outfile.Close()
if err = pe.Parse(); err != nil {
log.Fatalf(err.Error())
}
for _, sec := range pe.Sections {
if sec.String() == ".text" {
fmt.Printf("[*] %s Section: \n", sec.Header.Name)
fmt.Printf(" [*] VirtualAddress : 0x%x\n", sec.Header.VirtualAddress)
fmt.Printf(" [*] VirtualSize : %v\n", sec.Header.VirtualSize)
fmt.Printf(" [*] SizeOfRawData : %v\n", sec.Header.SizeOfRawData)
shellcode := sec.Data(sec.Header.VirtualAddress, sec.Header.VirtualSize, pe)
_, err := outfile.Write(shellcode)
if err != nil {
fmt.Println(err.Error())
}
break
}
}
}