Example #1
0
 def initStructure(self):
     '''Init history structure.'''
     sessionName = cf.cf.getData('sessionName')
     dbName = os.path.join(get_temp_dir(), 'db_' + sessionName)
     self._db = DB()
     # Check if the database already exists
     if os.path.exists(dbName):
         # Find one that doesn't exist
         for i in xrange(100):
             newDbName = dbName + '-' + str(i)
             if not os.path.exists(newDbName):
                 dbName = newDbName
                 break
     self._db.connect(dbName)
     self._sessionDir = os.path.join(get_temp_dir(),
                                     self._db.getFileName() + '_traces')
     tablename = self.getTableName()
     # Init tables
     self._db.createTable(
             tablename,
             self.getColumns(),
             self.getPrimaryKeyColumns())
     self._db.createIndex(tablename, self.getIndexColumns())
     # Init dirs
     try:
         os.mkdir(self._sessionDir)
     except OSError, oe:
         # [Errno EEXIST] File exists
         if oe.errno != EEXIST:
             msg = 'Unable to write to the user home directory: ' + get_temp_dir()
             raise w3afException(msg)
Example #2
0
class gtkOutput(baseOutputPlugin):
    '''
    Saves messages to kb.kb.getData('gtkOutput', 'queue'), messages are saved in the form of objects.
    
    @author: Andres Riancho ( [email protected] )
    '''
    
    def __init__(self):
        baseOutputPlugin.__init__(self)
        
        if not kb.kb.getData('gtkOutput', 'db') == []:
            # Restore it from the kb
            self._db = kb.kb.getData('gtkOutput', 'db')
            self.queue = kb.kb.getData('gtkOutput', 'queue')
        else:
            self.queue = Queue.Queue()
            kb.kb.save('gtkOutput', 'queue' , self.queue)
            # Create DB and add tables
            sessionName = cf.cf.getData('sessionName')
            dbName = os.path.join(get_home_dir(), 'sessions', 'db_' + sessionName)
            # Just in case the directory doesn't exist...
            try:
                os.mkdir(os.path.join(get_home_dir() , 'sessions'))
            except OSError, oe:
                # [Errno 17] File exists
                if oe.errno != 17:
                    msg = 'Unable to write to the user home directory: ' + get_home_dir()
                    raise w3afException( msg )

            self._db = DB()
            # Check if the database already exists
            if os.path.exists(dbName):
                # Find one that doesn't exist
                for i in xrange(100):
                    newDbName = dbName + '-' + str(i)
                    if not os.path.exists(newDbName):
                        dbName = newDbName
                        break

            # Create DB!
            self._db.open(dbName)
            # Create table
            historyItem = HistoryItem(self._db)
            self._db.createTable(historyItem.getTableName(),
                    historyItem.getColumns(),
                    historyItem.getPrimaryKeyColumns())
            kb.kb.save('gtkOutput', 'db', self._db)
Example #3
0
    def __init__(self):
        baseOutputPlugin.__init__(self)
        
        if not kb.kb.getData('gtkOutput', 'db') == []:
            # Restore it from the kb
            self._db = kb.kb.getData('gtkOutput', 'db')
            self.queue = kb.kb.getData('gtkOutput', 'queue')
        else:
            self.queue = Queue.Queue()
            kb.kb.save('gtkOutput', 'queue' , self.queue)
            # Create DB and add tables
            sessionName = cf.cf.getData('sessionName')
            dbName = os.path.join(get_home_dir(), 'sessions', 'db_' + sessionName)
            # Just in case the directory doesn't exist...
            try:
                os.mkdir(os.path.join(get_home_dir() , 'sessions'))
            except OSError, oe:
                # [Errno 17] File exists
                if oe.errno != 17:
                    msg = 'Unable to write to the user home directory: ' + get_home_dir()
                    raise w3afException( msg )

            self._db = DB()
            # Check if the database already exists
            if os.path.exists(dbName):
                # Find one that doesn't exist
                for i in xrange(100):
                    newDbName = dbName + '-' + str(i)
                    if not os.path.exists(newDbName):
                        dbName = newDbName
                        break

            # Create DB!
            self._db.connect(dbName)
            # Init history
            historyItem = HistoryItem(self._db)
            historyItem.initStructure()
            kb.kb.save('gtkOutput', 'db', self._db)
Example #4
0
class HistoryItem(object):
    '''Represents history item.'''

    _db = None
    _dataTable = 'data_table'
    _columns = [
        ('id','integer'), ('url', 'text'), ('code', 'integer'),
        ('tag', 'text'), ('mark', 'integer'), ('info', 'text'),
        ('time', 'float'), ('msg', 'text'), ('content_type', 'text'),
        ('charset', 'text'), ('method', 'text'), ('response_size', 'integer'),
        ('codef', 'integer'), ('alias', 'text'), ('has_qs', 'integer')
    ]
    _primaryKeyColumns = ('id',)
    _indexColumns = ('alias',)
    id = None
    _request = None
    _response = None
    info = None
    mark = False
    tag = ''
    contentType= ''
    responseSize = 0
    method = 'GET'
    msg = 'OK'
    code = 200
    time = 0.2

    def __init__(self):
        '''Construct object.'''
        self._border = '-#=' * 20
        self._ext = '.trace'
        if not kb.kb.getData('history', 'db') == []:
            self._db = kb.kb.getData('history', 'db')
            self._sessionDir = kb.kb.getData('history', 'sessionDir')
        else:
            self.initStructure()

    @property
    def response(self):
        resp = self._response
        if not resp and self.id:
            self._request, resp = self._loadFromFile(self.id)
            self._response = resp
        return resp
    
    @response.setter
    def response(self, resp):
        self._response = resp
    
    @property
    def request(self):
        req = self._request
        if not req and self.id:
            req, self._response = self._loadFromFile(self.id)
            self._request = req
        return req
    
    @request.setter
    def request(self, req):
        self._request = req    
    
    def initStructure(self):
        '''Init history structure.'''
        sessionName = cf.cf.getData('sessionName')
        dbName = os.path.join(get_temp_dir(), 'db_' + sessionName)
        self._db = DB()
        # Check if the database already exists
        if os.path.exists(dbName):
            # Find one that doesn't exist
            for i in xrange(100):
                newDbName = dbName + '-' + str(i)
                if not os.path.exists(newDbName):
                    dbName = newDbName
                    break
        self._db.connect(dbName)
        self._sessionDir = os.path.join(get_temp_dir(),
                                        self._db.getFileName() + '_traces')
        tablename = self.getTableName()
        # Init tables
        self._db.createTable(
                tablename,
                self.getColumns(),
                self.getPrimaryKeyColumns())
        self._db.createIndex(tablename, self.getIndexColumns())
        # Init dirs
        try:
            os.mkdir(self._sessionDir)
        except OSError, oe:
            # [Errno EEXIST] File exists
            if oe.errno != EEXIST:
                msg = 'Unable to write to the user home directory: ' + get_temp_dir()
                raise w3afException(msg)
        kb.kb.save('history', 'db', self._db)
        kb.kb.save('history', 'sessionDir', self._sessionDir)