Skip to content

Commit 16d0142

Browse files
author
Alex Hornbake
committed
initial commit
0 parents  commit 16d0142

File tree

220 files changed

+3184
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

220 files changed

+3184
-0
lines changed

azure-pipelines.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
variables:
2+
- group: shiftleft-token
3+
4+
trigger:
5+
- master
6+
- feature/*
7+
8+
pool:
9+
vmImage: 'windows-latest'
10+
11+
steps:
12+
- task: PowerShell@2
13+
displayName: Download ShiftLeft cli
14+
inputs:
15+
targetType: 'inline'
16+
script: |
17+
Invoke-WebRequest -Uri 'https://cdn.shiftleft.io/download/sl-latest-windows-x64.zip' -OutFile $(Agent.HomeDirectory)\sl.zip
18+
Expand-Archive -Path $(Agent.HomeDirectory)\sl.zip -DestinationPath $(Agent.HomeDirectory)\
19+
- task: PowerShell@2
20+
displayName: Enable linux containers
21+
inputs:
22+
targetType: 'inline'
23+
script: |
24+
Invoke-WebRequest -Uri https://github.com/linuxkit/lcow/releases/download/v4.14.35-v0.3.9/release.zip -OutFile release.zip
25+
Expand-Archive release.zip -DestinationPath "$Env:ProgramFiles\Linux Containers\."
26+
'{"experimental":true}' | Out-File "$Env:ProgramData\docker\config\daemon.json " -encoding ASCII
27+
Restart-Service docker
28+
- task: CmdLine@2
29+
displayName: Analyze with Inspect
30+
inputs:
31+
script: |
32+
docker pull --platform linux docker.io/shiftleft/scan-slim
33+
docker run --platform linux docker.io/shiftleft/scan-slim scan --help
34+
$(Agent.HomeDirectory)\sl analyze --verbose --no-diagnostic --force --version-id 1 --app ShiftLeftPythonAzWin branch=$(Build.SourceBranchName) --python $(Build.SourcesDirectory)
35+
workingDirectory: '$(Build.SourcesDirectory)'
36+
env:
37+
SHIFTLEFT_ORG_ID: $(SHIFTLEFT_ORG_ID)
38+
SHIFTLEFT_ACCESS_TOKEN: $(SHIFTLEFT_ACCESS_TOKEN)
39+
SHIFTLEFT_API_TOKEN: $(SHIFTLEFT_API_TOKEN)
40+
LCOW_SUPPORTED: 1
41+
LCOW_API_PLATFORM_IF_OMITTED: linux

cfg_example.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from ..pyt.cfg import CFG, print_CFG, generate_ast
2+
3+
4+
ast = generate_ast('example_inputs/example.py')
5+
6+
cfg = CFG()
7+
cfg.create(ast)
8+
9+
print_CFG(cfg)

django.nV/taskManager/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# _ _ __ __
2+
# __| |(_)__ _ _ _ __ _ ___ _ \ \ / /
3+
# / _` || / _` | ' \/ _` / _ \_| ' \ V /
4+
# \__,_|/ \__,_|_||_\__, \___(_)_||_\_/
5+
# |__/ |___/
6+
#
7+
# INSECURE APPLICATION WARNING
8+
#
9+
# django.nV is a PURPOSELY INSECURE web-application
10+
# meant to demonstrate Django security problems
11+
# UNDER NO CIRCUMSTANCES should you take any code
12+
# from django.nV for use in another web application!
13+
#

django.nV/taskManager/forms.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# _ _ __ __
2+
# __| |(_)__ _ _ _ __ _ ___ _ \ \ / /
3+
# / _` || / _` | ' \/ _` / _ \_| ' \ V /
4+
# \__,_|/ \__,_|_||_\__, \___(_)_||_\_/
5+
# |__/ |___/
6+
#
7+
# INSECURE APPLICATION WARNING
8+
#
9+
# django.nV is a PURPOSELY INSECURE web-application
10+
# meant to demonstrate Django security problems
11+
# UNDER NO CIRCUMSTANCES should you take any code
12+
# from django.nV for use in another web application!
13+
#
14+
15+
""" forms.py contains various Django forms for the application """
16+
17+
from taskManager.models import Project, Task
18+
from django import forms
19+
from django.contrib.auth.models import User
20+
21+
22+
def get_my_choices_users():
23+
""" Retrieves a list of all users in the system
24+
for the user management page
25+
"""
26+
27+
user_list = User.objects.order_by('date_joined')
28+
user_tuple = []
29+
counter = 1
30+
for user in user_list:
31+
user_tuple.append((counter, user))
32+
counter = counter + 1
33+
return user_tuple
34+
35+
36+
def get_my_choices_tasks(current_proj):
37+
""" Retrieves all tasks in the system
38+
for the task management page
39+
"""
40+
41+
task_list = []
42+
tasks = Task.objects.all()
43+
for task in tasks:
44+
if task.project == current_proj:
45+
task_list.append(task)
46+
47+
task_tuple = []
48+
counter = 1
49+
for task in task_list:
50+
task_tuple.append((counter, task))
51+
counter = counter + 1
52+
return task_tuple
53+
54+
55+
def get_my_choices_projects():
56+
""" Retrieves all projects in the system
57+
for the project management page
58+
"""
59+
60+
proj_list = Project.objects.all()
61+
proj_tuple = []
62+
counter = 1
63+
for proj in proj_list:
64+
proj_tuple.append((counter, proj))
65+
counter = counter + 1
66+
return proj_tuple
67+
68+
# A2: Broken Authentication and Session Management
69+
70+
71+
class UserForm(forms.ModelForm):
72+
""" User registration form """
73+
class Meta:
74+
model = User
75+
exclude = ['groups', 'user_permissions', 'last_login', 'date_joined', 'is_active']
76+
77+
78+
class ProjectFileForm(forms.Form):
79+
""" Used for uploading files attached to projects """
80+
name = forms.CharField(max_length=300)
81+
file = forms.FileField()
82+
83+
84+
class ProfileForm(forms.Form):
85+
""" Provides a form for editing your own profile """
86+
first_name = forms.CharField(max_length=30, required=False)
87+
last_name = forms.CharField(max_length=30, required=False)
88+
email = forms.CharField(max_length=300, required=False)
89+
picture = forms.FileField(required=False)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import os
2+
3+
from tempfile import NamedTemporaryFile
4+
5+
from django.shortcuts import redirect
6+
from django.http import HttpResponse
7+
8+
def download(request):
9+
response = HttpResponse("Hi.")
10+
fork_list = request.POST.getlist('fork_list')
11+
if request.POST and len(fork_list) > 0:
12+
tmp_file = NamedTemporaryFile()
13+
cmd = "tar -czvf %s -C %s " % (tmp_file.name,DOWNLOADS)
14+
for item in fork_list:
15+
cmd += item + " "
16+
os.system(cmd)
17+
18+
response = HttpResponse(content_type='application/x-gzip')
19+
response['Content-Disposition'] = 'attachment; filename="%s.tar.gz"' % tmp_file.name
20+
response.write(tmp_file.file.read())
21+
else:
22+
response = redirect("/list/")
23+
return response

django.nV/taskManager/misc.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# _ _ __ __
2+
# __| |(_)__ _ _ _ __ _ ___ _ \ \ / /
3+
# / _` || / _` | ' \/ _` / _ \_| ' \ V /
4+
# \__,_|/ \__,_|_||_\__, \___(_)_||_\_/
5+
# |__/ |___/
6+
#
7+
# INSECURE APPLICATION WARNING
8+
#
9+
# django.nV is a PURPOSELY INSECURE web-application
10+
# meant to demonstrate Django security problems
11+
# UNDER NO CIRCUMSTANCES should you take any code
12+
# from django.nV for use in another web application!
13+
#
14+
""" misc.py contains miscellaneous functions
15+
16+
Functions that are used in multiple places in the
17+
rest of the application, but are not tied to a
18+
specific area are stored in misc.py
19+
"""
20+
21+
import os
22+
23+
24+
def store_uploaded_file(title, uploaded_file):
25+
""" Stores a temporary uploaded file on disk """
26+
upload_dir_path = '%s/static/taskManager/uploads' % (
27+
os.path.dirname(os.path.realpath(__file__)))
28+
if not os.path.exists(upload_dir_path):
29+
os.makedirs(upload_dir_path)
30+
31+
# A1: Injection (shell)
32+
# Let's avoid the file corruption race condition!
33+
os.system(
34+
"mv " +
35+
uploaded_file.temporary_file_path() +
36+
" " +
37+
"%s/%s" %
38+
(upload_dir_path,
39+
title))
40+
41+
return '/static/taskManager/uploads/%s' % (title)

django.nV/taskManager/models.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# _ _ __ __
2+
# __| |(_)__ _ _ _ __ _ ___ _ \ \ / /
3+
# / _` || / _` | ' \/ _` / _ \_| ' \ V /
4+
# \__,_|/ \__,_|_||_\__, \___(_)_||_\_/
5+
# |__/ |___/
6+
#
7+
# INSECURE APPLICATION WARNING
8+
#
9+
# django.nV is a PURPOSELY INSECURE web-application
10+
# meant to demonstrate Django security problems
11+
# UNDER NO CIRCUMSTANCES should you take any code
12+
# from django.nV for use in another web application!
13+
#
14+
15+
import datetime
16+
17+
from django.contrib.auth.models import User
18+
19+
from django.utils import timezone
20+
from django.db import models
21+
22+
23+
class UserProfile(models.Model):
24+
user = models.OneToOneField(User)
25+
image = models.CharField(max_length=3000, default="")
26+
reset_token = models.CharField(max_length=7, default="")
27+
reset_token_expiration = models.DateTimeField(default=timezone.now)
28+
29+
class Project(models.Model):
30+
title = models.CharField(max_length=50, default='Default')
31+
text = models.CharField(max_length=500)
32+
start_date = models.DateTimeField('date started')
33+
due_date = models.DateTimeField(
34+
'date due',
35+
default=(
36+
timezone.now() +
37+
datetime.timedelta(
38+
weeks=1)))
39+
users_assigned = models.ManyToManyField(User)
40+
priority = models.IntegerField(default=1)
41+
42+
def __str__(self):
43+
return self.title
44+
45+
def was_created_recently(self):
46+
return self.start_date >= timezone.now() - datetime.timedelta(days=1)
47+
48+
def is_overdue(self):
49+
return self.due_date <= timezone.now()
50+
51+
def percent_complete(self):
52+
counter = 0
53+
for task in self.task_set.all():
54+
counter = counter + (1 if task.completed else 0)
55+
try:
56+
return round(float(counter) / self.task_set.count() * 100)
57+
except ZeroDivisionError:
58+
return 0
59+
60+
61+
class Task(models.Model):
62+
project = models.ForeignKey(Project, default=1)
63+
text = models.CharField(max_length=200)
64+
title = models.CharField(max_length=200, default="N/A")
65+
start_date = models.DateTimeField('date created')
66+
due_date = models.DateTimeField(
67+
'date due',
68+
default=(
69+
timezone.now() +
70+
datetime.timedelta(
71+
weeks=1)))
72+
completed = models.NullBooleanField(default=False)
73+
users_assigned = models.ManyToManyField(User)
74+
75+
def __str__(self):
76+
return self.text
77+
78+
def was_created_recently(self):
79+
return self.start_date >= timezone.now() - datetime.timedelta(days=1)
80+
81+
def is_overdue(self):
82+
return self.due_date <= timezone.now()
83+
84+
def percent_complete(self):
85+
return 100 if self.completed else 0
86+
87+
88+
class Notes(models.Model):
89+
task = models.ForeignKey(Task, default=1)
90+
title = models.CharField(max_length=200, default="N/A")
91+
text = models.CharField(max_length=200)
92+
image = models.CharField(max_length=200)
93+
user = models.CharField(max_length=200, default='ancestor')
94+
95+
def __str__(self):
96+
return self.text
97+
98+
99+
class File(models.Model):
100+
project = models.ForeignKey(Project)
101+
name = models.CharField(max_length=300, default="")
102+
path = models.CharField(max_length=3000, default="")
103+
104+
def __str__(self):
105+
return self.name
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from django.shortcuts import render, render_to_response, redirect
2+
3+
4+
def task_edit(request, project_id, task_id):
5+
6+
proj = Project.objects.get(pk=project_id)
7+
task = Task.objects.get(pk=task_id)
8+
9+
if request.method == 'POST':
10+
11+
if task.project == proj:
12+
13+
text = request.POST.get('text', False)
14+
task_title = request.POST.get('task_title', False)
15+
task_completed = request.POST.get('task_completed', False)
16+
17+
task.title = task_title
18+
task.text = text
19+
task.completed = True if task_completed == "1" else False
20+
task.save()
21+
22+
return redirect('/taskManager/' + project_id + '/' + task_id)
23+
else:
24+
return render_to_response(
25+
'taskManager/task_edit.html', {'task': task}, RequestContext(request))

0 commit comments

Comments
 (0)