예제 #1
0
    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))
예제 #2
0
 def __set__(self, instance, value):
     try:
         self.display_value = str(value)
         self.value = int(value)
     except ValueError:
         raise OptionValidationError(
             "Invalid option. Cannot cast '{}' to integer.".format(value))
예제 #3
0
    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))

        return content
예제 #4
0
 def __set__(self, instance, value):
     if not value or is_ipv4(value) or is_ipv6(value):
         self.value = self.display_value = value
     else:
         raise OptionValidationError(
             "Invalid address. Provided address is not valid IPv4 or IPv6 address."
         )
예제 #5
0
    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
예제 #6
0
 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))
예제 #7
0
    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
예제 #8
0
 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.")
예제 #9
0
    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`."
            )
예제 #10
0
 def __init__(self):
     if self.handler not in PayloadHandlers:
         raise OptionValidationError(
             "Please use one of valid payload handlers: {}".format(
                 PayloadHandlers._fields))