I was able to start a session using metasploit framework (msf6) with an android but after a while being in the session, the meterpreter session closes. Luckily however after a few seconds, another stage payload gets sent out, giving me access to another meterpreter session. I could login AGAIN using sessions <id>

I'm trying to run a session script using the run command and I want to catch this error:

[-] Error running command print_status: Rex::TimeoutError Operation timed out.

when my meterpreter sessions get closed to automatically open a new session again using sessions <id>.

For example, I am running this ruby script in the session, but general Ruby syntax error catching doesn't work.

  while true
    print_status("Hello world")
rescue => e
  print_status("This is where I want to catch when my session gets closed")
  print_status("The print_status doesn't work once meterpreter prompt closes")

Is it normal for meterpreter sessions to timeout after a while? Because I've learned to live with it, but it would be nice if I don't have to keep typing in sessions <new id> to get a new session after every session use.

  • This is mostly looking like a Ruby programming question, not a security question. I would clean up the tangential comments, add in what you've tried and what the results were and move this to StackOverflow.
    – schroeder
    Mar 12, 2022 at 0:47
  • @schroeder thats what i thought at first but it cant be pertinent to just ruby itself but some code in the metasploit framework itself. Mar 12, 2022 at 0:51
  • Also there is nothing else i can think of trying as i have documented in my question a code sample i used to catch the error if the meterpreter session closes. I dont know but can I also post this to regular StackOverflow incase no one here knows what to do? Mar 12, 2022 at 0:54


You must log in to answer this question.

Browse other questions tagged .