Beispiel #1
0
class BaseTask(Resource, Builtin):
    title = models.CharField(max_length=100, default='')
    event = models.ForeignKey(TaskEvent, on_delete=models.SET_NULL, null=True)
    content = models.TextField(default=None, null=True)
    answer = models.CharField(max_length=1024, null=True)
    score = models.PositiveIntegerField(default=0)
    public = models.BooleanField()
    last_edit_time = models.DateTimeField(default=timezone.now)
    status = models.PositiveIntegerField(default=TaskStatus.NORMAL)
    hash = models.CharField(max_length=100, null=True)
    is_copy = models.BooleanField(default=False)
    objects = MyManager({'status': TaskStatus.DELETE})
    original_objects = models.Manager()
    knowledges = models.CharField(max_length=1024, null=True)

    class Meta:
        abstract = True

    class MyMeta:
        _builtin_modify_field = [
            'public', 'id', 'is_copy', 'hash', 'status', 'last_edit_time'
        ]

    ResourceMeta = resource.BaseTaskMeta

    def __unicode__(self):
        return '%s' % self.title
Beispiel #2
0
class LessonJstree(Resource, models.Model):
    Type = enum(
        DEFAULT=0,
        FOLDER=1,
        FILE=2,
    )
    self_id = models.CharField(max_length=50)  # 记录jstree的id lesson+id 根id course+id
    course = models.ForeignKey(Course, null=True, blank=True, related_name='course_child')
    lesson = models.ForeignKey(Lesson, null=True, blank=True, related_name='lesson_child')
    parent = models.CharField(max_length=50, default="#")
    parents = models.CharField(max_length=100, default="#")
    text = models.CharField(max_length=200)
    type = models.PositiveIntegerField(default=Type.DEFAULT)  # 创建文件类型
    # state = models.CharField(max_length=200, null=True, blank=True)  # 节点属性json格式字符串
    public = models.BooleanField(default=True)  # 默认公开
    order = models.PositiveIntegerField(default=0)

    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)

    objects = models.Manager()
    original_objects = MyManager({'public': False})

    class Meta:
        db_table = 'course_lesson_jstree'
        unique_together = ('self_id', "course")

    def __unicode__(self):
        return self.text

    ResourceMeta = resource.LessonJstreeMeta
Beispiel #3
0
class OccupationSystem(Builtin):
    Difficult = enum(
        FIRSTLEVEL=1,
        SECONDLEVEL=2,
        THIRDLEVEL=3,
        FOURTHLEVEL=4,
    )

    name = models.CharField(max_length=100)
    describe = models.TextField(null=True, blank=True)
    difficulty = models.PositiveIntegerField(default=Difficult.FIRSTLEVEL)
    public = models.BooleanField(default=True)
    status = models.PositiveIntegerField(default=Status.NORMAL)
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)

    objects = MyManager({'status': Status.DELETE})
    original_objects = models.Manager()

    def __unicode__(self):
        return self.name

    class Meta:
        db_table = 'course_occupation_system'
        ordering = ['-create_time', '-update_time']

    class MyMeta:
        _builtin_modify_field = ['public', 'id']
Beispiel #4
0
class EventTask(models.Model):
    event = models.ForeignKey(Event, on_delete=models.PROTECT)
    seq = models.IntegerField()
    task_hash = models.CharField(max_length=500)
    task_score = models.FloatField(default=0)
    public = models.BooleanField(default=True)
    public_time = models.DateTimeField(default=None, null=True)

    # 题目类型
    Type = enum(
        THEORY=api.PRACTICE_TYPE_THEORY,
        REAL_VULN=api.PRACTICE_TYPE_REAL_VULN,
        EXCRISE=api.PRACTICE_TYPE_EXCRISE,
        MAN_MACHINE=api.PRACTICE_TYPE_MAN_MACHINE,
        ATTACK_DEFENSE=api.PRACTICE_TYPE_ATTACK_DEFENSE,
        WLAN=250,
    )
    type = models.PositiveIntegerField()

    # 题目状态
    Status = enum(
        DELETE=0,
        NORMAL=1,
        CLOSE=2,
    )
    status = models.PositiveIntegerField(default=Status.NORMAL)

    objects = MyManager({'status': Status.DELETE})
    original_objects = models.Manager()
Beispiel #5
0
class BaseEventSignup(models.Model):
    event = models.ForeignKey(Event, on_delete=models.PROTECT)
    time = models.DateTimeField(default=timezone.now)
    token = models.CharField(max_length=33, default=generate_signup_token)

    # 报名状态
    Status = enum(
        DELETE=0,
        SIGNUPED=1,
        FORBIDDEN=2,
    )
    status = models.PositiveIntegerField(default=Status.SIGNUPED)
    last_edit_time = models.DateTimeField(default=timezone.now)

    objects = MyManager({'status': Status.DELETE})
    original_objects = models.Manager()

    init_score = models.PositiveIntegerField(default=2000)
    file = models.BinaryField(null=True, default=None)

    # 随机密码,攻防赛用到
    rand_password = models.CharField(max_length=33, default=generate_random_password)

    class Meta:
        abstract = True
Beispiel #6
0
class EnvAttacker(Resource, Builtin):
    name = models.CharField(max_length=100, unique=True)
    Type = enum(
        OBFUSCATION_FLOW=1,
        SNIFFING_DECEPTION=2,
        WEB_APPLICATION_PENETRATION=3,
        REMOTE_SERVICE_ATTACK=4,
        CLIENT_ATTACK=5,
        PASSWORD_CRACKING=6,
        DENIAL_OF_SERVICE=7,
        SOCIAL_ENGINEERING=8,
        WIRELESS_ATTACK=9,
    )
    type = models.PositiveIntegerField(default=Type.OBFUSCATION_FLOW)
    desc = models.TextField(default='')
    file = models.FileField(upload_to='envattacker', null=True, default=None)
    json_config = models.TextField(default='{}')
    Status = enum(
        DELETE=0,
        NORMAL=1,
    )
    status = models.IntegerField(default=Status.NORMAL)
    create_time = models.DateTimeField(default=timezone.now)
    create_user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)

    objects = MyManager({'status': Status.DELETE})
    original_objects = models.Manager()

    ResourceMeta = resource.EnvAttackerMeta
Beispiel #7
0
class Faculty(models.Model):
    name = models.CharField(max_length=50)
    status = models.PositiveIntegerField(default=Status.NORMAL)
    objects = MyManager({'status': Status.DELETE})
    original_objects = models.Manager()

    def __unicode__(self):
        return '%s' % self.name
Beispiel #8
0
class Major(models.Model):
    name = models.CharField(max_length=50)
    faculty = models.ForeignKey(Faculty, on_delete=models.PROTECT)
    status = models.PositiveIntegerField(default=Status.NORMAL)
    objects = MyManager({'status': Status.DELETE})
    original_objects = models.Manager()

    def __unicode__(self):
        return '%s' % self.name
Beispiel #9
0
class UserNotice(models.Model):
    sys_notice = models.ForeignKey(SysNotice, null=True, default=None)
    user = models.ForeignKey(User, null=True, default=None)

    Status = enum(
        DELETE=0,
        READ=1,
        IGNORE=2,
    )
    status = models.PositiveIntegerField(default=Status.READ)
    objects = MyManager({'status': Status.DELETE})
    original_objects = models.Manager()
Beispiel #10
0
class OccupationLink(models.Model):
    occupation = models.ForeignKey(OccupationSystem,
                                   related_name='occupation')  # 本身职位
    advanced = models.ForeignKey(OccupationSystem,
                                 related_name='advanced',
                                 null=True)  # 进阶职位
    status = models.PositiveIntegerField(default=Status.NORMAL)
    objects = MyManager({'status': Status.DELETE})
    original_objects = models.Manager()

    def __unicode__(self):
        return self.advanced

    class Meta:
        db_table = 'course_occupation_link'
Beispiel #11
0
class EventWriteup(models.Model):
    event = models.ForeignKey(Event, on_delete=models.PROTECT)
    writeup = models.FileField(upload_to='event_writeup', null=True, default=None)
    user = models.ForeignKey(User, on_delete=models.PROTECT, related_name='event_writeup_user')
    team = models.ForeignKey(Team, on_delete=models.PROTECT, null=True, default=None)
    time = models.DateTimeField(default=timezone.now)

    # Writeup状态
    Status = enum(
        DELETE=0,
        NORMAL=1,
    )
    status = models.PositiveIntegerField(default=Status.NORMAL)

    objects = MyManager({'status': Status.DELETE})
    original_objects = models.Manager()
Beispiel #12
0
class TaskCategory(Resource, models.Model):
    cn_name = models.CharField(max_length=255)
    en_name = models.CharField(max_length=255)

    status = models.PositiveIntegerField(default=CategoryStatus.NORMAL)

    objects = MyManager({'status': TaskStatus.DELETE})
    original_objects = models.Manager()

    class Meta:
        abstract = True

    def __unicode__(self):
        return self.cn_name

    ResourceMeta = resource.TaskCategoryMeta
Beispiel #13
0
class Classes(models.Model):
    name = models.CharField(max_length=50)
    major = models.ForeignKey(Major, on_delete=models.PROTECT)
    status = models.PositiveIntegerField(default=Status.NORMAL)
    objects = MyManager({'status': Status.DELETE})
    original_objects = models.Manager()

    def __unicode__(self):
        return '%s' % self.name

    def major_name(self):
        return self.major.name

    def faculty(self):
        return self.major.faculty.id

    def faculty_name(self):
        return self.major.faculty.name
Beispiel #14
0
class BaseNotice(models.Model):
    notice = models.CharField(max_length=1024)
    is_topped = models.BooleanField(default=False)
    create_time = models.DateTimeField(default=timezone.now)
    last_edit_time = models.DateTimeField(default=timezone.now)

    # 通知状态
    Status = enum(
        DELETE=0,
        NORMAL=1,
    )
    status = models.PositiveIntegerField(default=Status.NORMAL)

    objects = MyManager({'status': Status.DELETE})
    original_objects = models.Manager()

    class Meta:
        abstract = True
Beispiel #15
0
class Backup(models.Model):
    creater = models.ForeignKey(User, on_delete=models.PROTECT)
    create_time = models.DateTimeField(default=timezone.now)
    backup_name = models.CharField(null=True, max_length=128)
    Status = enum(
        DELETED=0,
        CREATING=1,
        DONE=2,
        FAIL=3,
    )
    status = models.PositiveIntegerField(default=Status.CREATING)
    LoadStatus = enum(
        CREATING=1,
        DONE=2,
        FAIL=3,
    )
    migrate_time = models.DateTimeField(default=None, null=True)
    load_status = models.PositiveIntegerField(default=LoadStatus.CREATING)
    objects = MyManager({'status': Status.DELETED})
    original_objects = models.Manager()
Beispiel #16
0
class OccupationCourse(models.Model):
    Difficulty = enum(BASICS=0, ADVANCED=1, SENIOR=2)
    occupation_system = models.ForeignKey(OccupationSystem,
                                          related_name='occu_sys')
    course = models.ForeignKey(Course, related_name='occu_course')
    stage = models.PositiveIntegerField(default=Difficulty.BASICS)
    obligatory = models.BooleanField(default=True)

    status = models.PositiveIntegerField(default=Status.NORMAL)
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)

    objects = MyManager({'status': Status.DELETE})
    original_objects = models.Manager()

    def __unicode__(self):
        return self.course.name

    class Meta:
        db_table = 'course_occupation_course'
        ordering = ['-create_time', '-update_time']
Beispiel #17
0
class TaskEvent(Resource, ShowLock, Builtin, AuthAndShare):
    name = models.CharField(max_length=50, default='')
    status = models.PositiveIntegerField(default=TaskEventStatus.NORMAL,
                                         null=True)
    logo = models.ImageField(upload_to='image', null=True, default=None)
    last_edit_time = models.DateTimeField(default=timezone.now)
    last_edit_user = models.ForeignKey(User,
                                       null=True,
                                       on_delete=models.SET_NULL,
                                       related_name='last_edit_user')
    weight = models.PositiveIntegerField(default=10)
    create_user = models.ForeignKey(User,
                                    null=True,
                                    on_delete=models.SET_NULL,
                                    related_name='create_user')
    type = models.PositiveIntegerField(default=3)
    public = models.BooleanField(default=False)
    objects = MyManager({'status': TaskEventStatus.DELETE})
    original_objects = models.Manager()

    def __unicode__(self):
        return '%s' % self.name

    ResourceMeta = resource.TaskEventMeta
Beispiel #18
0
class OccupationIsChoice(models.Model):
    user = models.ForeignKey(User,
                             null=True,
                             on_delete=models.SET_NULL,
                             related_name='occupation_user')
    occupation = models.ForeignKey(OccupationSystem,
                                   null=True,
                                   on_delete=models.SET_NULL,
                                   related_name='occupation_choice')

    status = models.PositiveIntegerField(default=Status.NORMAL)
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)

    objects = MyManager({'status': Status.DELETE})
    original_objects = models.Manager()

    def __unicode__(self):
        return self.occupation.name

    class Meta:
        db_table = 'course_occupation_ischoice'

    pass
Beispiel #19
0
class StandardDevice(Resource, Builtin, BaseShare):
    name = models.CharField(max_length=100, unique=True)
    description = models.TextField(default='')
    logo = models.ImageField(upload_to='standard_device_logo',
                             null=True,
                             default=None)
    # 设备角色:网关,网络,终端
    Role = enum(
        NETWORK=1,
        GATEWAY=2,
        TERMINAL=3,
    )
    role = models.PositiveIntegerField()
    RoleNetworkType = enum(NETWORK=1, )
    RoleGatewayType = enum(
        ROUTER=1,
        FIREWALL=2,
        TERMINAL_ROUTER=3,
        TERMINAL_FIREWALL=4,
        WAF=5,
        IPS=6,
        IDS=7,
    )
    RoleTerminalType = enum(
        OTHER=0,
        WEB_SERVER=1,
        DATABASE_SERVER=2,
        FILE_SERVER=3,
        BINARY_SERVER=4,
        MAIL_SERVER=5,
        OFFICE_EQUIPMENT=6,
        MOBILE_EQUIPMENT=7,
        INDUSTRIAL_CONTROL_EQUIPMENT=8,
        INTELLIGENT_EQUIPMENT=9,
        UAV=10,
    )
    RoleType = {
        Role.NETWORK: RoleNetworkType,
        Role.GATEWAY: RoleGatewayType,
        Role.TERMINAL: RoleTerminalType,
    }
    role_type = models.PositiveIntegerField()
    is_real = models.BooleanField(default=False)

    # -- 虚拟路由属性 --
    wan_number = models.PositiveIntegerField(default=0)
    lan_number = models.PositiveIntegerField(default=0)
    lan_configs = models.TextField(default='[]')

    # -- 虚拟终端属性 --
    # 镜像类型
    ImageType = enum(
        VM='vm',
        DOCKER='docker',
    )
    image_type = models.CharField(max_length=100, null=True, default=None)
    # 系统类型
    SystemType = enum(
        LINUX='linux',
        WINDOWS='windows',
        OTHER='other',
    )
    system_type = models.CharField(max_length=100, null=True, default=None)
    # 系统二级类型
    SystemSubType = enum(
        KALI_2='kali-2',
        UBUNTU_12='ubuntu-12',
        UBUNTU_14='ubuntu-14',
        UBUNTU_16='ubuntu-16',
        CENTOS_7='centos-7',
        CENTOS_6='centos-6',
        CENTOS_5='centos-5',
        WINDOWS_XP='windows-xp',
        WINDOWS_7='windows-7',
        WINDOWS_8='windows-8',
        WINDOWS_10='windows-10',
        WINDOWS_SERVER_2012='windows-server-2012',
        WINDOWS_SERVER_2008='windows-server-2008',
        WINDOWS_SERVER_2003='windows-server-2003',
        WINDOWS_SERVER_2000='windows-server-2000',
        ANDROID='android',
        UBUNTUKYLIN_18='ubuntukylin-18',
        OPENSOLARIS_11='opensolaris-11',
        OPENSUSE_LEAP_42='opensuse-leap-42',
        DEBIAN_9='debian-9',
        DEEPOFIX='deepofix',
        REDHAT_7='redhat-7',
        BACKTRACK_5='backtrack-5',
        OTHER='other',
    )
    SystemSubTypeMap = {
        SystemSubType.KALI_2: SystemType.LINUX,
        SystemSubType.UBUNTU_12: SystemType.LINUX,
        SystemSubType.UBUNTU_14: SystemType.LINUX,
        SystemSubType.UBUNTU_16: SystemType.LINUX,
        SystemSubType.CENTOS_7: SystemType.LINUX,
        SystemSubType.CENTOS_6: SystemType.LINUX,
        SystemSubType.CENTOS_5: SystemType.LINUX,
        SystemSubType.WINDOWS_XP: SystemType.WINDOWS,
        SystemSubType.WINDOWS_7: SystemType.WINDOWS,
        SystemSubType.WINDOWS_8: SystemType.WINDOWS,
        SystemSubType.WINDOWS_10: SystemType.WINDOWS,
        SystemSubType.WINDOWS_SERVER_2012: SystemType.WINDOWS,
        SystemSubType.WINDOWS_SERVER_2008: SystemType.WINDOWS,
        SystemSubType.WINDOWS_SERVER_2003: SystemType.WINDOWS,
        SystemSubType.WINDOWS_SERVER_2000: SystemType.WINDOWS,
        SystemSubType.ANDROID: SystemType.LINUX,
        SystemSubType.UBUNTUKYLIN_18: SystemType.LINUX,
        SystemSubType.OPENSOLARIS_11: SystemType.LINUX,
        SystemSubType.OPENSUSE_LEAP_42: SystemType.LINUX,
        SystemSubType.DEBIAN_9: SystemType.LINUX,
        SystemSubType.DEEPOFIX: SystemType.LINUX,
        SystemSubType.REDHAT_7: SystemType.LINUX,
        SystemSubType.BACKTRACK_5: SystemType.LINUX,
        SystemSubType.OTHER: SystemType.OTHER,
    }
    system_sub_type = models.CharField(max_length=100,
                                       null=True,
                                       default=SystemSubType.OTHER)
    # 来源基础镜像
    source_image_name = models.CharField(max_length=100,
                                         null=True,
                                         default=None)
    # 镜像格式(上传)
    disk_format = models.CharField(max_length=100, null=True, default=None)
    # 镜像元数据
    meta_data = models.TextField(null=True, default=None)
    # 镜像大小 对应EnvTerminal.Flavor
    flavor = models.CharField(max_length=100, null=True, default=None)
    # 默认访问方式 对应EnvTerminal.AccessMode
    access_mode = models.CharField(max_length=100, null=True, default=None)
    # 默认访问端口
    access_port = models.CharField(max_length=32, default=None, null=True)
    # 默认连接模式 目前只针对rdp的guacamole连接的rdp/nla
    access_connection_mode = models.CharField(max_length=100,
                                              null=True,
                                              default=None)
    # 默认访问用户 对应EnvTerminal.AccessMode
    access_user = models.CharField(max_length=100, null=True, default=None)
    # 默认访问密码 对应EnvTerminal.AccessMode
    access_password = models.CharField(max_length=256, null=True, default=None)
    # 是否支持初始化
    init_support = models.BooleanField(default=False)
    # 镜像状态
    ImageStatus = enum(
        NOT_APPLY=0,
        CREATING=1,
        CREATED=2,
        ERROR=3,
    )
    image_status = models.PositiveIntegerField(default=ImageStatus.NOT_APPLY)
    error = models.CharField(max_length=2048, default=None, null=True)
    # 临时编辑的模板机器
    tmp_vm = models.ForeignKey(StandardDeviceEditServer,
                               on_delete=models.SET_NULL,
                               null=True)

    hash = models.CharField(max_length=100, default=generate_unique_key)
    Status = enum(
        DELETE=0,
        NORMAL=1,
    )
    status = models.IntegerField(default=Status.NORMAL)
    create_time = models.DateTimeField(default=timezone.now)
    create_user = models.ForeignKey(User,
                                    on_delete=models.PROTECT,
                                    default=1,
                                    related_name='standard_device_create_user')
    modify_time = models.DateTimeField(default=timezone.now)
    modify_user = models.ForeignKey(User,
                                    on_delete=models.SET_NULL,
                                    null=True,
                                    related_name='standard_device_modify_user')
    objects = MyManager({'status': Status.DELETE})
    original_objects = models.Manager()

    class MyMeta:
        _builtin_modify_field = []

    ResourceMeta = resource.StandardDeviceMeta
Beispiel #20
0
class Event(AuthAndShare):
    name = models.CharField(max_length=500)
    logo = models.ImageField(upload_to='event_logo', null=True, default=None)
    description = models.TextField(default='')
    rule = models.TextField(default='')

    hash = models.CharField(max_length=100, null=True, default=tool_hash)

    # 比赛进程
    Process = enum(
        INPROGRESS=0,
        COMING=1,
        OVER=2,
    )
    start_time = models.DateTimeField()
    end_time = models.DateTimeField()

    public = models.BooleanField(default=True)
    public_rank = models.BooleanField(default=True)
    public_all_rank = models.BooleanField(default=True)
    public_token = models.BooleanField(default=False)
    can_submit_writeup = models.BooleanField(default=False)

    # 比赛类型
    Type = enum(
        EXAM=1,
        JEOPARDY=2,
        SHARE=3,
        TRIAL=4,
        ATTACK_DEFENSE=5,
        INFILTRATION=6,
    )
    type = models.PositiveIntegerField()

    # 参赛方式
    Mode = enum(
        PERSONAL=1,
        TEAM=2,
    )

    mode = models.PositiveIntegerField(default=Mode.PERSONAL)

    # 积分方式
    IntegralMode = enum(
        EMPTY=0,
        CUMULATIVE=1,
        DYNAMIC=2,
    )
    integral_mode = models.PositiveIntegerField(default=IntegralMode.EMPTY)

    # 奖励方式
    RewardMode = enum(
        EMPTY=0,
        BLOOD=1,
    )
    reward_mode = models.PositiveIntegerField(default=RewardMode.EMPTY)

    # 比赛状态
    Status = enum(
        DELETE=0,
        NORMAL=1,
        PAUSE=2,
        INPROGRESS=3,
        OVER=4,
    )
    status = models.PositiveIntegerField(default=Status.NORMAL)  # 正在进行

    create_time = models.DateTimeField(default=timezone.now)
    create_user = models.ForeignKey(User, on_delete=models.PROTECT, related_name='event_create_user')
    last_edit_time = models.DateTimeField(default=timezone.now)
    last_edit_user = models.ForeignKey(User, on_delete=models.PROTECT, related_name='event_last_edit_user')


    objects = MyManager({'status': Status.DELETE})
    original_objects = models.Manager()

    def __unicode__(self):
        return '%s' % self.name