def __set__(self, instance, value): try: value = int(value) if 0 < value <= 65535: # max port number is 65535 self.display_value = str(value) self.value = value else: raise OptionValidationError("Invalid option. Port value should be between 0 and 65536.") except ValueError: raise OptionValidationError("Invalid option. Cannot cast '{}' to integer.".format(value))
def _apply_widget(self, value): try: value = int(value) if 0 < value <= 65535: # max port number is 65535 return value else: raise OptionValidationError( "Invalid option. Port value should be between 0 and 65536." ) except ValueError: raise OptionValidationError( "Invalid option. Cannot cast '{}' to integer.".format(value))
def _apply_widget(self, value): if is_ipv4(value) or is_ipv6(value): return value else: raise OptionValidationError( "Invalid address. Provided address is not valid IPv4 or IPv6 address." )
def run(self): print_status("Generating payload") try: data = self.generate() except OptionValidationError as e: print_error(e) return if self.output == "elf": with open(self.filepath, 'wb+') as f: print_status("Building ELF payload") content = self.generate_elf(data) print_success("Saving file {}".format(self.filepath)) f.write(content) elif self.output == "c": print_success("Bulding payload for C") content = self.generate_c(data) print_info(content) elif self.output == "python": print_success("Building payload for python") content = self.generate_python(data) print_info(content) else: raise OptionValidationError( "No such option as {}".format(self.output) )
def __set__(self, instance, value): try: self.display_value = str(value) self.value = float(value) except ValueError: raise OptionValidationError( "Invalid option. Cannot cast '{}' to float.".format(value))
def __init__(self): if self.handler not in PayloadHandlers: raise OptionValidationError( "Please use one of valid payload handlers: {}".format( PayloadHandlers._fields ) )
def __set__(self, instance, value): if not value or is_ipv4(value) or is_ipv6(value) or value == "localip": self.value = self.display_value = value else: raise OptionValidationError( "Invalid address. Provided address is not valid IPv4 or IPv6 address." )
def __set__(self, instance, value): if value.startswith("file://"): path = value.replace("file://", "") if not os.path.exists(path): raise OptionValidationError("File '{}' does not exist.".format(path)) self.value = self.display_value = value
def __set__(self, instance, value): regexp = r"^[a-f\d]{1,2}:[a-f\d]{1,2}:[a-f\d]{1,2}:[a-f\d]{1,2}:[a-f\d]{1,2}:[a-f\d]{1,2}$" if re.match(regexp, value.lower()): self.value = self.display_value = value else: raise OptionValidationError( "Invalid option. '{}' is not a valid MAC address".format( value))
def __set__(self, instance, value): encoder = instance.get_encoder(value) if encoder: self.value = encoder self.display_value = value else: raise OptionValidationError("Encoder not available. Check available encoders with `show encoders`.")
def _apply_widget(self, value): regexp = r"^[a-f\d]{1,2}:[a-f\d]{1,2}:[a-f\d]{1,2}:[a-f\d]{1,2}:[a-f\d]{1,2}:[a-f\d]{1,2}$" if re.match(regexp, value.lower()): return value else: raise OptionValidationError( "Invalid option. '{}' is not a valid MAC address".format( value))
def __init__(self): super(ArchitectureSpecificPayload, self).__init__() if self.architecture not in Architectures: raise OptionValidationError( "Please use one of valid payload architectures: {}".format( Architectures._fields)) self.header = ARCH_ELF_HEADERS[self.architecture] self.bigendian = True if self.architecture.endswith("be") else False
def __set__(self, instance, value): if value == "true": self.value = True self.display_value = value elif value == "false": self.value = False self.display_value = value else: raise OptionValidationError("Invalid value. It should be true or false.")
def _apply_widget(self, value): if value.startswith("file://"): path = value.replace("file://", "") if not os.path.exists(path): raise OptionValidationError( "File '{}' does not exist.".format(path)) return value return value
def __set__(self, instance, value): if not value: self.value = self.display_value = '' return name, _, _ = value.strip().partition(':') engine = get_engine_module(name) if engine.parse_protocal(value): self.value = self.display_value = value else: raise OptionValidationError("Invalid engine.")
def __init__(self, default, description="", advanced=False): self.description = description if default: self.display_value = "true" else: self.display_value = "false" self.value = default try: self.advanced = bool(advanced) except ValueError: raise OptionValidationError("Invalid value. Cannot cast '{}' to boolean.".format(advanced))
def __init__(self, default, description="", advanced=False): self.label = None self.description = description try: self.advanced = bool(advanced) except ValueError: raise OptionValidationError("Invalid value. Cannot cast '{}' to boolean.".format(advanced)) if default or default == 0: self.__set__("", default) else: self.display_value = "" self.value = ""
def _apply_widget(self, value): try: return float(value) except ValueError: raise OptionValidationError( "Invalid option. Cannot cast '{}' to float.".format(value))
def _apply_widget(self, value): if value in ["true", "false"]: return value else: raise OptionValidationError( "Invalid value. It should be true or false.")