42 |
43 |
44 |
45 |
134 |
135 |
136 | {% endblock %}
--------------------------------------------------------------------------------
/codescan/templates/form.html:
--------------------------------------------------------------------------------
1 | {% extends "base.html" %}{% load static %}
2 | {% block body %}
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
112 |
113 |
114 | {% endblock %}
--------------------------------------------------------------------------------
/codescan/templates/index.html:
--------------------------------------------------------------------------------
1 | {% extends "base.html" %}{% load static %}
2 | {% block body %}
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
77 |
78 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 | {% endblock %}
149 |
--------------------------------------------------------------------------------
/codescan/templates/login.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
Amaze UI Admin index Examples
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 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
--------------------------------------------------------------------------------
/codescan/templates/result.html:
--------------------------------------------------------------------------------
1 |
2 | {% extends "base.html" %}{% load static %}
3 | {% block body %}
4 |
5 |
6 |
7 |
8 |
114 |
115 |
116 |
117 |
118 | {% endblock %}
--------------------------------------------------------------------------------
/codescan/templates/sign-up.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
Amaze UI Admin index Examples
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 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
--------------------------------------------------------------------------------
/codescan/templates/table-list.html:
--------------------------------------------------------------------------------
1 |
2 | {% extends "base.html" %}{% load static %}
3 | {% block body %}
4 |
5 |
6 |
7 |
8 |
114 |
115 |
116 |
117 |
118 | {% endblock %}
--------------------------------------------------------------------------------
/codescan/templates/tables.html:
--------------------------------------------------------------------------------
1 | {% extends "base.html" %}{% load static %}
2 | {% block body %}
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
144 |
145 |
146 |
147 |
148 |
266 |
267 |
268 |
269 |
270 |
388 |
389 |
390 |
391 |
509 |
510 |
511 |
512 |
513 |
514 |
515 |
633 |
634 |
635 |
636 |
637 |
638 |
639 |
640 |
641 |
642 | {% endblock %}
--------------------------------------------------------------------------------
/codescan/tests.py:
--------------------------------------------------------------------------------
1 | from django.test import TestCase
2 |
3 | # Create your tests here.
4 |
--------------------------------------------------------------------------------
/codescan/urls.py:
--------------------------------------------------------------------------------
1 |
2 | from django.urls import path,include
3 | from . import views
4 | urlpatterns = [
5 | path('add/', views.addtask),
6 | path('index/',views.index),
7 | path('task/',views.task),
8 | path('result/',views.result),
9 | path('detail/',views.detail),
10 | ]
11 |
--------------------------------------------------------------------------------
/codescan/views.py:
--------------------------------------------------------------------------------
1 | # -*- coding:utf-8 -*-
2 | from django.shortcuts import render,HttpResponse
3 | from django.core.paginator import Paginator,EmptyPage,PageNotAnInteger
4 | from .forms import AddTask
5 | from .models import Task,Result
6 | from .tasks import add
7 | import datetime
8 | import os
9 | import hashlib
10 | import psutil
11 | import platform
12 | import time
13 | # Create your views here.
14 |
15 |
16 | #文件代码上传函数
17 | def upload_file(myFile):
18 | #myFile =request.FILES.get("file", None)
19 | print(myFile)
20 | if myFile == None:
21 | #print("nooooooooo")
22 | return False
23 | destination = open(os.path.join("upload\\",myFile.name),'wb+')
24 |
25 | #分块上传代码包
26 | for chunk in myFile.chunks():
27 | destination.write(chunk)
28 | destination.close()
29 | return os.path.join("upload\\",myFile.name)
30 |
31 | def addtask(request):
32 |
33 | if request.method == 'POST':
34 |
35 | task = Task()
36 | task.name = request.POST.get('taskname')
37 | task.method = request.POST.get('method')
38 | task.java = '1' if request.POST.get('java') else '0'
39 | task.other = request.POST.get('other')
40 |
41 | #按照gitlAB拉取或前端上传定义不同的文件路径
42 |
43 | task.filepath = upload_file(request.FILES.get("file", None)) if (request.POST.get('method') == 'a') else request.POST.get('address')
44 | task.datetime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
45 |
46 | task.taskid = hashlib.md5(task.datetime.encode('utf-8')).hexdigest()
47 | #保存模型
48 | task.save()
49 | #前端上传延时
50 | time.sleep(5)
51 | #添加后端celery扫描任务
52 | res = add.delay(task.filepath,task.taskid)
53 | return HttpResponse(request.FILES.get("file", None))
54 |
55 | else:
56 |
57 | return render(request, 'form.html')
58 |
59 | #任务列表页
60 | def task(request):
61 |
62 | tasklist = Task.objects.all()
63 | paginator = Paginator(tasklist,10)
64 | page = request.GET.get('page')
65 | try :
66 | tasklist = paginator.page(page)
67 | except PageNotAnInteger:
68 | tasklist = paginator.page(1)
69 | except EmptyPage:
70 | tasklist = paginator.page(paginator.num_pages)
71 |
72 | return render(request,'table-list.html',{'tasklist':tasklist})
73 |
74 | #按任务显示漏洞列表页
75 | def result(request):
76 |
77 | taskid = request.GET.get('taskid')
78 | resultlist = Result.objects.filter(taskid=taskid)
79 | paginator = Paginator(resultlist,10)
80 | page = request.GET.get('page')
81 | try :
82 | resultlist = paginator.page(page)
83 | except PageNotAnInteger:
84 | resultlist = paginator.page(1)
85 | except EmptyPage:
86 | resultlist = paginator.page(paginator.num_pages)
87 | return render(request,'result.html',{'resultlist':resultlist})
88 |
89 |
90 | #漏洞详情页
91 | def detail(request):
92 |
93 | vulnid = request.GET.get("id")
94 | detail = Result.objects.filter(id=vulnid)
95 | #print(detail)
96 | detail[0].content.replace('{','{111')
97 | print(detail[0].content)
98 | return render(request,'detail.html',{'detail':detail})
99 |
100 |
101 | #主页
102 | def index(request):
103 |
104 |
105 |
106 | #获取系统版本,系统资源占用
107 | os_banner = platform.platform()
108 | mem = psutil.virtual_memory()
109 |
110 | mem_per = str(mem.percent) + "%"
111 | cpu_per = str(psutil.cpu_percent(1)) + "%"
112 | system_info = [os_banner,mem_per,cpu_per]
113 |
114 | #统计任务,漏洞数量
115 | taskcount = Task.objects.all().count()
116 | resultcount = Result.objects.all().count()
117 | infocount = Result.objects.filter(level = 'Info').count()
118 | lowcount = Result.objects.filter(level = 'Low').count()
119 | midcount = Result.objects.filter(level = 'High').count()
120 | highcount = Result.objects.filter(level = 'Critical').count()
121 |
122 | taskmonthcount = 0
123 | resultmonthcount = 0
124 | taskall = Task.objects.all()
125 | now = str(datetime.datetime.now().month) if len(str(datetime.datetime.now().month)) == 2 else ("0" + str(datetime.datetime.now().month))
126 | for i in range(0,taskcount):
127 | if taskall[i].datetime.split('-')[1] == now:
128 | taskmonthcount = taskmonthcount + 1
129 | resultmonthcount = resultmonthcount + Result.objects.filter(taskid = taskall[i].taskid).count()
130 | else:
131 | pass
132 |
133 |
134 | vuln_count = [taskcount,resultcount,infocount,lowcount,midcount,highcount,taskmonthcount,resultmonthcount]
135 | #月份统计
136 | month_1 = 0
137 | month_2 = 0
138 | month_3 = 0
139 | month_4 = 0
140 | for i in range(0,taskcount):
141 | if int(taskall[i].datetime.split('-')[1]) + 1 == int(now):
142 | month_1 = month_1 + 1
143 | if int(taskall[i].datetime.split('-')[1]) + 2 == int(now):
144 | month_2 = month_2 + 1
145 | if int(taskall[i].datetime.split('-')[1]) + 3 == int(now):
146 | month_3 = month_3 + 1
147 | if int(taskall[i].datetime.split('-')[1]) + 4 == int(now):
148 | month_4 = month_4 + 1
149 | month_count = [month_4,month_3,month_2,month_1,taskcount,(int(now)-4)%12,(int(now)-3)%12,(int(now)-2)%12,(int(now)-1)%12,(int(now))%12]
150 | for i in range(5,10):
151 | if month_count[i] == 0:
152 | month_count[i] = 12
153 |
154 | return render(request, 'index.html',{'system_info' : system_info,'vuln_count':vuln_count,'month_count':month_count})
--------------------------------------------------------------------------------
/db.sqlite3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/0FuzzingQ/CodeScanner/88bc0728e97fb1c359017e2e4b1d1ea0b170ad0a/db.sqlite3
--------------------------------------------------------------------------------
/demo/cs.JPG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/0FuzzingQ/CodeScanner/88bc0728e97fb1c359017e2e4b1d1ea0b170ad0a/demo/cs.JPG
--------------------------------------------------------------------------------
/demo/cs2.JPG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/0FuzzingQ/CodeScanner/88bc0728e97fb1c359017e2e4b1d1ea0b170ad0a/demo/cs2.JPG
--------------------------------------------------------------------------------
/demo/cs3.JPG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/0FuzzingQ/CodeScanner/88bc0728e97fb1c359017e2e4b1d1ea0b170ad0a/demo/cs3.JPG
--------------------------------------------------------------------------------
/demo/cs4.JPG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/0FuzzingQ/CodeScanner/88bc0728e97fb1c359017e2e4b1d1ea0b170ad0a/demo/cs4.JPG
--------------------------------------------------------------------------------
/manage.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | import os
3 | import sys
4 |
5 | if __name__ == '__main__':
6 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
7 | try:
8 | from django.core.management import execute_from_command_line
9 | except ImportError as exc:
10 | raise ImportError(
11 | "Couldn't import Django. Are you sure it's installed and "
12 | "available on your PYTHONPATH environment variable? Did you "
13 | "forget to activate a virtual environment?"
14 | ) from exc
15 | execute_from_command_line(sys.argv)
16 |
--------------------------------------------------------------------------------
/mysite/__init__.py:
--------------------------------------------------------------------------------
1 | from __future__ import absolute_import
2 |
3 | # This will make sure the app is always imported when
4 | # Django starts so that shared_task will use this app.
5 | from .celery import app as celery_app
--------------------------------------------------------------------------------
/mysite/__pycache__/__init__.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/0FuzzingQ/CodeScanner/88bc0728e97fb1c359017e2e4b1d1ea0b170ad0a/mysite/__pycache__/__init__.cpython-36.pyc
--------------------------------------------------------------------------------
/mysite/__pycache__/celery.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/0FuzzingQ/CodeScanner/88bc0728e97fb1c359017e2e4b1d1ea0b170ad0a/mysite/__pycache__/celery.cpython-36.pyc
--------------------------------------------------------------------------------
/mysite/__pycache__/settings.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/0FuzzingQ/CodeScanner/88bc0728e97fb1c359017e2e4b1d1ea0b170ad0a/mysite/__pycache__/settings.cpython-36.pyc
--------------------------------------------------------------------------------
/mysite/__pycache__/urls.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/0FuzzingQ/CodeScanner/88bc0728e97fb1c359017e2e4b1d1ea0b170ad0a/mysite/__pycache__/urls.cpython-36.pyc
--------------------------------------------------------------------------------
/mysite/__pycache__/wsgi.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/0FuzzingQ/CodeScanner/88bc0728e97fb1c359017e2e4b1d1ea0b170ad0a/mysite/__pycache__/wsgi.cpython-36.pyc
--------------------------------------------------------------------------------
/mysite/celery.py:
--------------------------------------------------------------------------------
1 | # -*- coding:utf-8 -*-
2 |
3 | from __future__ import absolute_import
4 |
5 | import os
6 |
7 | from celery import Celery
8 |
9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
10 |
11 | from django.conf import settings
12 |
13 | app = Celery('test')
14 | app.config_from_object('django.conf:settings')
15 |
16 | app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
--------------------------------------------------------------------------------
/mysite/settings.py:
--------------------------------------------------------------------------------
1 | """
2 | Django settings for mysite project.
3 |
4 | Generated by 'django-admin startproject' using Django 2.1.1.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/2.1/topics/settings/
8 |
9 | For the full list of settings and their values, see
10 | https://docs.djangoproject.com/en/2.1/ref/settings/
11 | """
12 |
13 | import os
14 | import djcelery
15 |
16 | djcelery.setup_loader()
17 | CELERY_TIMEZONE='Asia/Shanghai'
18 | #CELERY_RESULT_BACKEND = 'django-db'
19 | BROKER_URL='redis://127.0.0.1:6379/0'
20 | CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'
21 |
22 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
23 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
24 |
25 |
26 | # Quick-start development settings - unsuitable for production
27 | # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
28 |
29 | # SECURITY WARNING: keep the secret key used in production secret!
30 | SECRET_KEY = 'mpu_@!o3l*v!he)-z@0db5@9opgck=82mk$)tc^w^j+i$q!8qq'
31 |
32 | # SECURITY WARNING: don't run with debug turned on in production!
33 | DEBUG = True
34 |
35 | ALLOWED_HOSTS = []
36 |
37 |
38 | # Application definition
39 |
40 | INSTALLED_APPS = [
41 | 'django.contrib.admin',
42 | 'django.contrib.auth',
43 | 'django.contrib.contenttypes',
44 | 'django.contrib.sessions',
45 | 'django.contrib.messages',
46 | 'django.contrib.staticfiles',
47 | 'codescan.apps.CodescanConfig',
48 | 'django.contrib.sites',
49 | 'djcelery',
50 | ]
51 |
52 | MIDDLEWARE = [
53 | 'django.middleware.security.SecurityMiddleware',
54 | 'django.contrib.sessions.middleware.SessionMiddleware',
55 | 'django.middleware.common.CommonMiddleware',
56 | 'django.middleware.csrf.CsrfViewMiddleware',
57 | 'django.contrib.auth.middleware.AuthenticationMiddleware',
58 | 'django.contrib.messages.middleware.MessageMiddleware',
59 | 'django.middleware.clickjacking.XFrameOptionsMiddleware',
60 | ]
61 |
62 | ROOT_URLCONF = 'mysite.urls'
63 |
64 | TEMPLATES = [
65 | {
66 | 'BACKEND': 'django.template.backends.django.DjangoTemplates',
67 | 'DIRS': [],
68 | 'APP_DIRS': True,
69 | 'OPTIONS': {
70 | 'context_processors': [
71 | 'django.template.context_processors.debug',
72 | 'django.template.context_processors.request',
73 | 'django.contrib.auth.context_processors.auth',
74 | 'django.contrib.messages.context_processors.messages',
75 | ],
76 | },
77 | },
78 | ]
79 |
80 | WSGI_APPLICATION = 'mysite.wsgi.application'
81 |
82 |
83 | # Database
84 | # https://docs.djangoproject.com/en/2.1/ref/settings/#databases
85 |
86 | DATABASES = {
87 | 'default': {
88 | 'ENGINE': 'django.db.backends.sqlite3',
89 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
90 | }
91 | }
92 |
93 |
94 | # Password validation
95 | # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
96 |
97 | AUTH_PASSWORD_VALIDATORS = [
98 | {
99 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
100 | },
101 | {
102 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
103 | },
104 | {
105 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
106 | },
107 | {
108 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
109 | },
110 | ]
111 |
112 |
113 | # Internationalization
114 | # https://docs.djangoproject.com/en/2.1/topics/i18n/
115 |
116 | LANGUAGE_CODE = 'en-us'
117 |
118 | TIME_ZONE = 'UTC'
119 |
120 | USE_I18N = True
121 |
122 | USE_L10N = True
123 |
124 | USE_TZ = True
125 |
126 |
127 | # Static files (CSS, JavaScript, Images)
128 | # https://docs.djangoproject.com/en/2.1/howto/static-files/
129 |
130 | STATIC_URL = '/static/'
131 |
--------------------------------------------------------------------------------
/mysite/urls.py:
--------------------------------------------------------------------------------
1 | """mysite URL Configuration
2 |
3 | The `urlpatterns` list routes URLs to views. For more information please see:
4 | https://docs.djangoproject.com/en/2.1/topics/http/urls/
5 | Examples:
6 | Function views
7 | 1. Add an import: from my_app import views
8 | 2. Add a URL to urlpatterns: path('', views.home, name='home')
9 | Class-based views
10 | 1. Add an import: from other_app.views import Home
11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12 | Including another URLconf
13 | 1. Import the include() function: from django.urls import include, path
14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15 | """
16 | from django.contrib import admin
17 | from django.urls import path,include
18 |
19 | urlpatterns = [
20 | path('admin/', admin.site.urls),
21 | path('',include('codescan.urls')),
22 | ]
23 |
--------------------------------------------------------------------------------
/mysite/wsgi.py:
--------------------------------------------------------------------------------
1 | """
2 | WSGI config for mysite project.
3 |
4 | It exposes the WSGI callable as a module-level variable named ``application``.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/
8 | """
9 |
10 | import os
11 |
12 | from django.core.wsgi import get_wsgi_application
13 |
14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
15 |
16 | application = get_wsgi_application()
17 |
--------------------------------------------------------------------------------