@@ -486,24 +486,38 @@ def __build_windows_cmdline(self):
486
486
487
487
@staticmethod
488
488
def __validate_target (target ):
489
- # See https://nmap.org/book/man-target-specification.html for all the
490
- # ways targets can be specified
489
+ """
490
+ Check if a provided target is valid. This function was created
491
+ in order to address CVE-2022-30284
492
+
493
+ See https://nmap.org/book/man-target-specification.html for all the
494
+ ways targets can be specified
495
+
496
+ This function verifies the following:
497
+
498
+ - matches the user specified target against a list of allowed chars
499
+ - check if dashes are used at the start or at the end of target
500
+
501
+ FQDN can contain dashes anywhere except at the beginning or end
502
+ This check also fixes/prevents CVE-2022-30284, which depends on being
503
+ able to pass options such as --script as a target
504
+
505
+ :return: False if target contains forbidden characters
506
+ """
491
507
allowed_characters = frozenset (
492
508
string .ascii_letters + string .digits + "-.:/% "
493
509
)
494
510
if not set (target ).issubset (allowed_characters ):
495
511
raise Exception (
496
512
"Target '{}' contains invalid characters" .format (target )
497
513
)
498
- # FQDN can contain dashes anywhere except at the beginning or end
499
- # This check also fixes/prevents CVE-2022-30284, which depends on being
500
- # able to pass options such as --script as a target
501
514
elif target .startswith ("-" ) or target .endswith ("-" ):
502
515
raise Exception (
503
516
"Target '{}' cannot begin or end with a dash ('-')" .format (
504
517
target
505
518
)
506
519
)
520
+ return True
507
521
508
522
@property
509
523
def command (self ):
0 commit comments