/
menu.go
78 lines (69 loc) · 2.75 KB
/
menu.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
// Merlin is a post-exploitation command and control framework.
// This file is part of Merlin.
// Copyright (C) 2021 Russel Van Tuyl
// Merlin is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
// Merlin is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Merlin. If not, see <http://www.gnu.org/licenses/>.
package menu
import (
"github.com/Ne0nd0g/merlin/pkg/cli/core"
)
var handler func([]string)
const (
// MAIN is for the main menu
MAIN = iota
// AGENT is for the agent menu
AGENT
// MODULE is for the module menu
MODULE
// LISTENER is for a specific, already instantiated, listener menu
LISTENER
// LISTENERS is for the top-level listeners menu
LISTENERS
// LISTENERSETUP is the menu used to configure listener options before creation
LISTENERSETUP
)
// Handle receives commands entered on the command line and processes them to take an action
func Handle(cmd []string) {
handler(cmd)
}
// Set configures the CLI's to use a specific menu system. Typically, used to switch between menus.
func Set(m int) {
switch m {
case AGENT:
handler = handlerAgent
core.Prompt.SetPrompt("\033[31mMerlin[\033[32magent\033[31m][\033[33m" + agent.String() + "\033[31m]»\033[0m ")
core.Prompt.Config.AutoComplete = completerAgent()
case LISTENER:
handler = handlerListener
core.Prompt.SetPrompt("\033[31mMerlin[\033[32mlisteners\033[31m][\033[33m" + listener.name + "\033[31m]»\033[0m ")
core.Prompt.Config.AutoComplete = completerListener()
case LISTENERS:
handler = handlerListeners
core.Prompt.SetPrompt("\033[31mMerlin[\033[32mlisteners\033[31m]»\033[0m ")
core.Prompt.Config.AutoComplete = completerListeners()
case LISTENERSETUP:
handler = handlerListenerSetup
core.Prompt.SetPrompt("\033[31mMerlin[\033[32mlisteners\033[31m][\033[33m" + listenerType + "\033[31m]»\033[0m ")
core.Prompt.Config.AutoComplete = completerListenerSetup()
case MAIN:
handler = handlerMain
core.Prompt.SetPrompt("\u001B[31mMerlin»\u001B[0m ")
core.Prompt.Config.AutoComplete = completerMain()
case MODULE:
handler = handlerModule
core.Prompt.SetPrompt("\033[31mMerlin[\033[32mmodule\033[31m][\033[33m" + module.Name + "\033[31m]»\033[0m ")
core.Prompt.Config.AutoComplete = completerModule()
default:
handler = handlerMain
core.Prompt.SetPrompt("\u001B[31mMerlin»\u001B[0m ")
core.Prompt.Config.AutoComplete = completerMain()
}
}