예제 #1
0
    def createDefault():
        logging.info("Create a default configuration file")
        defaultConfig = ConfigParser.RawConfigParser()
        defaultConfig.add_section('clustering')
        defaultConfig.add_section('projects')
        defaultConfig.add_section('automata')
        defaultConfig.add_section('logging')
        defaultConfig.add_section('import')

        defaultConfig.set('clustering', 'equivalence_threshold', '60')
        defaultConfig.set('clustering', 'orphan_reduction', '0')
        defaultConfig.set('clustering', 'nbiteration', '100')
        defaultConfig.set('clustering', 'do_internal_slick', '0')
        defaultConfig.set('clustering', 'protocol_type', '1')

        defaultTraceDirectory = os.path.join(ResourcesConfiguration.getWorkspaceFile(), "projects")
        defaultConfig.set('projects', 'path', defaultTraceDirectory)

        defaultAutomatonDirectory = os.path.join(ResourcesConfiguration.getWorkspaceFile(), "automaton")
        defaultConfig.set('automata', 'path', defaultAutomatonDirectory)

        defaultConfig.set('logging', 'path', '')

        #defaultConfig.set('import', 'repository_prototypes', 'resources/prototypes/repository.xml')
        defaultConfig.set('import', 'repository_prototypes', '')

        return defaultConfig
예제 #2
0
 def test_workspaceParsing(self):
     
     # We first load the workspace
     workspace = Workspace.loadWorkspace(ResourcesConfiguration.getWorkspaceFile())
     self.assertNotEqual(workspace, None)
     
     
     
     # Now we load all the project which are declared in
     for project_path in workspace.getProjectsPath() :
         project = Project.loadProject(workspace, project_path)
         if project != None :
             logging.info("The project " + project.getName() + " has been loaded !")        
예제 #3
0
    def __init__(self):
        self.configurationFilePath = os.path.join(ResourcesConfiguration.getWorkspaceFile(), ResourcesConfiguration.CONFFILE)

        # If the config file exists we parse it
        # if not we create an in-memory default one
        if self.configurationFilePath == None or not os.path.isfile(self.configurationFilePath):
            # create default in memory file
            self.config = ConfigurationParser.createDefault()
            self.config.write(open(self.configurationFilePath, "w"))
        else:
            # Configure the configuration parser
            self.config = ConfigParser.ConfigParser()
            # Parse the configuration file
            self.config.read(self.configurationFilePath)
예제 #4
0
파일: NetzobGui.py 프로젝트: KurSh/netzob
    def __init__(self):

        # Command line commands
        parser = CommandLine.get_parser()
        opts, args = parser.parse_args()

        gettext.bindtextdomain("netzob", ResourcesConfiguration.getLocaleLocation())
        gettext.textdomain("netzob")

        try:
            locale.getlocale()
        except:
            logging.exception("setlocale failed, resetting to C")
            locale.setlocale(locale.LC_ALL, "C")

        (status, version) = DepCheck.test_lxml()
        if status == False:
            logging.fatal("Version of python-lxml ({0}) is too old for Netzob. Please install a recent version (>= 2.3)".format(version))
            sys.exit()

        # First we initialize and verify all the resources
        if not ResourcesConfiguration.initializeResources():
            logging.fatal("Error while configuring the resources of Netzob")
            sys.exit()

        if opts.workspace == None:
            workspace = str(ResourcesConfiguration.getWorkspaceFile())
        else:
            workspace = opts.workspace

        logging.debug("The workspace: {0}".format(str(workspace)))

        # loading the workspace
        self.currentWorkspace = (Workspace.loadWorkspace(workspace))

        # the semi-automatic loading of the workspace has failed (second attempt)
        if self.currentWorkspace == None:
            # we force the creation (or specification) of the workspace
            if not ResourcesConfiguration.initializeResources(True):
                logging.fatal("Error while configuring the resources of Netzob")
                sys.exit()
            workspace = str(ResourcesConfiguration.getWorkspaceFile())
            logging.debug("The workspace: {0}".format(str(workspace)))
            # loading the workspace
            self.currentWorkspace = (Workspace.loadWorkspace(workspace))
            if self.currentWorkspace == None:
                logging.fatal("Stopping the execution (no workspace computed)!")
                sys.exit()

        self.currentProject = self.currentWorkspace.getLastProject()

        # Second we create the logging infrastructure
        LoggingConfiguration().initializeLogging(self.currentWorkspace)

        # Now we load all the available plugins
        NetzobPlugin.loadPlugins(self)

        # create logger with the given configuration
        self.log = logging.getLogger('netzob.py')
        self.log.info(_("Starting netzob"))

        # Main window definition
        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
        self.set_default_size(800, 600)
        self.set_title(_("Netzob: Inferring communication protocols"))

        self.set_icon_from_file(("%s/logo.png" %
                                 ResourcesConfiguration.getStaticResources()))
        self.connect("delete_event", self.evnmtDelete)
        self.connect("destroy", self.destroy)
        main_vbox = gtk.VBox(False, spacing=0)

        # Create and display the menu

        self.menu = Menu(self)
        menubar = self.menu.getMenuBar(self)
        menubar.show()
        self.menu.update()
        main_vbox.pack_start(menubar, False, True, 0)

        # Notebook definition
        self.notebook = gtk.Notebook()
        self.notebook.set_tab_pos(gtk.POS_TOP)
        self.notebook.connect("switch-page", self.notebookFocus)
        main_vbox.pack_start(self.notebook, True, True, 0)

        self.pageList = []
        # Adding the different notebook
        self.modelization = UImodelization(self)
        self.grammarInference = UIGrammarInference(self)
#        self.fuzzing = UIfuzzing(self)
        self.simulator = UISimulator(self)

        self.pageList.append([_("Vocabulary inference"), self.modelization])
        self.pageList.append([_("Grammar inference"), self.grammarInference])
#        self.pageList.append(["Fuzzing", self.fuzzing])
        self.pageList.append([_("Simulator"), self.simulator])

        for page in self.pageList:
            self.notebook.append_page(page[1].panel, gtk.Label(page[0]))

        # Initialize a clipboard object
        self.clipboard = (gtk.Clipboard(gtk.gdk.display_get_default(),
                                        "CLIPBOARD"))

        # Show every widgets
        self.notebook.show()
        main_vbox.show()
        self.add(main_vbox)
        self.show()