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

Improve accuracy of msfconsole performance profiling #17744

Conversation

adfoster-r7
Copy link
Contributor

Improves the accuracy of msfconsole performance profiling

Verification

Verify profiling reports still work as expected:

METASPLOIT_CPU_PROFILE=true ./msfconsole -x 'exit'
METASPLOIT_MEMORY_PROFILE=true ./msfconsole -x 'exit'

@adfoster-r7 adfoster-r7 added the rn-enhancement release notes enhancement label Mar 7, 2023
Copy link
Contributor

@gwillcox-r7 gwillcox-r7 left a comment

Choose a reason for hiding this comment

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

Looks good! This will now also measure the speed of loading the msfenv library as well as the libraries needed to run the console itself.

@gwillcox-r7 gwillcox-r7 self-assigned this Mar 7, 2023
@gwillcox-r7
Copy link
Contributor

gwillcox-r7 commented Mar 7, 2023

CPU profile seems to be working:

image

Can also see the generated report renders properly:

image

@gwillcox-r7
Copy link
Contributor

gwillcox-r7 commented Mar 7, 2023

Unfortunately the memory dump appears to be crashing on my machine due to getting a SIGKILL message for some reason?

 ~/git/metasploit-framework │ land-pr17744:pr/17744 ?32  METASPLOIT_MEMORY_PROFILE=true ./msfconsole -x 'exit'                                                 ✔ │ 1m 59s │ 3.0.5  │ 11:07:05 
                                                  

Unable to handle kernel NULL pointer dereference at virtual address 0xd34db33f
EFLAGS: 00010046
eax: 00000001 ebx: f77c8c00 ecx: 00000000 edx: f77f0001
esi: 803bf014 edi: 8023c755 ebp: 80237f84 esp: 80237f60
ds: 0018   es: 0018  ss: 0018
Process Swapper (Pid: 0, process nr: 0, stackpage=80377000)


Stack: 90909090990909090990909090
       90909090990909090990909090
       90909090.90909090.90909090
       90909090.90909090.90909090
       90909090.90909090.09090900
       90909090.90909090.09090900
       ..........................
       cccccccccccccccccccccccccc
       cccccccccccccccccccccccccc
       ccccccccc.................
       cccccccccccccccccccccccccc
       cccccccccccccccccccccccccc
       .................ccccccccc
       cccccccccccccccccccccccccc
       cccccccccccccccccccccccccc
       ..........................
       ffffffffffffffffffffffffff
       ffffffff..................
       ffffffffffffffffffffffffff
       ffffffff..................
       ffffffff..................
       ffffffff..................


Code: 00 00 00 00 M3 T4 SP L0 1T FR 4M 3W OR K! V3 R5 I0 N5 00 00 00 00
Aiee, Killing Interrupt handler
Kernel panic: Attempted to kill the idle task!
In swapper task - not syncing


       =[ metasploit v6.3.6-dev-6e06d1e6f8                ]
+ -- --=[ 2297 exploits - 1202 auxiliary - 410 post       ]
+ -- --=[ 968 payloads - 45 encoders - 11 nops            ]
+ -- --=[ 9 evasion                                       ]

Metasploit tip: Use the analyze command to suggest 
runnable modules for hosts
Metasploit Documentation: https://docs.metasploit.com/

Generating memory dump /tmp/msf-profile-2023030711103620230307-798230-usawzy/memory
[1]    798230 killed     METASPLOIT_MEMORY_PROFILE=true ./msfconsole -x 'exit'
 ~/git/metasploit-framework │ land-pr17744:pr/17744 ?32  ls /tmp/msf-profile-2023030711103620230307-798230-usawzy/memory                                     KILL ✘ │ 36s │ 3.0.5  │ 11:11:10 
ls: cannot access '/tmp/msf-profile-2023030711103620230307-798230-usawzy/memory': No such file or directory
 ~/git/metasploit-framework │ land-pr17744:pr/17744 ?32  ls -alh /tmp/msf-profile-2023030711103620230307-798230-usawzy/memory                                         2 ✘ │ 3.0.5  │ 11:11:27 
ls: cannot access '/tmp/msf-profile-2023030711103620230307-798230-usawzy/memory': No such file or directory
 ~/git/metasploit-framework │ land-pr17744:pr/17744 ?32    

@gwillcox-r7
Copy link
Contributor

After speaking to @adfoster-r7 about above issue with memory profiling it seems this was an existing issue and is not related to these changes. Will land this in its current state and then we can look into fixing up the memory profiling code. For reference this failed in the same way on a Ubuntu 22.04 LTS system with OhMyZSH shell both on the native shell and within a shell spawned from within RubyMine.

@gwillcox-r7 gwillcox-r7 merged commit 795b9c9 into rapid7:master Mar 7, 2023
@gwillcox-r7
Copy link
Contributor

gwillcox-r7 commented Mar 7, 2023

Release Notes

The code for msfconsole has been updated so that performance profiling can also take into account the time it takes to load msfenv and console related libraries, thereby allowing for more accurate performance profiling.

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
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants