-
Notifications
You must be signed in to change notification settings - Fork 7
/
shellcode.go
52 lines (41 loc) · 975 Bytes
/
shellcode.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
package helper
import (
"crypto/md5"
"encoding/hex"
"errors"
"io/ioutil"
"strings"
"github.com/asaskevich/govalidator"
)
const (
phpShell = "./shellcode/php/shellcode.code"
aspShell = "./shellcode/asp/shellcode.code"
)
// WriteShellcode ...
func (s *Service) WriteShellcode(key string, shell string) (string, error) {
if govalidator.IsNull(key) {
return "", errors.New("invalid shellcode key")
}
if !(shell == "php" || shell == "asp") {
return "", errors.New("invalid shellcode type, valid shellcode php, asp")
}
shellType := shell
if shell == "php" {
shellType = phpShell
}
if shell == "asp" {
shellType = aspShell
}
template, err := ioutil.ReadFile(shellType)
if err != nil {
return "", err
}
hash := md5.New()
_, err = hash.Write([]byte(key))
if err != nil {
return "", err
}
hashKey := hex.EncodeToString(hash.Sum(nil))
shellcode := strings.Replace(string(template), "shellcode_key", hashKey, -1)
return shellcode, nil
}