FS#66480 - [metasploit] irb.rb not found

Attached to Project: Community Packages
Opened by gch (gch) - Thursday, 30 April 2020, 16:10 GMT
Last edited by Levente Polyak (anthraxx) - Monday, 18 July 2022, 17:55 GMT
Task Type Bug Report
Category Packages
Status Closed
Assigned To Levente Polyak (anthraxx)
Architecture x86_64
Severity Medium
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 1
Private No

Details

Description:
Cannot run 'irb' in msfconsole.
Package version : community/metasploit 5.0.86-1

Steps to reproduce:
In msfconsole, run 'irb' then enter.
The following message is displayed:
```
[-] Error while running command irb: cannot load such file -- irb.rb
```

I'm not sure this is due to the archlinux package.

By looking in the source code, msfconsole try to run load('irb.rb') in lib/rex/ui/text/irb_shell.rb.

I have two 'irb.rb' files on my system:
- /usr/lib/ruby/gems/2.7.0/gems/irb-1.2.1/lib
- /opt/ruby2.6/lib/ruby/2.6.0/

I can bypass this failure with the following:
```
msf5> irb -e '$LOAD_PATH << "/opt/ruby2.6/lib/ruby/2.6.0/"' # or the 1st one
[*] Starting IRB shell...
[*] You are in the "framework" object

/opt/ruby2.6/lib/ruby/2.6.0/irb/workspace.rb:52: warning: calling private without arguments inside a method may not have the intended effect
irb: warn: can't alias jobs from irb_jobs.
>> 1+1
=>2
```

And yes 'irb -e "<ruby code>"' works.
I don't get the warning message when add "/usr/lib/ruby/gems/2.7.0/gems/irb-1.2.1/lib" to $LOAD_PATH.

This task depends upon

Closed by  Levente Polyak (anthraxx)
Monday, 18 July 2022, 17:55 GMT
Reason for closing:  Fixed
Comment by Alexandre ZANNI (noraj) - Thursday, 21 May 2020, 20:52 GMT
`/opt/ruby2.6/lib/ruby/2.6.0/` is there only because you installed ruby2.6 package.

The workaround that works with the standard ruby package is (as you said):

```
$ msfconsole -q
msf5 > irb -e '$LOAD_PATH << "/usr/lib/ruby/gems/2.7.0/gems/irb-1.2.1/lib/"'
msf5 > irb
[*] Starting IRB shell...
[*] You are in the "framework" object

irb: warn: can't alias jobs from irb_jobs.
>>
```
Comment by gch (gch) - Saturday, 23 May 2020, 15:26 GMT
Thanks for the comment. I figured this out by testing the default installation on various OS and using various installation methods.
I think this report could be closed.
Comment by Alexandre ZANNI (noraj) - Sunday, 24 May 2020, 01:24 GMT
The is still the error on ArchLinux, on other OSes using the irb command inside msfconsole instantly works without tricks.

When ghc said "I think this report could be closed." it's because he think this issue a support demand rather than a bug report.

Also when he says "I figured this out by testing the default installation on various OS and using various installation methods.", he means the fact that irb.rb exists in /opt/ruby2.6/lib/ruby/2.6.0/ not the fact that the bug exists on other oses.
Comment by Levente Polyak (anthraxx) - Sunday, 24 May 2020, 10:08 GMT
This is a missing declaration of dependencies in metasploit, we just package a bundled version in opt using exactly what metasploit declares. The hacks you are using override the load path to include system packages where you have irb installed.
if irb is required, which seems to be the case for this feature, it should be declared explicitly so bundler can pick it up.
Comment by Alexandre ZANNI (noraj) - Sunday, 24 May 2020, 14:29 GMT
@anthraxx I opened an upstream issue and PR: https://github.com/rapid7/metasploit-framework/issues/13513

In the meantime we should maybe add a sed command in a prepare() statement to temporarily patch/workaround this.
Comment by Alexandre ZANNI (noraj) - Friday, 29 May 2020, 00:50 GMT Comment by gch (gch) - Friday, 29 May 2020, 07:51 GMT
@noraj: thanks for taking the lead on this. Really appreciated :-)
Comment by Levente Polyak (anthraxx) - Monday, 18 July 2022, 17:55 GMT
Seems this issue got left open for a long time, thanks a lot for the fix and the work. closing finally :)

Loading...