-
Notifications
You must be signed in to change notification settings - Fork 28
/
terminal.go
127 lines (99 loc) · 2.14 KB
/
terminal.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
package main
import (
"github.com/chzyer/readline"
"fmt"
"io"
"strings"
)
var context string = "main"
var prompt string = "Browser-C2 (\033[0;32m%s\033[0;0m)\033[31m >> \033[0;0m"
var MainCompleter = readline.NewPrefixCompleter(
// List agents
readline.PcItem("agents"),
//Use agent
readline.PcItem("use"),
// Exit
readline.PcItem("exit"),
)
var AgentCompleter = readline.NewPrefixCompleter(
readline.PcItem("whoami"),
readline.PcItem("tasklist"),
readline.PcItem("ipconfig"),
readline.PcItem("back"),
)
func backMain(l *readline.Instance){
context = "main"
l.SetPrompt(fmt.Sprintf(prompt,"main"))
l.Config.AutoComplete = MainCompleter
}
func HandleAgentCommands(agentName string, l *readline.Instance){
// Add function to check if Agent exists
l.Config.AutoComplete = AgentCompleter
l.SetPrompt(fmt.Sprintf(prompt,agentName))
for {
line, err := l.Readline()
if err == readline.ErrInterrupt {
if len(line) == 0 {
break
} else {
continue
}
} else if err == io.EOF {
break
}
line = strings.TrimSpace(line)
switch line{
case "back":
backMain(l)
return
case "":
// Ignore when the user presses enter.
default:
AddCommand(agentName,line)
}
}
}
func HandleInput(line string ,l *readline.Instance) {
switch {
// Handle the use functions
case strings.HasPrefix(line, "use "):
temp := strings.Split(line," ")
if len(temp) > 1 {
agent := temp[1]
HandleAgentCommands(agent,l)
}
// Prints the Agents
case strings.HasPrefix(line, "agents"):
PrintAgents()
case strings.HasPrefix(line,""):
default:
fmt.Println("Invalid command")
}
}
func StartTerminal() {
l, err := readline.NewEx(&readline.Config{
Prompt: fmt.Sprintf(prompt,"main"),
HistoryFile: "history.tmp",
InterruptPrompt: "^C",
EOFPrompt: "exit",
AutoComplete: MainCompleter,
})
if err != nil {
panic(err)
}
defer l.Close()
for {
line, err := l.Readline()
if err == readline.ErrInterrupt {
if len(line) == 0 {
break
} else {
continue
}
} else if err == io.EOF {
break
}
line = strings.TrimSpace(line)
HandleInput(line,l)
}
}