@@ -16,76 +16,84 @@ import (
1616)
1717
1818func Commands (con * core.Console ) []* cobra.Command {
19- listModuleCmd := & cobra.Command {
20- Use : consts .ModuleListModule ,
19+ moduleCmd := & cobra.Command {
20+ Use : consts .CommandModule ,
21+ Short : "Module management" ,
22+ }
23+
24+ listCmd := & cobra.Command {
25+ Use : "list" ,
2126 Short : "List modules" ,
22- // Long: help.FormatLongHelp(consts.ModuleListModule),
2327 RunE : func (cmd * cobra.Command , args []string ) error {
2428 return ListModulesCmd (cmd , con )
2529 },
2630 }
2731
28- loadModuleCmd := & cobra.Command {
29- Use : consts . ModuleLoadModule + " [module_file]" ,
32+ loadCmd := & cobra.Command {
33+ Use : "load [module_file]" ,
3034 Short : "Load module" ,
31- // Long: help.FormatLongHelp(consts.ModuleLoadModule),duan
3235 RunE : func (cmd * cobra.Command , args []string ) error {
3336 return LoadModuleCmd (cmd , con )
3437 },
3538 Example : `load module from malefic-modules
36- before loading, you can list the current modules:
39+ before loading, you can list the current modules:
3740~~~
38- execute_addon,exec ...
41+ module list
3942~~~
4043then you can load module
4144~~~
42- load_module --path <module_file.dll>
45+ module load --path <module_file.dll>
4346~~~
44- you can see more modules loaded by list_module
47+ you can see more modules loaded by module list
4548~~~
4649execute_addon,clear,ps,powershell...
4750~~~
48- ` }
49-
50- common .BindFlag (loadModuleCmd , func (f * pflag.FlagSet ) {
51+ ` ,
52+ }
53+ common .BindFlag (loadCmd , func (f * pflag.FlagSet ) {
5154 f .String ("path" , "" , "module path" )
5255 f .String ("modules" , "" , "modules list,eg: basic,extend" )
5356 f .StringP ("bundle" , "" , "" , "bundle name" )
5457 f .String ("3rd" , "" , "build 3rd-party modules" )
5558 f .String ("artifact" , "" , "exist module artifact" )
5659 })
57- common .BindFlagCompletions (loadModuleCmd , func (comp carapace.ActionMap ) {
60+ common .BindFlagCompletions (loadCmd , func (comp carapace.ActionMap ) {
5861 comp ["path" ] = carapace .ActionFiles ()
5962 comp ["modules" ] = common .ModulesCompleter ()
6063 comp ["artifact" ] = common .ModuleArtifactsCompleter (con )
6164 })
62- common .BindArgCompletions (loadModuleCmd , nil ,
65+ common .BindArgCompletions (loadCmd , nil ,
6366 carapace .ActionFiles ().Usage ("path to the module file" ))
6467
65- refreshModuleCmd := & cobra.Command {
66- Use : consts .ModuleRefreshModule ,
68+ unloadCmd := & cobra.Command {
69+ Use : "unload [bundle_name]" ,
70+ Short : "Unload a module bundle by name" ,
71+ Args : cobra .ExactArgs (1 ),
72+ RunE : func (cmd * cobra.Command , args []string ) error {
73+ return UnloadModuleCmd (cmd , con )
74+ },
75+ }
76+ common .BindArgCompletions (unloadCmd , nil ,
77+ common .SessionModuleCompleter (con ).Usage ("bundle name to unload" ))
78+
79+ refreshCmd := & cobra.Command {
80+ Use : "refresh" ,
6781 Short : "Refresh module" ,
68- // Long: help.FormatLongHelp(consts.ModuleRefreshModule),
6982 RunE : func (cmd * cobra.Command , args []string ) error {
7083 return RefreshModuleCmd (cmd , con )
7184 },
7285 }
7386
7487 clearCmd := & cobra.Command {
75- Use : consts .ModuleClear ,
76- Short : "Clear modules" ,
77- // Long: help.FormatLongHelp(consts.ModuleClear),
88+ Use : "clear" ,
89+ Short : "Clear all modules" ,
7890 RunE : func (cmd * cobra.Command , args []string ) error {
7991 return ClearCmd (cmd , con )
8092 },
8193 }
8294
83- return []* cobra.Command {
84- listModuleCmd ,
85- loadModuleCmd ,
86- refreshModuleCmd ,
87- clearCmd ,
88- }
95+ moduleCmd .AddCommand (listCmd , loadCmd , unloadCmd , refreshCmd , clearCmd )
96+ return []* cobra.Command {moduleCmd }
8997}
9098
9199func Register (con * core.Console ) {
@@ -108,17 +116,21 @@ func Register(con *core.Console) {
108116 var rowEntries []table.Row
109117 var row table.Row
110118 tableModel := tui .NewTable ([]table.Column {
111- table .NewFlexColumn ("Module" , "Module" , 1 ),
112- table .NewFlexColumn ("Help" , "Help" , 2 ),
119+ table .NewFlexColumn ("Module" , "Module" , 2 ),
120+ table .NewFlexColumn ("Bundle" , "Bundle" , 1 ),
121+ table .NewFlexColumn ("Help" , "Help" , 3 ),
113122 }, true )
123+ bundleMap := modules .GetBundleMap ()
114124 for _ , module := range modules .GetModules () {
115125 var short string
116126 if cmd := con .CMDs [module ]; cmd != nil {
117127 short = cmd .Short
118128 }
129+ bundle := bundleMap [module ]
119130 row = table .NewRow (
120131 table.RowData {
121132 "Module" : module ,
133+ "Bundle" : bundle ,
122134 "Help" : short ,
123135 })
124136 rowEntries = append (rowEntries , row )
@@ -152,6 +164,61 @@ func Register(con *core.Console) {
152164 },
153165 []string {"task" })
154166
167+ con .RegisterImplantFunc (
168+ consts .ModuleUnloadModule ,
169+ unloadModule ,
170+ "" ,
171+ nil ,
172+ func (ctx * clientpb.TaskContext ) (interface {}, error ) {
173+ resp := ctx .Spite .GetModules ()
174+ ctx .Session .Modules = resp .Modules
175+ con .RefreshCmd (con .AddSession (ctx .Session ))
176+ return resp .Modules , nil
177+ },
178+ func (content * clientpb.TaskContext ) (string , error ) {
179+ modules := content .Spite .GetModules ()
180+ remaining := modules .GetModules ()
181+ if len (remaining ) == 0 {
182+ return "All modules unloaded." , nil
183+ }
184+
185+ var rowEntries []table.Row
186+ var row table.Row
187+ tableModel := tui .NewTable ([]table.Column {
188+ table .NewFlexColumn ("Module" , "Module" , 2 ),
189+ table .NewFlexColumn ("Bundle" , "Bundle" , 1 ),
190+ table .NewFlexColumn ("Help" , "Help" , 3 ),
191+ }, true )
192+ bundleMap := modules .GetBundleMap ()
193+ for _ , module := range remaining {
194+ var short string
195+ if cmd := con .CMDs [module ]; cmd != nil {
196+ short = cmd .Short
197+ }
198+ bundle := bundleMap [module ]
199+ row = table .NewRow (
200+ table.RowData {
201+ "Module" : module ,
202+ "Bundle" : bundle ,
203+ "Help" : short ,
204+ })
205+ rowEntries = append (rowEntries , row )
206+ }
207+ tableModel .SetMultiline ()
208+ tableModel .SetRows (rowEntries )
209+ return "Unloaded successfully. Remaining modules:\n " + tableModel .View (), nil
210+ })
211+
212+ con .AddCommandFuncHelper (
213+ consts .ModuleUnloadModule ,
214+ consts .ModuleUnloadModule ,
215+ consts .ModuleUnloadModule + "(active(),\" bundle_name\" )" ,
216+ []string {
217+ "session: special session" ,
218+ "bundle: bundle name to unload" ,
219+ },
220+ []string {"task" })
221+
155222 con .RegisterImplantFunc (
156223 consts .ModuleRefreshModule ,
157224 refreshModule ,
@@ -173,7 +240,7 @@ func Register(con *core.Console) {
173240 },
174241 []string {"task" })
175242
176- //clear
243+ // clear
177244 con .RegisterImplantFunc (
178245 consts .ModuleClear ,
179246 clearAll ,
0 commit comments