Globalizing variables in Metasploit
Working on a particular range or a specific host, we can always use the setg
command to specify the LHOST
and RHOST
options. Setting the options with the setg
command will set the RHOST
or LHOST
options globally for every module loaded. Hence, the setg
command eliminates the use of setting up these specific options repeatedly. We can should make use of the setg
command instead of options such as LPORT
, RPORT
, and payload
. However, different services run on different ports and we may need to alter the payloads as well. Hence, setting up options that do not alter from one module to another is a better approach. Let's have a look at an example:
We assigned RHOST
with setg
command in the preceding screenshot. We can see that no matter how many times we change the module, the value of RHOST
remains constant for all modules and we do not need to enter it manually in every module. The get
command fetches the value of a variable from the current context...