Search code examples
rubycommand-line-argumentsmetasploit

How can I pass arguments to msfconsole -r resource.rc <arg1> <arg2>


So everything is in the title. Is there a way I can pass arguments to :

msf> resource path/to/resource.rc <arg1> <arg2>

Or

msfconsole -r resource.rc <arg1> <arg2>

Those arguments would passed into the ruby resource code as follow:

<ruby>
 ip   = ARGV[1]
 port = ARGV[2]
...
...
</ruby>

Solution

  • Unfortunately resource files don't accept arguments, but they do accept ruby blocks. So you can do it with a bit of trickery. Make a resource file that looks something like this:

    Where it's using the ruby ENV command to pull in the environmental variable "DSTIP"

    metasploit-framework [git:master]$ cat /tmp/test.rc
    <ruby>
    run_single("set RHOST #{ENV['DSTIP']}")
    </ruby>
    

    Now when I run msfconsole, I can set that DSTIP variable and it will set the RHOST when I start up MSF to whatever was in that environmental variable:

    metasploit-framework [git:master]$ DSTIP=192.168.1.1 ./msfconsole -r /tmp/test.rc -Lq
    [*] Processing /tmp/test.rc for ERB directives.
    [*] resource (/tmp/test.rc)> Ruby Code (40 bytes)
    RHOST => 192.168.1.1
    

    You can do this with as many environmental variables as you want. Now if you want to run it from within MSFCONSOLE I tried changing the environmental variable after msfconsole was running with no luck. I'm sure there is a way that a beardy linux master will have to do it but I don't I'm sorry.

    Side note: you can also use ruby file reads to pull in text from. (Think configuration file)

    Hope this help!

    mubix