Exemplo n.º 1
0
class User(db.Model, UserMixin):
    """
    User model.
    """
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True)
    # N-N relationships
    samples = db.relationship('Sample',
                              secondary=usersample,
                              backref=db.backref('users', lazy="dynamic"))
    families = db.relationship('Family',
                               secondary=userfamily,
                               backref=db.backref('users', lazy="dynamic"))
    # Login
    nickname = db.Column(db.String(), index=True, unique=True)

    # Complete user name
    completename = db.Column(db.String(), index=True, unique=True)

    theme = db.Column(db.String())

    # User's email (not used for now)
    email = db.Column(db.String(), index=True, unique=True)
    # Password
    password = db.Column(db.String())
    api_key = db.Column(db.String())
    roles = db.relationship('Role',
                            secondary=roles_users,
                            backref=db.backref('users', lazy='dynamic'))

    last_login_at = db.Column(db.DateTime())
    current_login_at = db.Column(db.DateTime())
    last_login_ip = db.Column(db.String(45))
    current_login_ip = db.Column(db.String(45))
    login_count = db.Column(db.Integer)
    active = db.Column(db.Boolean(), default=False)

    def get_id(self):
        return self.id

    def __repr__(self):
        return '<User %r>' % (self.nickname)
Exemplo n.º 2
0
class Family(db.Model):
    """
    Family model.
    """
    __tablename__ = 'family'

    id = db.Column(db.Integer, primary_key=True)

    # N-N relationships
    samples = db.relationship('Sample',
                              secondary=familytosample,
                              backref=db.backref('families', lazy='dynamic'))
    yaras = db.relationship('YaraRule',
                            secondary=familytoyara,
                            backref=db.backref('families', lazy='dynamic'))
    # 1-N relationships
    parent_id = db.Column(db.Integer, db.ForeignKey('family.id'))
    subfamilies = db.relationship('Family',
                                  backref=db.backref('parents',
                                                     remote_side=[id]))
    # 1-N relationships, without any backrefs for now
    associated_files = db.relationship('FamilyDataFile')
    detection_items = db.relationship('DetectionElement')
    # Family name's
    name = db.Column(db.String(), index=True, unique=True)
    # User-supplied abstract
    abstract = db.Column(db.String())
    # Analysis status
    status = db.Column(db.Integer(), default=FamilyStatus.NOT_STARTED)
    # Tlp level
    TLP_sensibility = db.Column(db.Integer(), default=TLPLevel.TLPAMBER)

    def __repr__(self):
        return 'Family %d %s' % (self.id, self.name)

    def __init__(self, name=None):
        if name is None:
            raise IOError
        self.name = name
Exemplo n.º 3
0
class User(db.Model, UserMixin):
    """
    User model.
    """
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True)
    # N-N relationships
    samples = db.relationship('Sample', secondary=usersample,
                              backref=db.backref('users', lazy="dynamic"))
    families = db.relationship('Family', secondary=userfamily,
                               backref=db.backref('users', lazy="dynamic"))
    # Login
    nickname = db.Column(db.String(), index=True, unique=True)
    # Complete user name
    completename = db.Column(db.String(), index=True, unique=True)
    theme = db.Column(db.String())
    # User's email (not used for now)
    email = db.Column(db.String(), index=True, unique=True)
    # User's most loved pokemon!!!
    poke_id = db.Column(db.Integer())
    # Password
    password = db.Column(db.String())
    api_key = db.Column(db.String())
    # Priv level
    privilege_level = db.Column(db.Integer())

    # Flask-login related methods. All methods return True because multiple
    # logins are authorized.
    def get_id(self):
        return self.id

    def is_active(self):
        return True

    def is_authenticated(self):
        return True

    def __repr__(self):
        return '<User %r>' % (self.nickname)
Exemplo n.º 4
0
class IDAStruct(IDAAction):
    """
        Structures are a particular type of
        actions, as the address and will always be null,
        and they store a relationship with their members
        The management of the members is done by the controller,
        and at each update the structure's timestamp is updated
    """
    __tablename__ = "idastructs"
    id = db.Column(db.Integer(),
                   db.ForeignKey('idaactions.id'),
                   primary_key=True)
    name = db.Column(db.String())
    size = db.Column(db.Integer())
    members = db.relationship("IDAStructMember",
                              backref=db.backref("struct"),
                              remote_side=[id])

    __mapper_args__ = {"polymorphic_identity": "idastructs"}
Exemplo n.º 5
0
class Sample(db.Model):
    """
    Samples model.
    """
    __tablename__ = 'sample'
    id = db.Column(db.Integer, primary_key=True)
    # N-N relationships
    family_id = db.Column(db.Integer, db.ForeignKey('family.id'))
    check_list = db.relationship('CheckList',
                                 secondary=sampletochecklist,
                                 backref=db.backref('samples', lazy='dynamic'))
    actions = db.relationship('IDAAction',
                              secondary=sampletoactions,
                              backref=db.backref('samples', lazy='dynamic'))
    yaras = db.relationship('YaraRule',
                            secondary=sampletoyara,
                            backref=db.backref('samples', lazy='dynamic'))
    # Enriched N-N relationships (double link)
    linked_samples = db.relationship('SampleMatch',
                                     backref=db.backref('sample1',
                                                        remote_side=[id]),
                                     foreign_keys=[SampleMatch.sid_1])
    linked_samples_2 = db.relationship('SampleMatch',
                                       backref=db.backref('sample2',
                                                          remote_side=[id]),
                                       foreign_keys=[SampleMatch.sid_2])
    # 1-N relationships
    strings = db.relationship(
        "StringsItem", backref=db.backref(
            'sample', remote_side=[id]))
    s_metadata = db.relationship(
        "SampleMetadata", backref=db.backref(
            'sample', remote_side=[id]))
    functions = db.relationship(
        "FunctionInfo", backref=db.backref(
            'sample', remote_side=[id]), lazy="dynamic")
    filenames = db.relationship(
        "FileName", backref=db.backref(
            'sample', remote_side=[id]))
    analysis_data = db.relationship(
        'AnalysisResult', backref=db.backref(
            "sample", remote_side=[id]))
    # Sample's binary path
    storage_file = db.Column(db.String())
    # File size
    size = db.Column(db.Integer())
    # File's internal date (compilation timestamp, etc.)
    file_date = db.Column(db.DateTime(), index=True)
    # Hashes
    md5 = db.Column(db.String(32), index=True, nullable=False)
    sha1 = db.Column(db.String(40), index=True, nullable=False)
    sha256 = db.Column(db.String(64), index=True, nullable=False)
    # Mime type
    mime_type = db.Column(db.String())
    full_mime_type = db.Column(db.String())
    # Abstract, set by user
    abstract = db.Column(db.String())
    # Import hash, set by tasks
    import_hash = db.Column(db.String(), index=True)
    # TLP level, mandatory
    TLP_sensibility = db.Column(
        db.Integer(),
        nullable=False,
        default=TLPLevel.TLPAMBER)
    # Analysis status
    analysis_status = db.Column(
        db.Integer(),
        nullable=False,
        default=AnalysisStatus.TOSTART)
    # Sample's analysis date
    analysis_date = db.Column(db.DateTime())
    # "status" is not used, for now
    # status = db.Column(db.Integer())

    def __repr__(self):
        return 'Sample %d' % self.id