Skip to content

Commit b121e2c

Browse files
committed
adds a get and getg method besides the already existing set/setg and unset/unsetg
1 parent 5596cee commit b121e2c

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

features/commands/help.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Feature: Help command
1919
connect Communicate with a host
2020
edit Edit the current module with $VISUAL or $EDITOR
2121
exit Exit the console
22+
get Gets the value of a variable
23+
getg Gets the value of a global variable
2224
go_pro Launch Metasploit web GUI
2325
grep Grep the output of another command
2426
help Help menu

lib/msf/core/rpc/v10/rpc_core.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ def rpc_stop
1515
self.service.stop
1616
end
1717

18+
def rpc_getg(var)
19+
val = framework.datastore[var]
20+
{ var.to_s => val.to_s }
21+
end
22+
1823
def rpc_setg(var, val)
1924
framework.datastore[var] = val
2025
{ "result" => "success" }

lib/msf/ui/console/command_dispatcher/core.rb

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ def commands
112112
"color" => "Toggle color",
113113
"exit" => "Exit the console",
114114
"edit" => "Edit the current module with $VISUAL or $EDITOR",
115+
"get" => "Gets the value of a variable",
116+
"getg" => "Gets the value of a global variable",
115117
"go_pro" => "Launch Metasploit web GUI",
116118
"grep" => "Grep the output of another command",
117119
"help" => "Help menu",
@@ -2295,6 +2297,86 @@ def cmd_unload_tabs(str, words)
22952297
return tabs
22962298
end
22972299

2300+
def cmd_get_help
2301+
print_line "Usage: get var1 var2 var3"
2302+
print_line
2303+
print_line "The get command is used to get the value of one or more variables."
2304+
print_line
2305+
end
2306+
2307+
#
2308+
# Gets a value if it's been set.
2309+
#
2310+
def cmd_get(*args)
2311+
2312+
# Figure out if these are global variables
2313+
global = false
2314+
2315+
if (args[0] == '-g')
2316+
args.shift
2317+
global = true
2318+
end
2319+
2320+
# Determine which data store we're operating on
2321+
if (active_module and global == false)
2322+
datastore = active_module.datastore
2323+
else
2324+
datastore = framework.datastore
2325+
end
2326+
2327+
# No arguments? No cookie.
2328+
if (args.length == 0)
2329+
cmd_get_help
2330+
return false
2331+
end
2332+
2333+
while ((val = args.shift))
2334+
print_line("#{val} => #{datastore[val]}")
2335+
end
2336+
end
2337+
2338+
#
2339+
# Tab completion for the get command
2340+
#
2341+
# @param str [String] the string currently being typed before tab was hit
2342+
# @param words [Array<String>] the previously completed words on the command line. words is always
2343+
# at least 1 when tab completion has reached this stage since the command itself has been completed
2344+
2345+
def cmd_get_tabs(str, words)
2346+
datastore = active_module ? active_module.datastore : self.framework.datastore
2347+
datastore.keys
2348+
end
2349+
2350+
2351+
def cmd_getg_help
2352+
print_line "Usage: getg var1 [var2 ...]"
2353+
print_line
2354+
print_line "Exactly like get -g, get global variables"
2355+
print_line
2356+
end
2357+
2358+
#
2359+
# Gets variables in the global data store.
2360+
#
2361+
def cmd_getg(*args)
2362+
args.unshift('-g')
2363+
2364+
cmd_get(*args)
2365+
end
2366+
2367+
#
2368+
# Tab completion for the getg command
2369+
#
2370+
# @param str [String] the string currently being typed before tab was hit
2371+
# @param words [Array<String>] the previously completed words on the command line. words is always
2372+
# at least 1 when tab completion has reached this stage since the command itself has been completed
2373+
2374+
def cmd_getg_tabs(str, words)
2375+
self.framework.datastore.keys
2376+
end
2377+
2378+
alias cmd_getg_help cmd_get_help
2379+
22982380
def cmd_unset_help
22992381
print_line "Usage: unset [-g] var1 var2 var3 ..."
23002382
print_line

0 commit comments

Comments
 (0)