-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathmodels.py
149 lines (116 loc) · 6.52 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
from sqlalchemy import Boolean, Column , ForeignKey
from sqlalchemy import DateTime, Integer, String, Text, Float
from werkzeug import security as seguridad
import sqlalchemy.orm as orm
from app import db
def foreign_key_column(name, type_, target, nullable=False):
"""Construct a foreign key column for a table.
``name`` is the column name. Pass ``None`` to omit this arg in the
``Column`` call; i.e., in Declarative classes.
``type_`` is the column type.
``target`` is the other column this column references.
``nullable``: pass True to allow null values. The default is False
(the opposite of SQLAlchemy's default, but useful for foreign keys).
"""
fk = db.ForeignKey(target)
if name:
return db.Column(name, type_, fk, nullable=nullable)
else:
return db.Column(type_, fk, nullable=nullable)
class Warrior_DB(db.Model):
__tablename__ = "Warrior"
IDWarrior = db.Column(db.Integer, primary_key= True, nullable=False)
State = db.Column(db.String(100))
Legacy = db.Column(db.String(100))
Alias = db.Column(db.String(100),nullable=False)
Os = db.Column(db.String(100))
Arch = db.Column(db.String(100))
Name = db.Column(db.String(100))
PID = db.Column(db.String(100))
Lastseen = db.Column(db.String(100))
IP = db.Column(db.String(100))
class Technique_DB(db.Model):
__tablename__ = "Technique"
IDTech = db.Column(db.Integer, primary_key= True, nullable=False)
URL_Mitre = db.Column(db.String(500))
Name = db.Column(db.String(100))
IDMitre = db.Column(db.String(100), unique=True, nullable=False)
# intels = orm.relationship("Inteligence", order_by="Inteligence.IDIntel")
class Tactic_DB(db.Model):
__tablename__ = "Tactic"
IDTactic = db.Column(db.Integer, primary_key= True, nullable=False)
URL_Mitre = db.Column(db.String(100))
Name = db.Column(db.String(100))
Description = db.Column(db.String(500))
IDMitre = db.Column(db.String(100), unique=True, nullable=False)
# intels = orm.relationship("Inteligence", order_by="Inteligence.IDIntel")
class Inteligence_DB(db.Model):
__tablename__ = "Inteligence"
IDIntel = db.Column(db.Integer, primary_key= True, nullable=False)
IDTech = foreign_key_column("IDTech", db.String, "Technique.IDMitre")
IDTactic = foreign_key_column("IDTactic", db.String, "Tactic.IDMitre")
Function = db.Column(db.String(500))
Terminated = db.Column(db.String(100))
class Threat_DB(db.Model):
__tablename__ = "Threat"
IDthreat = db.Column(db.Integer, primary_key= True, nullable=False)
Created = db.Column(db.String(100))
Modified = db.Column(db.String(100))
Name = db.Column(db.String(100))
Description = db.Column(db.String(1000))
Windows = db.Column(db.String(100))
MacOS = db.Column(db.String(100))
Linux = db.Column(db.String(100))
class Plan_DB(db.Model):
__tablename__ = "Plan"
IDPlan = db.Column(db.Integer, primary_key= True, nullable=False)
IDThreat = foreign_key_column("IDThreat", db.Integer, "Threat.IDthreat")
Name = db.Column(db.String(100))
Description = db.Column(db.String(500))
class Task_DB(db.Model):
__tablename__ = "Task"
IDTask = db.Column(db.Integer, primary_key= True, nullable=False)
IDPlan = foreign_key_column("IDPlan", db.Integer, "Plan.IDPlan")
IDIntel = foreign_key_column("IDIntel", db.Integer, "Inteligence.IDIntel")
Orden = db.Column(db.String(100))
class Directive_DB(db.Model):
__tablename__ = "Directive"
IDDirective = db.Column(db.Integer, primary_key = True, nullable=False)
IDWarrior = foreign_key_column("IDWarrior", db.Integer, "Warrior.IDWarrior")
IDTask = foreign_key_column("IDTask", db.Integer, "Task.IDTask")
Result = db.Column(db.String(2000))
Done = db.Column(db.String(100))
Good = db.Column(db.String(100))
Privilege = db.Column(db.String(100))
class DataStore_DB(db.Model):
__tablename__ = "DataStore"
IDData = db.Column(db.Integer, primary_key= True, nullable=False)
IDWarrior = foreign_key_column("IDWarrior", db.Integer, "Warrior.IDWarrior")
User = db.Column(db.String(100))
IP = db.Column(db.String(100))
Password = db.Column(db.String(100))
NTLM = db.Column(db.String(100))
LM = db.Column(db.String(100))
Port = db.Column(db.String(100))
class Version_DB(db.Model):
__tablename__ = "migrate_version"
repository_id = db.Column(db.String(250), primary_key= True)
repository_path = db.Column(db.Text )
version = db.Column(db.Integer)
class Users_DB(db.Model):
__tablename__ = "usuarios"
id = db.Column(db.Integer, primary_key= True, nullable=False)
username = db.Column(db.String(200), nullable=False)
password_hash = db.Column(db.String(128), nullable=False)
admin = db.Column(db.Boolean, default=False)
latchAccountId = db.Column(db.String(200), nullable=True)
def __repr__(self):
return (u'<{self.__class__.__name__}: {self.id}>'.format(self=self))
@property
def password(self):
raise AttributeError('password is not a readable attribute')
@password.setter
def password(self, password):
self.password_hash = seguridad.generate_password_hash(password)
def verify_password(self, password):
return seguridad.check_password_hash(self.password_hash, password)