コード例 #1
0
ファイル: entify.py プロジェクト: febrezo/osrframework
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
コード例 #2
0
ファイル: entify.py プロジェクト: humbertcostas/osrframework
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
コード例 #3
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 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" + 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

    # 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