@@ -356,7 +356,7 @@ def hash_login(self, domain, username, ntlm_hash):
356356 color = ("magenta" if ((reason or "CredSSP" in str (e )) and reason != "STATUS_LOGON_FAILURE" ) else "red" ),
357357 )
358358 return False
359-
359+
360360 async def _send_keystrokes (self , text , delay = 0.02 ):
361361 """Helper method to send keystrokes to the RDP session"""
362362 for char in text :
@@ -365,35 +365,35 @@ async def _send_keystrokes(self, text, delay=0.02):
365365 key_event .is_pressed = True
366366 await self .conn .ext_in_queue .put (key_event )
367367 await asyncio .sleep (delay )
368-
368+
369369 async def _send_enter (self ):
370370 """Helper method to send Enter key to the RDP session"""
371371 await self .conn .send_key_virtualkey ("VK_RETURN" , True , False )
372372 await asyncio .sleep (0.05 )
373373 await self .conn .send_key_virtualkey ("VK_RETURN" , False , False )
374-
374+
375375 async def _send_win_r (self ):
376376 """Helper method to send Windows+R key combination to open Run dialog"""
377377 try :
378378 self .logger .debug ("Sending Win+R using scancode method" )
379-
379+
380380 layout = KeyboardLayoutManager ().get_layout_by_shortname ("enus" )
381-
381+
382382 win_scancode = layout .vk_to_scancode ("VK_LWIN" )
383383 await self .conn .send_key_scancode (win_scancode , True , False )
384384 await asyncio .sleep (0.1 )
385-
385+
386386 r_scancode = layout .char_to_scancode ("r" )[0 ]
387387 await self .conn .send_key_scancode (r_scancode , True , False )
388388 await asyncio .sleep (0.1 )
389-
389+
390390 await self .conn .send_key_scancode (r_scancode , False , False )
391391 await asyncio .sleep (0.1 )
392-
392+
393393 await self .conn .send_key_scancode (win_scancode , False , False )
394-
394+
395395 await asyncio .sleep (0.5 )
396-
396+
397397 self .logger .debug ("Win+R sent successfully" )
398398 return True
399399 except (ConnectionResetError , ConnectionError , OSError ) as e :
@@ -404,12 +404,12 @@ async def _send_win_r(self):
404404 self .logger .debug (f"Error sending Win+R: { e !s} " )
405405 self .logger .debug ("Using fallback approach for opening command prompt" )
406406 return False
407-
407+
408408 async def execute_shell (self , payload , get_output , shell_type ):
409409 # Append | clip to send output to clipboard
410410 payload_with_clip = f"{ payload } | clip & exit" if shell_type == "cmd" else f"{ payload } | clip; exit"
411411 self .logger .debug (f"Executing command: { payload_with_clip } " )
412-
412+
413413 # Create a connection
414414 try :
415415 self .conn = RDPConnection (iosettings = self .iosettings , target = self .target , credentials = self .auth )
@@ -452,12 +452,12 @@ async def execute_shell(self, payload, get_output, shell_type):
452452
453453 # Wait for desktop to be available
454454 await asyncio .sleep (self .args .cmd_delay )
455-
455+
456456 try :
457457 # Try to open Run dialog using Windows+R
458458 self .logger .debug ("Attempting to open Run dialog" )
459459 win_r_success = await self ._send_win_r ()
460-
460+
461461 if win_r_success :
462462 self .logger .debug (f"Launching { shell_type } via Run dialog" )
463463 await self ._send_keystrokes (f"{ shell_type } .exe" )
@@ -469,20 +469,20 @@ async def execute_shell(self, payload, get_output, shell_type):
469469 await self ._send_keystrokes (f"{ shell_type } .exe" )
470470 await self ._send_enter ()
471471 await asyncio .sleep (self .args .cmd_delay )
472-
472+
473473 # Type the command with | clip
474474 self .logger .debug (f"Typing command: { payload_with_clip } " )
475475 await self ._send_keystrokes (payload_with_clip )
476476 await self ._send_enter ()
477-
477+
478478 # Wait for command to execute
479479 await asyncio .sleep (self .args .cmd_delay )
480480
481481 if get_output :
482482 # Get the current clipboard text
483483 self .logger .debug ("Getting clipboard content..." )
484484 clipboard_text = await self .conn .get_current_clipboard_text ()
485-
485+
486486 if clipboard_text :
487487 self .logger .debug ("Command output retrieved from clipboard:" )
488488 for line in clipboard_text .lstrip ().strip ("\n " ).splitlines ():
@@ -493,7 +493,7 @@ async def execute_shell(self, payload, get_output, shell_type):
493493
494494 self .logger .debug ("Command execution completed" )
495495 return None
496-
496+
497497 except (ConnectionResetError , ConnectionError , OSError ) as e :
498498 self .logger .debug (f"Connection error during command execution: { e !s} " )
499499 self .logger .fail ("Connection was reset by the remote host during command execution" )
@@ -505,7 +505,7 @@ async def execute_shell(self, payload, get_output, shell_type):
505505 else :
506506 self .logger .fail (f"Command execution failed: { e !s} " )
507507 return None
508-
508+
509509 except (ConnectionResetError , ConnectionError , OSError ) as e :
510510 self .logger .debug (f"Connection error: { e !s} " )
511511 self .logger .fail ("Connection was reset by the remote host" )
@@ -522,19 +522,19 @@ async def execute_shell(self, payload, get_output, shell_type):
522522 await self .conn .terminate ()
523523 except Exception as e :
524524 self .logger .debug (f"Error terminating connection: { e !s} " )
525-
525+
526526 def execute (self , payload = None , shell_type = "cmd" ):
527527 """Execute a command via RDP"""
528528 if not payload :
529529 payload = self .args .execute
530-
530+
531531 get_output = bool (not self .args .no_output )
532532
533533 self .logger .success (f"Executing command: { payload } with delay { self .args .cmd_delay } seconds" )
534-
534+
535535 try :
536536 result = asyncio .run (self .execute_shell (payload , get_output , shell_type ))
537-
537+
538538 if result :
539539 self .logger .debug ("Command execution completed" )
540540 return result
@@ -566,7 +566,7 @@ async def screen(self):
566566 buffer .save (filename , "png" )
567567 self .logger .highlight (f"Screenshot saved { filename } " )
568568
569- def screenshot (self ):
569+ def screenshot (self ):
570570 asyncio .run (self .screen ())
571571
572572 async def nla_screen (self ):
0 commit comments