Esempio n. 1
0
 def __init__(self, the_type, fuzz_delims=True, fuzzable=True, name=None):
     '''
     :type the_type: str
     :param the_type: the FTP type
     :param fuzz_delims: should fuzz delimiters (default: True)
     :param fuzzable: is the container fuzzable (default: True)
     :param name: name of the container (default: None)
     '''
     super(FType, self).__init__(
         name=name,
         fuzzable=fuzzable,
         fields=[
             Delimiter(name='delim from path',
                       value=';',
                       fuzzable=fuzz_delims),
             String(name='key', value='ftype'),
             Delimiter(name='delim from value',
                       value='=',
                       fuzzable=fuzz_delims),
             OneOf(name='file type',
                   fields=[
                       Group(name='possible valid values',
                             values=['A', 'I', 'D', 'a', 'i', 'd']),
                       String(name='mutations', value=the_type),
                   ])
         ])
Esempio n. 2
0
 def __init__(self,
              search='',
              fuzz_delims=False,
              fuzz_param=False,
              fuzz_value=True,
              fuzzable=True,
              name=None):
     '''
     :param search: search string (default: '')
     :param fuzz_delims: should fuzz the delimiters (default: False)
     :param name: name of container (default: None)
     :param fuzzable: should fuzz the container (default: True)
     '''
     fields = [
         Delimiter(name='search main delim',
                   value='?',
                   fuzzable=fuzz_delims),
     ]
     for i, part in enumerate(search.split('&')):
         part = part.split('=')
         fields.append(
             Container(name='param_%s' % part[0],
                       fields=[
                           String(name='search_%d_key' % i,
                                  value=part[0],
                                  fuzzable=fuzz_param),
                           Delimiter(value='=', fuzzable=fuzz_delims),
                           String(name='search_%d_value' % i,
                                  value=part[1],
                                  fuzzable=fuzz_value)
                       ]))
     super(Search, self).__init__(name=name,
                                  fields=fields,
                                  fuzzable=fuzzable)
Esempio n. 3
0
 def __init__(self,
              data='',
              fuzz_delims=False,
              fuzz_param=False,
              fuzz_value=True,
              fuzzable=True,
              name=None):
     '''
     :param data: data string (default: '')
     :param fuzz_delims: should fuzz the delimiters (default: False)
     :param name: name of container (default: None)
     :param fuzzable: should fuzz the container (default: True)
     '''
     fields = []
     for i, part in enumerate(data.split('&')):
         part = part.split('=')
         if len(fields) >= 1:
             fields.append(
                 Delimiter(name='search_delim_%d' % i,
                           value='&',
                           fuzzable=fuzz_delims))
         fields.append(
             Container(name='param_%s' % part[0],
                       fields=[
                           String(name='search_%d_key' % i,
                                  value=part[0],
                                  fuzzable=fuzz_param),
                           Delimiter(value='=', fuzzable=fuzz_delims),
                           String(name='search_%d_value' % i,
                                  value=part[1],
                                  fuzzable=fuzz_value)
                       ]))
     super(PostFormUrlencoded, self).__init__(name=name,
                                              fields=fields,
                                              fuzzable=fuzzable)
Esempio n. 4
0
 def __init__(self,
              path=None,
              path_delim='/',
              fuzz_delims=True,
              fuzzable=True,
              name=None):
     '''
     :type path: str
     :param path: path string
     :param path_delim: delimiter in the path str
     :param fuzz_delims: should fuzz the delimiters (default: False)
     :param name: name of container (default: None)
     :param fuzzable: should fuzz the container (default: True)
     '''
     fields = []
     if path is not None:
         fields.append(
             Delimiter(name='main delim', value='/', fuzzable=fuzz_delims))
         path_parts = path.split(path_delim)
         if not path_parts[0]:
             path_parts = path_parts[1:]
         for i in range(len(path_parts) - 1):
             fields.append(
                 String(name='path part %d' % i, value=path_parts[i]))
             fields.append(
                 Delimiter(name='path delim %d' % i,
                           value=path_delim,
                           fuzzable=fuzz_delims))
         fields.append(String(name='path last part', value=path_parts[-1]))
     super(Path, self).__init__(name=name, fields=fields, fuzzable=fuzzable)
Esempio n. 5
0
 def __init__(self,
              data=b'',
              boundary=b'',
              fuzz_delims=False,
              fuzz_param=False,
              fuzz_value=True,
              name=None):
     self.separator = b'--%s' % boundary
     self.terminator = b'--%s--' % boundary
     multipart = self.multipart2json_parse(data)
     fields = []
     for item in multipart:
         fields += [
             Delimiter(self.separator, fuzzable=fuzz_delims),
             Static(b'\r\n')
         ]
         inner_container_header = []
         ContentDisposition = item.get(b'header').get(
             b'Content-Disposition').get(b'params')
         var_name = ContentDisposition.get(b'name')
         var_value = item.get(b'value')
         for header_field in item.get(b'header'):
             header_value = item.get(b'header')[header_field].get(b'value')
             header_params = item.get(b'header')[header_field].get(
                 b'params')
             multipart_header_name = '%s_%s' % (header_field.decode(),
                                                var_name.decode())
             inner_container_header.append(
                 TextField(key=header_field,
                           value=header_value,
                           params=header_params,
                           name=multipart_header_name,
                           fuzzable_key=fuzz_param,
                           fuzzable_value=fuzz_value))
         inner_container_header.append(Static(b'\r\n'))
         fields.append(
             Container(fields=inner_container_header,
                       name='%s_header' % var_name))
         # Append multipart param value
         if var_value.isdigit():
             fields.append(
                 DecimalNumber(name="multipart_value_%s" %
                               var_name.decode(),
                               num_bits=bit_length(int(var_value)),
                               value=int(var_value),
                               signed=True))
         else:
             fields.append(String(var_value))
         fields.append(Static(b'\r\n'))
     # Append terminator boundary
     fields += [
         Delimiter(self.terminator, fuzzable=fuzz_delims),
         Static(b'\r\n')
     ]
     super(PostMultipartFormData, self).__init__(name=name,
                                                 fields=fields,
                                                 fuzzable=fuzz_value)
Esempio n. 6
0
    def __init__(self,
                 scheme,
                 login,
                 url_path=None,
                 fuzz_scheme=True,
                 fuzz_login=True,
                 fuzz_delims=True,
                 fuzzable=True,
                 name=None):
        '''
        :type scheme: str or instance of :class:`~kitty.model.low_level.field.BaseField`
        :param scheme: url scheme
        :type login:

            str or instance of :class:`~kitty.model.low_level.field.BaseField`
            recommend using :class:`~katnip.legos.url.Login`

        :param login: the login information
        :type path:

            instance of :class:`~kitty.model.low_level.field.BaseField`
            recommend using :class:`~katnip.legos.url.Path`

        :param url_path: the url path (default: None)
        :param fuzz_scheme: should fuzz scheme (default: True)
        :param fuzz_login: should fuzz login (default: True)
        :param fuzz_delims: should fuzz delimiters (default: True)
        :param fuzzable: should fuzz the container (default: True)
        :param name: name of container (default: None)
        '''
        parts_fields = [
            Delimiter(name=_merge(name, 'forward slashs'),
                      value='//',
                      fuzzable=fuzz_delims),
            _to_string_field(_merge(name, 'login'), login, fuzzable=fuzz_login)
        ]
        if url_path is not None:
            parts_fields.append(
                Delimiter(name=_merge(name, 'url path delim'),
                          value='/',
                          fuzzable=fuzz_delims))
            parts_fields.append(url_path)
        parts = Container(name=_merge(name, 'parts'), fields=parts_fields)
        super(IpUrl, self).__init__(name=name,
                                    scheme=scheme,
                                    parts=parts,
                                    fuzz_scheme=fuzz_scheme,
                                    fuzz_delim=fuzz_delims,
                                    fuzzable=fuzzable)
Esempio n. 7
0
 def __init__(self,
              scheme,
              parts,
              fuzz_scheme=True,
              fuzz_parts=True,
              fuzz_delim=True,
              fuzzable=True,
              name=None):
     '''
     :type scheme: str or instance of :class:`~kitty.model.low_level.field.BaseField`
     :param scheme: url scheme
     :type parts: str or instance of :class:`~kitty.model.low_level.field.BaseField`
     :param parts: url parts (i.e. content)
     :param fuzz_scheme: should fuzz scheme (default: True)
     :param fuzz_parts: should fuzz parts (default: True)
     :param fuzz_delim: should fuzz delimiters (default: True)
     :param fuzzable: should fuzz the container (default: True)
     :param name: name of container (default: None)
     '''
     scheme = _to_string_field(_merge(name, 'scheme'),
                               scheme,
                               fuzzable=fuzz_scheme)
     delim = Delimiter(name=_merge(name, 'delimiter'),
                       value=':',
                       fuzzable=fuzz_delim)
     parts = _to_string_field(_merge(name, 'scheme parts'),
                              parts,
                              fuzzable=fuzz_parts)
     super(Url, self).__init__(name=name,
                               fields=[scheme, delim, parts],
                               fuzzable=fuzzable)
Esempio n. 8
0
 def __init__(self,
              key,
              username,
              password,
              end=False,
              delim=':',
              fuzz_username=True,
              fuzz_password=True,
              fuzzable_key=False,
              fuzzable=True):
     value_field = [
         Static('Basic '),
         Container(name='base64_auth',
                   fields=[
                       String(name='username',
                              value=username,
                              fuzzable=fuzz_username),
                       Delimiter(delim, fuzzable=False),
                       String(name='password',
                              value=password,
                              fuzzable=fuzz_password),
                   ],
                   encoder=ENC_BITS_BASE64)
     ]
     super(AuthorizationField, self).__init__(key, value_field, end,
                                              fuzzable_key, fuzzable)
Esempio n. 9
0
 def __init__(self,
              value,
              fuzz_value=True,
              fuzz_length=True,
              fuzz_delim=True,
              name=None):
     '''
     :param value: str, will be enclosed in String
     :param fuzz_value: bool (default: True)
     :param fuzz_length: bool (default: True)
     :param fuzz_delim: bool (default: True)
     :param name: name of container (default: None)
     '''
     name = name if name is not None else _unique_name(type(self).__name__)
     if isinstance(value, str):
         fvalue = String(value=value,
                         fuzzable=fuzz_value,
                         name=_merge(name, 'value'))
     else:
         fvalue = value
     fvalue_name = fvalue.get_name()
     super(TString,
           self).__init__(name=name,
                          fields=[
                              SizeInBytes(sized_field=fvalue_name,
                                          length=32,
                                          encoder=ENC_INT_DEC,
                                          fuzzable=fuzz_length,
                                          name=_merge(name, 'length')),
                              Delimiter(value=':',
                                        fuzzable=fuzz_delim,
                                        name=_merge(name, 'delim')), fvalue
                          ])
Esempio n. 10
0
    def __init__(self,
                 username=None,
                 password=None,
                 fuzz_username=True,
                 fuzz_password=True,
                 fuzz_delims=True,
                 fuzzable=True,
                 name=None):
        '''
        :param username: user name (default: None)
        :param password: password (default: None)
        :param fuzz_username: should fuzz username (default: True)
        :param fuzz_password: should fuzz password (default: True)
        :param fuzz_delims: should fuzz delimiters (default: True)
        :param fuzzable: should fuzz the container (default: True)
        :param name: name of container (default: None)
        '''
        fields = []
        if username is not None:
            fields.append(
                _to_string_field(_merge('name', 'username'),
                                 username,
                                 fuzzable=fuzz_username))
            if password is not None:
                fields.append(
                    Delimiter(name=_merge(name, 'username password delim'),
                              value=':',
                              fuzzable=fuzz_delims))
                fields.append(
                    _to_string_field(_merge('name', 'password'),
                                     password,
                                     fuzzable=fuzz_password))
            fields.append(
                Delimiter(name=_merge(name, 'username hostport delim'),
                          value='@',
                          fuzzable=fuzz_delims))
        elif password is not None:
            raise KittyException('Login cannot have password without username')

        super(Login, self).__init__(name=name,
                                    fields=fields,
                                    fuzzable=fuzzable)
Esempio n. 11
0
    def __init__(self,
                 scheme='ftp',
                 login=None,
                 hostport=None,
                 path=None,
                 ftype=None,
                 fuzz_scheme=True,
                 fuzz_delims=True,
                 fuzzable=True,
                 name=None):
        '''
        :param scheme: URL scheme name (default: 'ftp')
        :type login:

            instance of :class:`~kitty.model.low_level.field.BaseField`
            recommend using :class:`~katnip.legos.url.Login`

        :param login: the login information (default: None)
        :type hostport: :class:`katnip.legos.url.HostPort` object (default: None)
        :param hostport: FTP host and port
        :type path: :class:`katnip.legos.url.Path` object (default: None)
        :param path: file path
        :type ftype: :class:`katnip.legos.url.FType` object (default: None)
        :param ftype: FTP type
        :param fuzz_scheme: should fuzz the URL scheme (default: True)
        :param fuzz_delims: should fuzz the delimiters (default: True)
        :param fuzzable: is the container fuzzable (default: True)
        :param name: name of the container (default: None)
        '''
        fields = []
        fields.append(
            Delimiter(name=_merge(name, 'forward slashs'),
                      value='//',
                      fuzzable=fuzz_delims))
        if login is not None:
            fields.append(login)
        fields.append(hostport)
        if path:
            fields.append(path)
            if ftype is not None:
                fields.append(ftype)
        parts = Container(name='parts', fields=fields, fuzzable=fuzzable)
        super(FtpUrl, self).__init__(name=name,
                                     scheme=scheme,
                                     parts=parts,
                                     fuzz_scheme=fuzz_scheme,
                                     fuzz_delim=fuzz_delims,
                                     fuzzable=fuzzable)
Esempio n. 12
0
 def __init__(self, search='', fuzz_delims=False, fuzzable=True, name=None):
     '''
     :param search: search string (default: '')
     :param fuzz_delims: should fuzz the delimiters (default: False)
     :param name: name of container (default: None)
     :param fuzzable: should fuzz the container (default: True)
     '''
     fields = [
         Delimiter(name='search main delim',
                   value='?',
                   fuzzable=fuzz_delims),
         String(name='search data', value=search),
     ]
     super(Search, self).__init__(name=name,
                                  fields=fields,
                                  fuzzable=fuzzable)
Esempio n. 13
0
    def __init__(self,
                 scheme='http',
                 login=None,
                 hostport=None,
                 path=None,
                 search=None,
                 fuzz_scheme=True,
                 fuzz_delims=True,
                 fuzzable=True,
                 name=None):
        '''
        :param scheme: URL scheme name (default: 'http')
        :type login:

            instance of :class:`~kitty.model.low_level.field.BaseField`
            recommend using :class:`~katnip.legos.url.Login`

        :param login: the login information (default: None)
        :param hostport: :class:`katnip.legos.url.HostPort` object, must be set (default: None)
        :param path: Path object (default: None)
        :param search: Search object (default: None)
        :param fuzz_scheme: should fuzz the URL scheme (default: True)
        :param fuzz_delims: should fuzz the delimiters (default: True)
        :param fuzzable: is the container fuzzable (default: True)
        :param name: name of the container (default: None)
        '''
        if hostport is None:
            raise KittyException('hostport is mandatory in HttpUrl')
        parts_fields = []
        parts_fields.append(
            Delimiter(name=_merge(name, 'forward slashs'),
                      value='//',
                      fuzzable=fuzz_delims))
        if login:
            parts_fields.append(login)
        parts_fields.append(hostport)
        if path:
            parts_fields.append(path)
            if search is not None:
                parts_fields.append(search)
        parts = Container(name=_merge(name, 'parts'), fields=parts_fields)
        super(HttpUrl, self).__init__(name=name,
                                      scheme=scheme,
                                      parts=parts,
                                      fuzz_scheme=fuzz_scheme,
                                      fuzz_delim=fuzz_delims,
                                      fuzzable=fuzzable)
