Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support <ruby> directives in Meterpreter rc scripts #9145

Merged
merged 1 commit into from Nov 1, 2017

Conversation

zeroSteiner
Copy link
Contributor

@zeroSteiner zeroSteiner commented Oct 29, 2017

Per @egypt's request in #8702, this PR adds support to Meterpreter's resource command to process <ruby> directives. This also adds tab completion support for an option meterpreter sub directory under the existing resource scripts directory. This is because the context of the two are different enough that it would be beneficial to keep them separate as alot of the commands would not work in both contexts.

Alot of the code is copy and pasted, if anyone has a suggestion on where it could be placed to be reused just let me know and I'll get it all refactored.

Verification

List the steps needed to make sure this thing works

  • Create a resource script at ~/.msf4/scripts/resource/meterpreter/foo.rc with the following contents
sysinfo
<ruby>
$stderr.puts("session.platform: #{session.platform}, framework: #{framework}")
</ruby>
  • Start msfconsole
  • Get a meterpreter session some how
  • Type resource then try and tab complete the meterpreter rc scripts
  • See foo.rc displayed in the completion suggestions
  • Run resource foo.rc and see:
    • The sysinfo output, showing normal commands are still run
    • The session platform, showing that the session object is exposed

Example Output

meterpreter > resource 
resource .dockerignore                 resource .ruby-gemset                  resource CONTRIBUTING.md               resource LICENSE                       resource foo.rc                        resource msfupdate
resource .gitignore                    resource .ruby-version                 resource COPYING                       resource LICENSE_GEMS                  resource metasploit-framework.gemspec  resource msfvenom
resource .gitmodules                   resource .simplecov                    resource Dockerfile                    resource README.md                     resource msfconsole                    
resource .mailmap                      resource .travis.yml                   resource Gemfile                       resource Rakefile                      resource msfd                          
resource .rspec                        resource .yardopts                     resource Gemfile.local.example         resource Vagrantfile                   resource msfrpc                        
resource .rubocop.yml                  resource CODE_OF_CONDUCT.md            resource Gemfile.lock                  resource docker-compose.yml            resource msfrpcd                       
meterpreter > resource foo.rc 
[*] Processing /home/steiner/.msf4/scripts/resource/meterpreter/foo.rc for ERB directives.
resource (/home/steiner/.msf4/scripts/resource/meterpreter/foo.rc)> sysinfo
Computer        : localhost.localdomain
OS              : Linux 4.13.5-200.fc26.x86_64 #1 SMP Thu Oct 5 16:53:13 UTC 2017
Architecture    : x64
System Language : en_US
Meterpreter     : python/linux
[*] resource (/home/steiner/.msf4/scripts/resource/meterpreter/foo.rc)> Ruby Code (79 bytes)
session.platform: linux, framework: #<Msf::Framework:0x000000000560a630>
meterpreter > 

@wvu
Copy link
Contributor

wvu commented Oct 29, 2017

You rock. Thanks for implementing this.

@wvu
Copy link
Contributor

wvu commented Nov 1, 2017

I believe when we found this and tried to move load_resource, we didn't find an immediately ideal place for it. What you've done is fine. There's already a nauseating amount of crossover between command dispatchers, though...

@wvu wvu merged commit 940573a into rapid7:master Nov 1, 2017
wvu added a commit that referenced this pull request Nov 1, 2017
@bwatters-r7
Copy link
Contributor

Release Notes

This PR adds support for meterpreter's resource command to support rc scripts with inline ruby and ERB to make resource scripts run through meterpreter more powerful.

@tdoan-r7 tdoan-r7 added the rn-enhancement release notes enhancement label Nov 17, 2017
@zeroSteiner zeroSteiner deleted the met-rc-rb branch February 23, 2021 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature library rn-enhancement release notes enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants