rapid7 / metasploit-framework

Metasploit Framework
https://www.metasploit.com/
Other
34.07k stars 13.95k forks source link

stream closed in another thread (IOError) #18462

Closed gh0x0st closed 9 months ago

gh0x0st commented 1 year ago

Steps to reproduce

When launching msfconsole through an alias alias c2-win64-https='sudo msfconsole -q -x "use exploit/multi/handler; set PAYLOAD windows/x64/meterpreter/reverse_https; set HandlerSSLCert /home/kali/PEN-300/Network Filters/defender.pem; set SSLVERSION TLS1.2; set LHOST 192.168.45.181; set LPORT 443; set EXITFUNC thread; exploit"'. The alias is likely irrelevant as I also get the same behavior randomly when running just msfconsole from the terminal.

Current behavior

When this occurs the program is rendered inoperable. For example, when running via the aforementioned alias the last error mentioned is '[-] Unknown command: exploit'.

┌──(kali㉿kali)-[~]
└─$ msfconsole       

 ______________________________________
/ it looks like you're trying to run a \                                                                                                                              
\ module                               /                                                                                                                              
 --------------------------------------                                                                                                                               
 \                                                                                                                                                                    
  \                                                                                                                                                                   
     __                                                                                                                                                               
    /  \                                                                                                                                                              
    |  |                                                                                                                                                              
    @  @                                                                                                                                                              
    |  |                                                                                                                                                              
    || |/                                                                                                                                                             
    || ||                                                                                                                                                             
    |\_/|                                                                                                                                                             
    \___/                                                                                                                                                             

       =[ metasploit v6.3.31-dev                          ]
+ -- --=[ 2346 exploits - 1220 auxiliary - 413 post       ]
+ -- --=[ 1387 payloads - 46 encoders - 11 nops           ]
+ -- --=[ 9 evasion                                       ]

Metasploit tip: Use sessions -1 to interact with the 
last opened session
Metasploit Documentation: https://docs.metasploit.com/

/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/rb-readline-0.5.5/lib/rbreadline.rb:6968:in ``': stream closed in another thread (IOError)
        from /usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/rb-readline-0.5.5/lib/rbreadline.rb:6968:in `block in save_tty_chars'
        from /usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/rb-readline-0.5.5/lib/rbreadline.rb:6957:in `retry_if_interrupted'
        from /usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/rb-readline-0.5.5/lib/rbreadline.rb:6967:in `save_tty_chars'
        from /usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/rb-readline-0.5.5/lib/rbreadline.rb:7072:in `rl_prep_terminal'
        from /usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/rb-readline-0.5.5/lib/rbreadline.rb:4871:in `readline'
        from /usr/share/metasploit-framework/lib/rex/ui/text/input/readline.rb:161:in `readline_with_output'
        from /usr/share/metasploit-framework/lib/rex/ui/text/input/readline.rb:99:in `pgets'
        from /usr/share/metasploit-framework/lib/rex/ui/text/shell.rb:329:in `get_input_line'
        from /usr/share/metasploit-framework/lib/rex/ui/text/shell.rb:145:in `block in run'
        from /usr/share/metasploit-framework/lib/rex/ui/text/shell/history_manager.rb:35:in `with_context'
        from /usr/share/metasploit-framework/lib/rex/ui/text/shell.rb:133:in `run'
        from /usr/share/metasploit-framework/lib/metasploit/framework/command/console.rb:48:in `start'
        from /usr/share/metasploit-framework/lib/metasploit/framework/command/base.rb:82:in `start'
        from /usr/bin/msfconsole:23:in `<main>'

Metasploit version

msf6 > version
Framework: 6.3.31-dev
Console  : 6.3.31-dev

Additional Information

This occurred on a fresh install on the latest weekly build of Kali Linux and in previous builds as well. I reinstalled the metasploit-framework package and it still randomly occurs.

smcintyre-r7 commented 1 year ago

I also get the same behavior randomly when running just msfconsole from the terminal.

I think I've seen this before as well where these errors come up randomly when starting Metasploit. Is the stack trace always the same or does it change when you do get the error?

gh0x0st commented 1 year ago

I also get the same behavior randomly when running just msfconsole from the terminal.

I think I've seen this before as well where these errors come up randomly when starting Metasploit. Is the stack trace always the same or does it change when you do get the error?

It looks like it's always the same for me

s3cur3c1ph3r commented 1 year ago

I am also having this issue

$ sudo msfdb init && msfconsole
[sudo] password for securecipher: 
Metasploit running on Kali Linux as root, using system database
A database appears to be already configured, skipping initialization
Metasploit tip: View missing module options with show missing

Call trans opt: received. 2-19-98 13:24:18 REC:Loc

     Trace program: running

           wake up, Neo...
        the matrix has you
      follow the white rabbit.

          knock, knock, Neo.

                        (`.         ,-,
                        ` `.    ,;' /
                         `.  ,'/ .'
                          `. X /.'
                .-;--''--.._` ` (
              .'            /   `
             ,           ` '   Q '
             ,         ,   `._    \
          ,.|         '     `-.;_'
          :  . `  ;    `  ` --,.._;
           ' `    ,   )   .'
              `._ ,  '   /_
                 ; ,''-,;' ``-
                  ``-..__``--`

                             https://metasploit.com

       =[ metasploit v6.3.38-dev-                         ]
+ -- --=[ 2365 exploits - 1228 auxiliary - 413 post       ]
+ -- --=[ 1391 payloads - 46 encoders - 11 nops           ]
+ -- --=[ 9 evasion                                       ]

Metasploit Documentation: https://docs.metasploit.com/

/opt/metasploit-framework/embedded/lib/ruby/gems/3.0.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require': stream closed in another thread (IOError)
    from /opt/metasploit-framework/embedded/lib/ruby/gems/3.0.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
    from /opt/metasploit-framework/embedded/lib/ruby/gems/3.0.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
    from /opt/metasploit-framework/embedded/lib/ruby/gems/3.0.0/gems/pry-0.14.2/lib/pry.rb:6:in `<top (required)>'
    from /opt/metasploit-framework/embedded/lib/ruby/gems/3.0.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
    from /opt/metasploit-framework/embedded/lib/ruby/gems/3.0.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
    from /opt/metasploit-framework/embedded/lib/ruby/gems/3.0.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
    from /opt/metasploit-framework/embedded/framework/lib/rex/ui/text/shell.rb:126:in `run'
    from /opt/metasploit-framework/embedded/framework/lib/metasploit/framework/command/console.rb:54:in `start'
    from /opt/metasploit-framework/embedded/framework/lib/metasploit/framework/command/base.rb:82:in `start'
    from /opt/metasploit-framework/bin/../embedded/framework/msfconsole:23:in `<main>'
stavoxnetworks commented 1 year ago

I am also seeing this issue and it only occurs if I run is as root. If I drop back to unprivileged and launch it with sudo, the issue disappears.

2023-10-20_20-27

gh0x0st commented 1 year ago

Updated metasploit-framework today, will see how things go with this issue.

msf6 > version
Framework: 6.3.38-dev
Console  : 6.3.38-dev
gh0x0st commented 1 year ago

I have not had this issue at all today since updating. @stavoxnetworks @s3cur3c1ph3r @smcintyre-r7 hopefully this solves it for you as well.

stavoxnetworks commented 1 year ago

I spoke too soon I suppose. The issue is back today and now its occurring both as root and under sudo. Previously it would come and go and I was able to avoid it at all via sudo. Now the error occurs on every launch.

Updated Error

Lankapatii commented 1 year ago

i am also having same issue it whether i run as a normal user or root user

Normal user:-

Screenshot from 2023-10-26 12-28-09

Root user:-

Screenshot from 2023-10-26 12-30-59

adfoster-r7 commented 1 year ago

I wasn't able to replicate this after a thousand runs on Kali with the following versions:

┌──(kali㉿kali)-[~]
└─$ ruby -e 'puts RUBY_DESCRIPTION'                
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux-gnu]

┌──(kali㉿kali)-[~]
└─$ msfconsole -v                                     
Framework Version: 6.3.39-dev

Script used to try and replicate:

for i in {1..1000}; do msfconsole -x 'use psexec; exit' || break; done

It's definitely an issue for some folk, I'm just not sure how to replicate.

gh0x0st commented 1 year ago

I wasn't able to replicate this after a thousand runs on Kali with the following versions:

┌──(kali㉿kali)-[~]
└─$ ruby -e 'puts RUBY_DESCRIPTION'                
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux-gnu]

┌──(kali㉿kali)-[~]
└─$ msfconsole -v                                     
Framework Version: 6.3.39-dev

Script used to try and replicate:

for i in {1..1000}; do msfconsole -x 'use psexec; exit' || break; done

It's definitely an issue for some folk, I'm just not sure how to replicate.

I can replicate it on demand using an alias with commands passed to msfconsole. However, I can't replicate it when i just run sudo msfconsole and then pass in a resource script vs using an alias.

Not Working

alias c2-win64-https='sudo msfconsole -q -x "use exploit/multi/handler; set PAYLOAD windows/x64/meterpreter/reverse_https; set HandlerSSLCert /home/kali/PEN-300/Network Filters/microsoft.pem; set SSLVERSION TLS1.2; set LHOST 192.168.45.229; set LPORT 443; set EXITFUNC thread; exploit"'

┌──(kali㉿kali)-[~]
└─$ c2-win64-https
[sudo] password for kali: 
[*] Starting persistent handler(s)...
[-] Error while running command use: stream closed in another thread

Call stack:
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:30:in `require'
/usr/share/metasploit-framework/lib/msf/ui/console/command_dispatcher/modules.rb:773:in `cmd_use'
/usr/share/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:581:in `run_command'
/usr/share/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:530:in `block in run_single'
/usr/share/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:524:in `each'
/usr/share/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:524:in `run_single'
/usr/share/metasploit-framework/lib/msf/ui/console/driver.rb:209:in `block in initialize'
/usr/share/metasploit-framework/lib/msf/ui/console/driver.rb:208:in `each'
/usr/share/metasploit-framework/lib/msf/ui/console/driver.rb:208:in `initialize'
/usr/share/metasploit-framework/lib/metasploit/framework/command/console.rb:66:in `new'
/usr/share/metasploit-framework/lib/metasploit/framework/command/console.rb:66:in `driver'
/usr/share/metasploit-framework/lib/metasploit/framework/command/console.rb:54:in `start'
/usr/share/metasploit-framework/lib/metasploit/framework/command/base.rb:82:in `start'
/usr/bin/msfconsole:23:in `<main>'
PAYLOAD => windows/x64/meterpreter/reverse_https
HandlerSSLCert => /home/kali/PEN-300/Network Filters/microsoft.pem
SSLVERSION => TLS1.2
LHOST => 192.168.45.229
LPORT => 443
EXITFUNC => thread
[-] Unknown command: exploit
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/rb-readline-0.5.5/lib/rbreadline.rb:6968:in ``': stream closed in another thread (IOError)
        from /usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/rb-readline-0.5.5/lib/rbreadline.rb:6968:in `block in save_tty_chars'
        from /usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/rb-readline-0.5.5/lib/rbreadline.rb:6957:in `retry_if_interrupted'
        from /usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/rb-readline-0.5.5/lib/rbreadline.rb:6967:in `save_tty_chars'
        from /usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/rb-readline-0.5.5/lib/rbreadline.rb:7072:in `rl_prep_terminal'
        from /usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/rb-readline-0.5.5/lib/rbreadline.rb:4871:in `readline'
        from /usr/share/metasploit-framework/lib/rex/ui/text/input/readline.rb:161:in `readline_with_output'
        from /usr/share/metasploit-framework/lib/rex/ui/text/input/readline.rb:99:in `pgets'
        from /usr/share/metasploit-framework/lib/rex/ui/text/shell.rb:341:in `get_input_line'
        from /usr/share/metasploit-framework/lib/rex/ui/text/shell.rb:142:in `block in run'
        from /usr/share/metasploit-framework/lib/rex/ui/text/shell.rb:309:in `block in with_history_manager_context'
        from /usr/share/metasploit-framework/lib/rex/ui/text/shell/history_manager.rb:35:in `with_context'
        from /usr/share/metasploit-framework/lib/rex/ui/text/shell.rb:306:in `with_history_manager_context'
        from /usr/share/metasploit-framework/lib/rex/ui/text/shell.rb:133:in `run'
        from /usr/share/metasploit-framework/lib/metasploit/framework/command/console.rb:54:in `start'
        from /usr/share/metasploit-framework/lib/metasploit/framework/command/base.rb:82:in `start'
        from /usr/bin/msfconsole:23:in `<main>'

Working

┌──(kali㉿kali)-[~]
└─$ sudo msfconsole -q
[*] Starting persistent handler(s)...
msf6 > resource /home/kali/PEN-300/C2/Listeners/win64-https.rc
[*] Processing /home/kali/PEN-300/C2/Listeners/win64-https.rc for ERB directives.
resource (/home/kali/PEN-300/C2/Listeners/win64-https.rc)> use exploit/multi/handler
[*] Using configured payload generic/shell_reverse_tcp
resource (/home/kali/PEN-300/C2/Listeners/win64-https.rc)> set PAYLOAD windows/x64/meterpreter/reverse_https
PAYLOAD => windows/x64/meterpreter/reverse_https
resource (/home/kali/PEN-300/C2/Listeners/win64-https.rc)> set HandlerSSLCert /home/kali/PEN-300/Network Filters/microsoft.pem
HandlerSSLCert => /home/kali/PEN-300/Network Filters/microsoft.pem
resource (/home/kali/PEN-300/C2/Listeners/win64-https.rc)> set SSLVERSION TLS1.2
SSLVERSION => TLS1.2
resource (/home/kali/PEN-300/C2/Listeners/win64-https.rc)> set LHOST 192.168.45.229
LHOST => 192.168.45.229
resource (/home/kali/PEN-300/C2/Listeners/win64-https.rc)> set LPORT 443
LPORT => 443
resource (/home/kali/PEN-300/C2/Listeners/win64-https.rc)> set EXITFUNC thread
EXITFUNC => thread
resource (/home/kali/PEN-300/C2/Listeners/win64-https.rc)> exploit

[*] Started HTTPS reverse handler on https://192.168.45.229:443
adfoster-r7 commented 1 year ago

Thanks for the extra replication steps; Unfortunately it still works for me everytime:

┌──(kali㉿kali)-[~]
└─$ alias c2-win64-https='sudo msfconsole -q -x "use exploit/multi/handler; set PAYLOAD windows/x64/meterpreter/reverse_https; set HandlerSSLCert ./gem-private_key.pem; set SSLVERSION TLS1.2; set LHOST 127.0.0.1; set LPORT 443; set EXITFUNC thread; exploit"'

┌──(kali㉿kali)-[~]
└─$ c2-win64-https 
[*] Using configured payload generic/shell_reverse_tcp
PAYLOAD => windows/x64/meterpreter/reverse_https
HandlerSSLCert => ./gem-private_key.pem
SSLVERSION => TLS1.2
LHOST => 127.0.0.1
LPORT => 443
EXITFUNC => thread
[!] You are binding to a loopback address by setting LHOST to 127.0.0.1. Did you want ReverseListenerBindAddress?
[*] Started HTTPS reverse handler on https://127.0.0.1:443

I think @smcintyre-r7 has run into this before, will sync up and see if we can replicate on his environment :+1:

gh0x0st commented 1 year ago

Thanks for the extra replication steps; Unfortunately it still works for me everytime:

┌──(kali㉿kali)-[~]
└─$ alias c2-win64-https='sudo msfconsole -q -x "use exploit/multi/handler; set PAYLOAD windows/x64/meterpreter/reverse_https; set HandlerSSLCert ./gem-private_key.pem; set SSLVERSION TLS1.2; set LHOST 127.0.0.1; set LPORT 443; set EXITFUNC thread; exploit"'

┌──(kali㉿kali)-[~]
└─$ c2-win64-https 
[*] Using configured payload generic/shell_reverse_tcp
PAYLOAD => windows/x64/meterpreter/reverse_https
HandlerSSLCert => ./gem-private_key.pem
SSLVERSION => TLS1.2
LHOST => 127.0.0.1
LPORT => 443
EXITFUNC => thread
[!] You are binding to a loopback address by setting LHOST to 127.0.0.1. Did you want ReverseListenerBindAddress?
[*] Started HTTPS reverse handler on https://127.0.0.1:443

I think @smcintyre-r7 has run into this before, will sync up and see if we can replicate on his environment 👍

Thank you! It's definitely an odd issue.

stavoxnetworks commented 1 year ago

For sure. I will try passing args later this evening.

On Thu, Oct 26, 2023, 12:08 PM Tristram @.***> wrote:

Thanks for the extra replication steps; Unfortunately it still works for me everytime:

┌──(kali㉿kali)-[~] └─$ alias c2-win64-https='sudo msfconsole -q -x "use exploit/multi/handler; set PAYLOAD windows/x64/meterpreter/reverse_https; set HandlerSSLCert ./gem-private_key.pem; set SSLVERSION TLS1.2; set LHOST 127.0.0.1; set LPORT 443; set EXITFUNC thread; exploit"'

┌──(kali㉿kali)-[~] └─$ c2-win64-https [] Using configured payload generic/shell_reverse_tcp PAYLOAD => windows/x64/meterpreter/reverse_https HandlerSSLCert => ./gem-private_key.pem SSLVERSION => TLS1.2 LHOST => 127.0.0.1 LPORT => 443 EXITFUNC => thread [!] You are binding to a loopback address by setting LHOST to 127.0.0.1. Did you want ReverseListenerBindAddress? [] Started HTTPS reverse handler on https://127.0.0.1:443

I think @smcintyre-r7 https://github.com/smcintyre-r7 has run into this before, will sync up and see if we can replicate on his environment 👍

Thank you! It's definitely an odd issue.

— Reply to this email directly, view it on GitHub https://github.com/rapid7/metasploit-framework/issues/18462#issuecomment-1781423628, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGSCDXJDJOVNEMO6RMWNNLTYBKDIJAVCNFSM6AAAAAA6EFHDZKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOBRGQZDGNRSHA . You are receiving this because you were mentioned.Message ID: @.***>

RobertoPatino1 commented 1 year ago

In my case the error was due to some dependencies being missing, I was able to fix it by running the following commands: sudo apt update sudo apt-get upgrade --fix-missing

jsherwood0 commented 12 months ago

FYI, this seems to happen more often when the system is under load. When I have several .rc scripts (4+) running different modules at the same time (large host lists keep them running concurrently), frequently the next one I start will error out with this problem.

adfoster-r7 commented 12 months ago

@jsherwood0 That's an interesting datapoint 👀

Is the issue resolved if you update your dependencies like @RobertoPatino1 performed?

jsherwood0 commented 12 months ago

@jsherwood0 That's an interesting datapoint 👀

Is the issue resolved if you update your dependencies like @RobertoPatino1 performed?

I did a full apt dist-upgrade this morning and haven't run into it yet after that. Will update here if I do see it again.

gh0x0st commented 12 months ago

@jsherwood0 That's an interesting datapoint 👀

Is the issue resolved if you update your dependencies like @RobertoPatino1 performed?

I'm trying this now and will report back how it goes over the next few days.

s3cur3c1ph3r commented 12 months ago

fixed with sudo apt dist-upgrade hope this fixes for you .

NodeRaven commented 12 months ago

I am also having this error. Everything is up to date, in fact the issue started after updates.

exil-security commented 11 months ago

I'm still having the same issue after update. My current version 6.3.40-dev.

Jorge2Rubio commented 11 months ago

Just use msfdb init and it will run.

wdahlenburg commented 11 months ago

Per the above comment from @Jorge2Rubio, resource scripts seem to work more reliably if a database is running. If postgres is disabled the bug seems to trigger pretty frequently.

adfoster-r7 commented 11 months ago

Does this patch solve your local issues? https://github.com/rapid7/metasploit-framework/pull/18538/files

wdahlenburg commented 11 months ago

Does this patch solve your local issues? https://github.com/rapid7/metasploit-framework/pull/18538/files

I'm not getting any errors with the patch

stavoxnetworks commented 11 months ago

Nor am I. I haven't had one since the last update 3 days ago. You guys are awesome.

On Tue, Nov 14, 2023, 4:38 PM Wyatt Dahlenburg @.***> wrote:

Does this patch solve your local issues? https://github.com/rapid7/metasploit-framework/pull/18538/files

I'm not getting any errors with the patch

— Reply to this email directly, view it on GitHub https://github.com/rapid7/metasploit-framework/issues/18462#issuecomment-1811364948, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGSCDXJNSX7VIGWQDV6PT4DYEPQFXAVCNFSM6AAAAAA6EFHDZKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMJRGM3DIOJUHA . You are receiving this because you were mentioned.Message ID: @.***>

syntaxerrortion commented 11 months ago

try > sudo service postgresql start

github-actions[bot] commented 10 months ago

Hi!

This issue has been left open with no activity for a while now.

We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 30 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request.

github-actions[bot] commented 9 months ago

Hi again!

It’s been 60 days since anything happened on this issue, so we are going to close it. Please keep in mind that I’m only a robot, so if I’ve closed this issue in error please feel free to reopen this issue or create a new one if you need anything else.

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request.

adfoster-r7 commented 9 months ago

This was fixed by https://github.com/rapid7/metasploit-framework/pull/18538