@@ -112,6 +112,8 @@ def commands
112
112
"color" => "Toggle color" ,
113
113
"exit" => "Exit the console" ,
114
114
"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" ,
115
117
"go_pro" => "Launch Metasploit web GUI" ,
116
118
"grep" => "Grep the output of another command" ,
117
119
"help" => "Help menu" ,
@@ -2295,6 +2297,86 @@ def cmd_unload_tabs(str, words)
2295
2297
return tabs
2296
2298
end
2297
2299
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
+
2298
2380
def cmd_unset_help
2299
2381
print_line "Usage: unset [-g] var1 var2 var3 ..."
2300
2382
print_line
0 commit comments