简体   繁体   中英

How to execute command in a sub/Child process using bash/shell scripting or python-shell scripting

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 ######
from os import *

system ( 'msfconsole -r /root/ms17-010.rc' )
system("shell")
system("getsystem")
## 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")

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM