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

Add profiling tools #13057

Merged
merged 2 commits into from
Mar 13, 2020
Merged

Add profiling tools #13057

merged 2 commits into from
Mar 13, 2020

Conversation

adfoster-r7
Copy link
Contributor

@adfoster-r7 adfoster-r7 commented Mar 11, 2020

Continuing on the awesome work from #12652 this PR adds profiling tools for CPU and memory.

METASPLOIT_CPU_PROFILE

Generates various useful reports.

Stack view

image

Graph view

image

There is also an ascii flat view.

Note This uses ruby-prof under the hood, to generate a different style of report you can supply additional ENV args. The default value is RubyProf::WALL_TIME. You may can specify the measure mode by using the RUBY_PROF_MEASURE_MODE environment variable:

export RUBY_PROF_MEASURE_MODE=wall
export RUBY_PROF_MEASURE_MODE=process
export RUBY_PROF_MEASURE_MODE=allocations
export RUBY_PROF_MEASURE_MODE=memory

METASPLOIT_MEMORY_PROFILE

Although the cpu/ruby-prof report can give similar insights, the memory profile can be easier to understand:

Total allocated: 359069342 bytes (4122901 objects)
Total retained:  56207062 bytes (367424 objects)

allocated memory by gem
-----------------------------------
 198248069  metasploit-framework/lib
  38101324  activesupport-4.2.11.1
  37770426  pathname
  16573387  aws-sdk-ec2-1.146.0

...

Enabling

After setting the environment variables, metasploit will now begin profiling.

  • METASPLOIT_CPU_PROFILE=true ./msfconsole
  • METASPLOIT_MEMORY_PROFILE=true ./msfconsole

The report will be generated when metasploit exits.

Verification

List the steps needed to make sure this thing works

  • Verify METASPLOIT_CPU_PROFILE=true ./msfconsole -x 'exit' creates various CPU profile reports

  • Verify METASPLOIT_MEMORY_PROFILE=true ./msfconsole -x 'exit' creates various memory profile reports

  • Verify METASPLOIT_CPU_PROFILE=true ./msfvenom -x 'exit' creates various CPU profile reports

  • Verify METASPLOIT_MEMORY_PROFILE=true ./msfvenom -x 'exit' creates various memory profile reports

@busterb
Copy link
Member

busterb commented Mar 11, 2020

This is beautiful!

@@ -39,12 +39,56 @@ def spinner
end
end

def start_profiler
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a note, since this is more generic than just the code in this file I would prefer it to live in a more generic place where it could be started (and possibly stopped) independent of the framework console. Somewhere like lib/metasploit/framework/profile.rb or lib/msf/core/profile.rb should work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, thanks!

I've ripped it out, and ensured that it can be called from msfvenom too 👍

@dwelch-r7 dwelch-r7 self-assigned this Mar 13, 2020
@dwelch-r7 dwelch-r7 merged commit 786c968 into rapid7:master Mar 13, 2020
@dwelch-r7
Copy link
Contributor

dwelch-r7 commented Mar 13, 2020

Release Notes

Profiling tools for looking at memory and CPU utilization have been added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement rn-enhancement release notes enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants