Пример #1
0
def entify_main(args):
    ''' 
        Main function. This function is created in this way so as to let other applications make use of the full configuration capabilities of the application.    
    '''
    # Recovering the logger
    # Calling the logger when being imported
    logSet.setupLogger(loggerName="osrframework.entify", verbosity=args.verbose, logFolder=args.logfolder)    
    # From now on, the logger can be recovered like this:
    logger = logging.getLogger("osrframework.entify")

    logger.info("""entify.py Copyright (C) F. Brezo and Y. Rubio (i3visio) 2014
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it under certain conditions.
For details, run:
\tpython entify.py --license""")

    logger.info("Selecting the regular expressions to be analysed...")

    listRegexp = []
    if args.regexp:
        listRegexp = regexp_selection.getRegexpsByName(args.regexp)
    elif args.new_regexp:
        for i, r in enumerate(args.new_regexp):
            listRegexp.append(RegexpObject(name = "NewRegexp"+str(i), reg_exp = args.new_regexp))

    if not args.web:
        results = scanFolderForRegexp(folder = args.input_folder, listRegexp= listRegexp, recursive = args.recursive, verbosity=args.verbose, logFolder= args.logfolder)
    else:
        results = scanResource(uri = args.web, listRegexp= listRegexp, verbosity=args.verbose, logFolder= args.logfolder)
    logger.info("Logging the results:\n" + general.dictToJson(results))

    if not args.quiet:
        print general.dictToJson(results)

    if args.output_folder:
        logger.info("Preparing the output folder...")
        if not os.path.exists(args.output_folder):
            logger.warning("The output folder \'" + args.output_folder + "\' does not exist. The system will try to create it.")
            os.makedirs(args.output_folder)
        logger.info("Storing the results...")
        """if "csv" in args.extension:
            with open(os.path.join(args.output_folder, "results.csv"), "w") as oF:
                oF.write(resultsToCSV(results))"""
        if "json" in args.extension:
            with open(os.path.join(args.output_folder, "results.json"), "w") as oF:
                oF.write(general.dictToJson(results))

    return results
def textToI3visioEntities(argv, platform='all'):
    ''' 
        Method that obtains all the entities in a given i3visio.text entity.

        :param argv:    the uri to be received.
        :param platform:    a platform string representing the regular expression to be used.

        :return:    Nothing is returned but the code of the entities is created.
    '''
    me = MaltegoTransform(argv)

    # Trying to recover all the possible i3visio entities
    found_fields = {}
    
    # Getting the list of <RegExp> objects from entify
    lRegexp = regexp_selection.getRegexpsByName([platform])

    newEntities = entify.getEntitiesByRegexp(data=data, listRegexp = lRegexp)    
    # This returns a dictionary like the following:
    """
        [{
        'attributes': [],
        'type': 'i3visio.sha256',
        'value': 'a9b8c5d848205db514d4097d2b78f4528d01a79f39601e0f9c5c40ed689471'
        }, {
        'attributes': [],
        'type': 'i3visio.sha256',
        'value': 'b28b896e6eeb8d651cacd5f4a4d1490fbe9d05dbc92221609350b0ce7a68e9'
        }, {
        'attributes': [],
        'type': 'i3visio.sha256',
        'value': 'd727fed4d969b14b28165c75ad12d7dddd56c0198fa70cedc3fdad7ac395b2'
        }, {
        'attributes': [],
        'type': 'i3visio.sha256',
        'value': '3e9a2204fcfc6f7dde250e61ca35353411880024102cba14a0bd45f05f1e74'
        }]
    """

    # Adding the new entities
    me.addListOfEntities(newEntities)

    # Returning the output text...
    me.returnOutput()
Пример #3
0
def main(params=None):
    """
    Main function to launch phonefy.

    The function is created in this way so as to let other applications make
    use of the full configuration capabilities of the application. The
    parameters received are used as parsed by this modules `getParser()`.

    Args:
    -----
        params: A list with the parameters as grabbed by the terminal. It is
            None when this is called by an entry_point. If it is called by osrf
            the data is already parsed.

    Results:
    --------
        Returns a list with i3visio entities.
    """
    if params == None:
        parser = getParser()
        args = parser.parse_args(params)
    else:
        args = params

    results = []

    # Recovering the logger
    # Calling the logger when being imported
    logSet.setupLogger(loggerName="osrframework.entify",
                       verbosity=args.verbose,
                       logFolder=args.logfolder)
    # From now on, the logger can be recovered like this:
    logger = logging.getLogger("osrframework.entify")

    logger.info("Selecting the regular expressions to be analysed...")

    if not args.quiet:
        print(general.title(banner.text))

    sayingHello = """
      Entify | Copyright (C) Yaiza Rubio & Félix Brezo (i3visio) 2014-2018

This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you
are welcome to redistribute it under certain conditions. For additional info,
visit <{}>.
""".format(general.LICENSE_URL)
    print(general.info(sayingHello))

    if args.license:
        general.showLicense()
    else:
        listRegexp = []
        if args.regexp:
            listRegexp = regexp_selection.getRegexpsByName(args.regexp)
        elif args.new_regexp:
            for i, r in enumerate(args.new_regexp):
                listRegexp.append(
                    RegexpObject(name="NewRegexp" + str(i),
                                 reg_exp=args.new_regexp))

        if not args.web:
            results = scanFolderForRegexp(folder=args.input_folder,
                                          listRegexp=listRegexp,
                                          recursive=args.recursive,
                                          verbosity=args.verbose,
                                          logFolder=args.logfolder,
                                          quiet=args.quiet)
        else:
            results = scanResource(uri=args.web,
                                   listRegexp=listRegexp,
                                   verbosity=args.verbose,
                                   logFolder=args.logfolder)
        logger.info("Logging the results:\n" +
                    json.dumps(results, indent=2, sort_keys=True))

        # Trying to store the information recovered
        if args.output_folder != None:
            # Verifying an output folder was selected
            logger.debug("Preparing the output folder...")
            if not os.path.exists(args.output_folder):
                logger.warning(
                    "The output folder \'" + args.output_folder +
                    "\' does not exist. The system will try to create it.")
                os.makedirs(args.output_folder)

            # Grabbing the results
            fileHeader = os.path.join(args.output_folder, args.file_header)
            for ext in args.extension:
                # Generating output files
                general.exportUsufy(results, ext, fileHeader)

        # Showing the information gathered if requested
        if not args.quiet:
            now = dt.datetime.now()
            print("\n{}\tResults obtained:\n".format(str(now)))
            print(general.success(general.usufyToTextExport(results)))

            now = dt.datetime.now()
            print(
                str(now) +
                "\tYou can find all the information collected in the following files:"
            )
            for ext in args.extension:
                # Showing the output files
                print("\t-" + general.emphasis(fileHeader + "." + ext))

            # Urging users to place an issue on Github...
            print(banner.footer)

    if params:
        return results
Пример #4
0
def main(args):
    ''' 
        Main function. This function is created in this way so as to let other applications make use of the full configuration capabilities of the application.    
    '''
    # Recovering the logger
    # Calling the logger when being imported
    logSet.setupLogger(loggerName="osrframework.entify", verbosity=args.verbose, logFolder=args.logfolder)    
    # From now on, the logger can be recovered like this:
    logger = logging.getLogger("osrframework.entify")

    logger.info("""entify.py Copyright (C) F. Brezo and Y. Rubio (i3visio) 2014
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it under certain conditions. For additional info, visit to <http://www.gnu.org/licenses/gpl-3.0.txt>.""")

    logger.info("Selecting the regular expressions to be analysed...")

    sayingHello = """entify.py Copyright (C) F. Brezo and Y. Rubio (i3visio) 2015
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it under certain conditions. For additional info, visit <http://www.gnu.org/licenses/gpl-3.0.txt>."""    
    if not args.quiet:
        print sayingHello
        print
        logger.info("Starting entify.py")

    listRegexp = []
    if args.regexp:
        listRegexp = regexp_selection.getRegexpsByName(args.regexp)
    elif args.new_regexp:
        for i, r in enumerate(args.new_regexp):
            listRegexp.append(RegexpObject(name = "NewRegexp"+str(i), reg_exp = args.new_regexp))

    if not args.web:
        results = scanFolderForRegexp(folder = args.input_folder, listRegexp= listRegexp, recursive = args.recursive, verbosity=args.verbose, logFolder= args.logfolder, quiet=args.quiet)
    else:
        results = scanResource(uri = args.web, listRegexp= listRegexp, verbosity=args.verbose, logFolder= args.logfolder)
    logger.info("Logging the results:\n" + general.dictToJson(results))

    # Trying to store the information recovered
    if args.output_folder != None:    
        # Verifying an output folder was selected
        logger.debug("Preparing the output folder...")
        if not os.path.exists(args.output_folder):
            logger.warning("The output folder \'" + args.output_folder + "\' does not exist. The system will try to create it.")
            os.makedirs(args.output_folder)

        # Grabbing the results 
        fileHeader = os.path.join(args.output_folder, args.file_header)            
        for ext in args.extension:
            # Generating output files
            general.exportUsufy(results, ext, fileHeader)        

    # Showing the information gathered if requested                
    if not args.quiet:
        print "A summary of the results obtained are shown in the following table:"
        print unicode(general.usufyToTextExport(results))
        print

        print "You can find all the information collected in the following files:"                                                     
        for ext in args.extension:
            # Showing the output files
            print "\t-" + fileHeader + "." + ext         

    return results
Пример #5
0
def main(args):
    '''
        Main function. This function is created in this way so as to let other applications make use of the full configuration capabilities of the application.
    '''
    # Recovering the logger
    # Calling the logger when being imported
    logSet.setupLogger(loggerName="osrframework.entify", verbosity=args.verbose, logFolder=args.logfolder)
    # From now on, the logger can be recovered like this:
    logger = logging.getLogger("osrframework.entify")

    logger.info("""entify.py Copyright (C) F. Brezo and Y. Rubio (i3visio) 2015-2017
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it under certain conditions. For additional info, visit to <http://www.gnu.org/licenses/gpl-3.0.txt>.""")

    logger.info("Selecting the regular expressions to be analysed...")

    sayingHello = """entify.py Copyright (C) F. Brezo and Y. Rubio (i3visio) 2015-2017
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it under certain conditions. For additional info, visit <http://www.gnu.org/licenses/gpl-3.0.txt>."""
    if not args.quiet:
        print banner.text

        print sayingHello
        print
        logger.info("Starting entify.py")

    listRegexp = []
    if args.regexp:
        listRegexp = regexp_selection.getRegexpsByName(args.regexp)
    elif args.new_regexp:
        for i, r in enumerate(args.new_regexp):
            listRegexp.append(RegexpObject(name = "NewRegexp"+str(i), reg_exp = args.new_regexp))

    if not args.web:
        results = scanFolderForRegexp(folder = args.input_folder, listRegexp= listRegexp, recursive = args.recursive, verbosity=args.verbose, logFolder= args.logfolder, quiet=args.quiet)
    else:
        results = scanResource(uri = args.web, listRegexp= listRegexp, verbosity=args.verbose, logFolder= args.logfolder)
    logger.info("Logging the results:\n" + json.dumps(results, indent=2, sort_keys=True))

    # Trying to store the information recovered
    if args.output_folder != None:
        # Verifying an output folder was selected
        logger.debug("Preparing the output folder...")
        if not os.path.exists(args.output_folder):
            logger.warning("The output folder \'" + args.output_folder + "\' does not exist. The system will try to create it.")
            os.makedirs(args.output_folder)

        # Grabbing the results
        fileHeader = os.path.join(args.output_folder, args.file_header)
        for ext in args.extension:
            # Generating output files
            general.exportUsufy(results, ext, fileHeader)

    # Showing the information gathered if requested
    if not args.quiet:
        print "A summary of the results obtained are shown in the following table:"
        print unicode(general.usufyToTextExport(results))
        print

        print "You can find all the information collected in the following files:"
        for ext in args.extension:
            # Showing the output files
            print "\t-" + fileHeader + "." + ext

    # Urging users to place an issue on Github...
    if not args.quiet:
        print
        print "Did something go wrong? Is a platform reporting false positives? Do you need to integrate a new one?"
        print "Then, place an issue in the Github project: <https://github.com/i3visio/osrframework/issues>."
        print "Note that otherwise, we won't know about it!"
        print

    return results
def uriToI3visioEntities(argv, platform='all'):
    ''' 
        Method that obtains all the entities in a given profile.

        :param argv:    the uri to be received.
        :param platform:    a platform string representing the regular expression to be used.

        :return:    Nothing is returned but the code of the entities is created.
    '''
    me = MaltegoTransform(argv)

    # Recovering the Uri value
    try:
        uri = argv
    except:
        uri = me.getVar("@value")

    #print uri
    newEntities = []

    # Defining the main entity
    aux = {}
    aux["type"] = "i3visio.uri"
    aux["value"] = uri
    aux["attributes"] = []
    newEntities.append(aux)

    # Using i3visio browser to avoid certain issues...
    i3Browser = browser.Browser()
    # Accessing the resources
    data = i3Browser.recoverURL(uri)

    # Getting the list of <RegExp> objects from entify
    lRegexp = regexp_selection.getRegexpsByName([platform])

    newEntities = entify.getEntitiesByRegexp(data=data, listRegexp=lRegexp)
    # This returns a dictionary like the following:
    """
        [{
        'attributes': [],
        'type': 'i3visio.sha256',
        'value': 'a9b8c5d848205db514d4097d2b78f4528d01a79f39601e0f9c5c40ed689471'
        }, {
        'attributes': [],
        'type': 'i3visio.sha256',
        'value': 'b28b896e6eeb8d651cacd5f4a4d1490fbe9d05dbc92221609350b0ce7a68e9'
        }, {
        'attributes': [],
        'type': 'i3visio.sha256',
        'value': 'd727fed4d969b14b28165c75ad12d7dddd56c0198fa70cedc3fdad7ac395b2'
        }, {
        'attributes': [],
        'type': 'i3visio.sha256',
        'value': '3e9a2204fcfc6f7dde250e61ca35353411880024102cba14a0bd45f05f1e74'
        }]
    """
    # Adding list of entities to be displayed
    me.addListOfEntities(newEntities)
    #print json.dumps(entities, indent=2)
    #for elem in entities:
    #    newEnt = me.addEntity(elem["type"],elem["value"])
    #    newEnt.setDisplayInformation("<h3>" + elem["value"] +"</h3><p>"+str(elem["attributes"])+"</p>")
    #    for extraAtt in elem["attributes"]:
    #        newEnt.addAdditionalFields(str(extraAtt['type']), str(extraAtt['type']), True, str(extraAtt['value']))

    # Returning the output text...
    me.returnOutput()
Пример #7
0
def uriToI3visioEntities(argv, platform="all"):
    """ 
        Method that obtains all the entities in a given profile.

        :param argv:    the uri to be received.
        :param platform:    a platform string representing the regular expression to be used.

        :return:    Nothing is returned but the code of the entities is created.
    """
    me = MaltegoTransform(argv)

    # Recovering the Uri value
    try:
        uri = argv
    except:
        uri = me.getVar("@value")

    # print uri
    newEntities = []

    # Defining the main entity
    aux = {}
    aux["type"] = "i3visio.uri"
    aux["value"] = uri
    aux["attributes"] = []
    newEntities.append(aux)

    # Using i3visio browser to avoid certain issues...
    i3Browser = browser.Browser()
    # Accessing the resources
    data = i3Browser.recoverURL(uri)

    # Getting the list of <RegExp> objects from entify
    lRegexp = regexp_selection.getRegexpsByName([platform])

    newEntities = entify.getEntitiesByRegexp(data=data, listRegexp=lRegexp)
    # This returns a dictionary like the following:
    """
        [{
        'attributes': [],
        'type': 'i3visio.sha256',
        'value': 'a9b8c5d848205db514d4097d2b78f4528d01a79f39601e0f9c5c40ed689471'
        }, {
        'attributes': [],
        'type': 'i3visio.sha256',
        'value': 'b28b896e6eeb8d651cacd5f4a4d1490fbe9d05dbc92221609350b0ce7a68e9'
        }, {
        'attributes': [],
        'type': 'i3visio.sha256',
        'value': 'd727fed4d969b14b28165c75ad12d7dddd56c0198fa70cedc3fdad7ac395b2'
        }, {
        'attributes': [],
        'type': 'i3visio.sha256',
        'value': '3e9a2204fcfc6f7dde250e61ca35353411880024102cba14a0bd45f05f1e74'
        }]
    """
    # Adding list of entities to be displayed
    me.addListOfEntities(newEntities)
    # print json.dumps(entities, indent=2)
    # for elem in entities:
    #    newEnt = me.addEntity(elem["type"],elem["value"])
    #    newEnt.setDisplayInformation("<h3>" + elem["value"] +"</h3><p>"+str(elem["attributes"])+"</p>")
    #    for extraAtt in elem["attributes"]:
    #        newEnt.addAdditionalFields(str(extraAtt['type']), str(extraAtt['type']), True, str(extraAtt['value']))

    # Returning the output text...
    me.returnOutput()