1

I'm trying to build a module that will allow me to run a .sh script on an android device through meterpreter. I can run this manually by typing shell in the meterpreter session the problem is I can't automate this with an .rc file because it stops when it opens the shell, however I was thinking I could make a module that could execute the code on the target device that I could run through an .rc file.

I have copied my ruby file into /metasploit-framework/modules/post/android/manage/ and ran updatedb from msf but when I attempt to call the module it says:

[-] No results from search
[-] Failed to load module: post/android/manage/postscript

I think the problem may be in the code, I'm still quite new to programming especially ruby so apologies if the problem is obvious.

Here's the code:

##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Post
  include Msf::Post::Common

  def initialize(info={})
    super( update_info( info, {
        'Name'          => "Script Executer",
        'Description'   => %q{
            This module runs any .sh script on android shell through meterpreter.
        },
        'License'       => MSF_LICENSE,
        'Author'        => [ 'asta' ],
        'SessionTypes'  => [ 'meterpreter' ],
        'Platform'      => 'android',
      }
    ))
  end

  def run
    print_status("Running persistence script")
    cmd_exec("sh /sdcard/boot.sh")
  end

  print_status("You now have a persistence backdoor")
  end
end

Any help or suggestions would be greatly appreciated.

Asta_187
  • 11
  • 2
  • I have no experience with Metasploit but according to the [Official Docs](https://github.com/rapid7/metasploit-framework/wiki/Running-Private-Modules#mirror-the-real-metasploit-module-paths) it seems you are putting the file in the wrong location. Additionally `print_status` appears to be out of scope and you have an extra `end` on the following line, this makes the ruby invalid and may impact loading this file as well. – engineersmnky May 09 '22 at 17:53
  • 1
    @engineermnky - I got it working and detected by metasploit using the link you sent me, the only problem now is its not quite doing what I wanted it to do but I'll figure out in time. Thanks for your help. – Asta_187 May 09 '22 at 20:02

0 Answers0