Esempio n. 14
0
    def __init__(self,
                 host,
                 port=None,
                 fuzz_host=True,
                 fuzz_port=True,
                 fuzz_delim=True,
                 fuzzable=True,
                 name=None):
        '''
        :type host:

            str or instance of :class:`~kitty.model.low_level.field.BaseField`
            recommend using :class:`~katnip.legos.url.HostName`

        :param host: hostname
        :param port: port number (default: None)
        :param fuzz_host: should fuzz the hostname (default: True)
        :param fuzz_port: should fuzz the port (default: True)
        :param fuzz_delim: should fuzz the delimiter (default: True)
        :param fuzzable: should fuzz the container (default: True)
        :param name: name of container (default: None)
        '''
        fields = []
        fields.append(
            HostName(host=host,
                     fuzz_delims=fuzz_delim,
                     name=_merge(name, 'host'),
                     fuzzable=fuzz_host))
        if port is not None:
            fields.append(
                Delimiter(name=_merge(name, 'host port delimiter'),
                          value=':',
                          fuzzable=fuzz_delim))
            fields.append(
                DecimalNumber(name=_merge(name, 'port'),
                              value=port,
                              num_bits=32,
                              fuzzable=fuzz_port))
        super(HostPort, self).__init__(name=name,
                                       fields=fields,
                                       fuzzable=fuzzable)
Esempio n. 15
0
 def __init__(self,
              username,
              hostname,
              fuzz_delim=True,
              fuzzable=True,
              name=None):
     '''
     :param username: email username
     :param hostname: email hostname
     :param fuzz_delim: should fuzz the delimiter (default: True)
     :param fuzzable: is the container fuzzable (default: True)
     :param name: name of the container (default: None)
     '''
     fields = [
         _to_string_field(_merge(name, 'username'), username,
                          fuzzable=True),
         Delimiter('@', fuzzable=fuzz_delim),
         _to_string_field(_merge(name, 'hostname'), hostname,
                          fuzzable=True),
     ]
     super(EmailAddress, self).__init__(fields=fields,
                                        fuzzable=fuzzable,
                                        name=name)
Esempio n. 16
0
 def __init__(self, host='', fuzz_delims=False, fuzzable=True, name=None):
     '''
     :type host: str
     :param host: hostname (default: '')
     :param fuzz_delims: should fuzz the delimiters (default: False)
     :param fuzzable: should fuzz the container (default: True)
     :param name: name of container (default: None)
     '''
     fields = []
     domain_labels = host.split('.')
     if len(domain_labels):
         for i, domain_label in enumerate(domain_labels[:-1]):
             fields.append(
                 String(name='domain label %d' % i, value=domain_label))
             fields.append(
                 Delimiter(name='domain label delimiter %d' % i,
                           value='.',
                           fuzzable=fuzz_delims))
         fields.append(
             String(name='top most domain label', value=domain_labels[-1]))
     super(HostName, self).__init__(name=name,
                                    fields=fields,
                                    fuzzable=fuzzable)
Esempio n. 17
0
 def _static_fuzz_strings():
     fuzz_strings = []
     fuzz_strings.extend([s[0] for s in String("")._get_class_lib()])
     fuzz_strings.extend([d[0] for d in Delimiter("")._get_class_lib()])
     return fuzz_strings
Esempio n. 18
0
 def _dynamic_fuzz_strings(value):
     fuzz_strings = []
     fuzz_strings.extend([s[0] for s in String(value)._get_local_lib()])
     fuzz_strings.extend([s[0] for s in Delimiter(value)._get_local_lib()])
     return fuzz_strings