-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgxor.go
58 lines (53 loc) · 1.26 KB
/
gxor.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
package main
import (
"flag"
"fmt"
"os"
"strconv"
)
var (
inputBinaryFile = flag.String("input-file", "", "input bin file")
xorKey = flag.Int("xor-key", 8, "input xor key")
outputBinaryFile = flag.String("output-file", "output.bin", "input bin file")
appendFlag = flag.String("append-flag", "", "flag for file head, 1 bytes")
)
func usage() {
fmt.Println("[gxor] Xor Binary file")
fmt.Println("Usage : gxor -input-file payload.bin -output-file out.bin -xor-key 10 -appendFlag A")
}
func main() {
flag.Parse()
if *inputBinaryFile == "" {
usage()
return
}
fp, err := os.Open(*inputBinaryFile)
if err != nil {
fmt.Println(err)
}
defer fp.Close()
fileInfo, err := fp.Stat()
if err != nil {
fmt.Println(err)
return
}
fmt.Println("File Size:", fileInfo.Size())
fileSize, _ := strconv.Atoi(strconv.FormatInt(fileInfo.Size(), 10))
data := make([]byte, fileInfo.Size())
fp.Read(data)
for i := 0; i < fileSize; i++ {
data[i] ^= byte(*xorKey)
}
newFile, err := os.Create(*outputBinaryFile)
defer newFile.Close()
if err != nil {
fmt.Println(err)
return
}
if len(*appendFlag) > 0 {
newFile.Write([]byte(*appendFlag))
}
newFile.Write(data)
fmt.Println("[*]Flag Size:", len(*appendFlag))
fmt.Println("[*]Output:", *outputBinaryFile)
}