How to use the ciscoconfparse.models_asa function in ciscoconfparse

To help you get started, we’ve selected a few ciscoconfparse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GoSecure / Cisco2Checkpoint / lib / ciscoconfparse_patch.py View on Github external
(?:\s+
    (?Plog)
    (?:\s+(?P{2}))?
    (?:\s+interval\s+(?P\d+))?
 )?
 (?:\s+(?Pdisable))?
 (?:
    (?:\s+(?Pinactive))
   |(?:\s+time-range\s+(?P\S+))
 )?
)
)                                                   # Close non-capture parens
""".format(_ACL_PROTOCOLS, _ACL_LOGLEVELS, _ACL_ICMP_PROTOCOLS, _PORT_NAMES)
_RE_ASA_ACL = re.compile(_RE_ASA_ACL_STR, re.VERBOSE)

class ASAAclLine(models_asa.ASACfgLine):

    def __init__(self, *args, **kwargs):
        """Provide attributes on Cisco ASA Access-Lists"""
        super(ASAAclLine, self).__init__(*args, **kwargs)
        mm = _RE_ASA_ACL.search(self.text)
        if not (mm is None):
            self._mm_results = mm.groupdict()   # All regex match results
        else:
            raise ValueError("[FATAL] models_asa cannot parse '{0}'".format(self.text))

    @classmethod
    def is_object_for(cls, line="", re=re):
        if re.search('^access-list', line):
            return True
        return False
github GoSecure / Cisco2Checkpoint / lib / ciscoconfparse_patch.py View on Github external
_RE_NAMEOBJECT_STR = r'''(?: # Non-capturing parentesis
# Valid values
#   name 1.2.3.4
#   name 1.2.3.4 host1
#   name 1.2.3.4 host1 description bla bla bla
#
  (^name
  \s+(?P\d+\.\d+\.\d+\.\d+)
  (?:\s+(?P\S+))
  (?:\s+description\s+(?P
github GoSecure / Cisco2Checkpoint / lib / ciscoconfparse_patch.py View on Github external
|(^\s+service-object\s+(?P{3})$)
|(^\s+service-object\s+(?P{0})(?:\s+destination)?
    \s+(?P{1})\s+(?P{2}))
|(^\s+service-object\s+(?P{0})(?:\s+destination)?
    \s+(?Prange)\s+(?P\d+)\s+(?P\d+))
|(^\s+service-object\sobject\s+(?P\S+))
|(^\s+port-object\s+(?P{1})\s+(?P{2}))
|(^\s+port-object\s+(?Prange)
    \s+(?P\d+)\s+(?P\d+))
|(^\s+group-object\s+(?P\S+))
|(^\s+icmp-object\s+(?P\S+))
|(^\s+service-object\sicmp\s+(?P\S+))
)                                                   # Close non-capture parens
""".format(_IP_PROTO,_PORT_SIMPLE_OP,_PORT_NAMES,_ACL_PROTOCOLS)
_RE_ASA_SVCGROUP_CHILD = re.compile(_RE_ASA_SVCGROUP_CHILD_STR, re.VERBOSE)
class ASAObjGroupService(models_asa.ASAObjGroupService):
    def __init__(self, *args, **kwargs):
        """Provide attributes on Cisco ASA Service groups"""
        super(ASAObjGroupService, self).__init__(*args, **kwargs)

        # Update to catch specific cases
        self.name = self.re_match_typed(r'object-group\s+service\s+(\S+)\s*.*$',
            result_type=str, default='')
    
    def __repr__(self):
        return "<%s # %s '%s'>" % (self.classname, self.linenum, self.name)

    @classmethod
    def is_object_for(cls, line="", re=re):
        if re.search(r'^(?:object-group\sservice)', line):
            return True
        return False
github GoSecure / Cisco2Checkpoint / lib / ciscoconfparse_patch.py View on Github external
)?
  (?:\s+destination
    (?:                         # destination port
      (?:\s+
        (?P{1})
        \s+(?P(?:(?:{2})\s?)+)
      )
      |(?:\s+range\s+(?P\d+)\s+(?P\d+))
      |(?:\s+object-group\s+(?P\S+))
    )
  )
 )
)                               # Close non-capture parentesis
""".format(_IP_PROTO,_PORT_SIMPLE_OP,_PORT_NAMES)
_RE_ASA_SVCOBJ_CHILD = re.compile(_RE_ASA_SVCOBJ_CHILD_STR, re.VERBOSE)
class ASAObjService(models_asa.ASAObjService):

# TODO: Parent's class is defined differently. Determine why.
#
#   @classmethod
#    def is_object_for(cls, line="", re=re):
#        if 'object service ' in line[0:15].lower():
#            return True
#        return False
    @classmethod
    def is_object_for(cls, line="", re=re):
        if re.search(r'^(object\sservice)', line):
            return True
        return False

    @property
    def name(self):
github GoSecure / Cisco2Checkpoint / lib / ciscoconfparse_patch.py View on Github external
retval['name'] = self._mm_results['name']
        retval['addr'] = self._mm_results['addr']
        retval['desc'] = self._mm_results['desc']

        return retval


_RE_ASA_NETOBJ_CHILD_STR = r"""(?:
(^\s+description(?P.+)$)
|(^\s+host\s+(?P\S+)$)
|(^\s+subnet\s+(?P\d+\.\d+\.\d+\.\d+)\s+(?P\d+\.\d+\.\d+\.\d+)$)
|(^\s+range\s+(?P\d+\.\d+\.\d+\.\d+)\s+(?P\d+\.\d+\.\d+\.\d+)$)
)
"""
_RE_ASA_NETOBJ_CHILD = re.compile(_RE_ASA_NETOBJ_CHILD_STR, re.VERBOSE)
class ASAObjNetwork(models_asa.ASAObjNetwork):

    @property
    def name(self):
        retval = self.re_match_typed(r'^\s*object\snetwork\s+(\S.+)$',
            result_type=str, default='')
        return retval

    @property
    def description(self):
        regex = r"(^\s+description(?P.+)$)"
        retval = self.re_match_iter_typed(regex,
            result_type=str, default='')
        return retval

    @property
    def result_dict(self):
github GoSecure / Cisco2Checkpoint / lib / ciscoconfparse_patch.py View on Github external
models_cisco.IOSAaaGroupServerLine, \
                  models_cisco.IOSHostnameLine, \
                  models_cisco.IOSIntfGlobal, \
                  IOSAclLine, \
                  IOSIPAclLine, \
                  IOSIPAclChildLine, \
                  models_cisco.IOSCfgLine]
    elif syntax=='asa':
        classes = [ASAName, \
                  ASAObjNetwork, \
                  ASAObjService, \
                  ASAObjGroupNetwork, \
                  ASAObjGroupService, \
                  ASAObjGroupProtocol, \
                  models_asa.ASAIntfLine, \
                  models_asa.ASAIntfGlobal, \
                  models_asa.ASAHostnameLine, \
                  ASAAclLine, \
                  models_asa.ASACfgLine]
    for cls in classes:
        if cls.is_object_for(text):
            inst = cls(text=text, 
                comment_delimiter=comment_delimiter) # instance of the proper subclass
            return inst
    raise ValueError("Could not find an object for '%s'" % line)
github GoSecure / Cisco2Checkpoint / lib / ciscoconfparse_patch.py View on Github external
elif mm_r.get('description0',None):
                retval['description'] =  mm_r['description0']
            else:
                raise NotImplementedError("Cannot parse '{0}'".format(obj.text))
        return retval

##
##-------------  ASA object group protocol
##
_RE_ASA_PROTO_GROUP_CHILD_STR = r"""(?:
(^\s+description(?P.+)$)
|(^\s+protocol-object\s+(?P\S+)$)
)
"""
_RE_ASA_PROTO_GROUP_CHILD = re.compile(_RE_ASA_PROTO_GROUP_CHILD_STR, re.VERBOSE)
class ASAObjGroupProtocol(models_asa.BaseCfgLine):
    def __init__(self, *args, **kwargs):
        """Provide attributes on Cisco ASA Service groups"""
        super(ASAObjGroupProtocol, self).__init__(*args, **kwargs)
    
    def __repr__(self):
        return "<%s # %s '%s'>" % (self.classname, self.linenum, self.name)

    @classmethod
    def is_object_for(cls, line="", re=re):
        if re.search(r'^(object-group\sprotocol)', line):
            return True
        return False

    @property
    def name(self):
        retval = self.re_match_typed(r'^\s*object-group\sprotocol\s+(\S.+)$',
github GoSecure / Cisco2Checkpoint / lib / ciscoconfparse_patch.py View on Github external
models_asa.ASAHostnameLine, \
                  ASAAclLine, \
                  models_asa.ASACfgLine]
    for cls in classes:
        if cls.is_object_for(text):
            inst = cls(text=text, 
                comment_delimiter=comment_delimiter) # instance of the proper subclass
            return inst
    raise ValueError("Could not find an object for '%s'" % line)

##
##------------- Monkey Patching
## Temporary patch. Goal is to send a pull request to the project.
##
ccp.ConfigLineFactory = ConfigLineFactory
models_asa.ASAConfigList = ASAConfigList

##
##------------- New CiscoConfParse definition
## Reason: Have a good reference to ASAConfigList
##
class CiscoConfParse(ccp.CiscoConfParse):
    """Parses Cisco IOS configurations and answers queries about the configs"""

    def __init__(self, config="", comment="!", debug=False, factory=False, 
        linesplit_rgx=r"\r*\n+", ignore_blank_lines=True, syntax='ios'):
        """
            You will find a great class description in ccp.CiscoConfParse
        """

        # all IOSCfgLine object instances...
        self.comment_delimiter = comment
github GoSecure / Cisco2Checkpoint / lib / ciscoconfparse_patch.py View on Github external
_RE_ASA_NETOBJECT_STR = r"""(?:                         # Non-capturing parenthesis
(^\s+description(?P.+)$)
|(^\s+network-object\s+host\s+(?P\S+))
|(^\s+network-object
    (?:\s+network)?
    \s+(?P\d+\.\d+\.\d+\.\d+)
    \s+(?P\d+\.\d+\.\d+\.\d+))
|(^\s+network-object
    \s+(?P\S+)
    \s+(?P\d+\.\d+\.\d+\.\d+))
|(^\s+network-object\s+object\s+(?P\S+))
|(^\s+group-object\s+(?P\S+))
)                                                   # Close non-capture parens
"""
_RE_ASA_NETOBJECT = re.compile(_RE_ASA_NETOBJECT_STR, re.VERBOSE)
class ASAObjGroupNetwork(models_asa.ASAObjGroupNetwork):

    def __init__(self, *args, **kwargs):
        """Accept an ASA line number and initialize family relationship
        attributes"""
        super(ASAObjGroupNetwork, self).__init__(*args, **kwargs)

        # Main diff with current code: Additional .+ to catch specific cases.
        self.name = self.re_match_typed(r'^object-group\snetwork\s+(\S.+)$',
            result_type=str, default='')

    @classmethod
    def is_object_for(cls, line="", re=re):
        if re.search(r'^(?:object-group\snetwork)', line):
            return True
        return False