Monday, April 6, 2015

Running System Commands Against Multiple SSH Servers With Metasploit

To run a command against multiple SSH servers and you want to use metasploit to do it

There doesn't exist a multi_ssh_exec type aux module to run commands. Luckily ? the ssh_login module creates a command shell session for you, on successful logins. You can use the builtin sessions functionality to run a command against all your (SSH) sessions.

msf auxiliary(ssh_login) > sessions -h
Usage: sessions [options]

Active session manipulation and interaction.


    -K        Terminate all sessions
    -c  Run a command on the session given with -i, or all
    -d  Detach an interactive session
    -h        Help banner
    -i  Interact with the supplied session ID
    -k  Terminate sessions by session ID and/or range
    -l        List all active sessions
    -q        Quiet mode
    -r        Reset the ring buffer for the session given with -i, or all
    -s  Run a script on the session given with -i, or all
    -t  Set a response timeout (default: 15)
    -u  Upgrade a shell to a meterpreter session on many platforms
    -v        List verbose fields

Many options allow specifying session ranges using commas and dashes.
For example:  sessions -s checkvm -i 1,3-5  or  sessions -k 1-2,5,6

So given some sessions, you can pass a

sessions -c 'command' all 

against all the sessions or a

sessions -c 'command' -i 2,4,5 

against specified sessions.



No comments: