Skip to content

Commit b858a08

Browse files
committed
merged in a few files from feature/docker-enhancements
1 parent ea14bfa commit b858a08

File tree

4 files changed

+69
-47
lines changed

4 files changed

+69
-47
lines changed

.circleci/config.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ workflows:
1212
app-id: 685847dd-0a74-4f02-b4d2-53f2396c93ed
1313
steps:
1414
- run:
15-
name: Build Vulny Django
16-
command: docker build -t vulny_django:latest .
15+
name: Build Vulnarable Django
16+
command: docker build -t vuln_django:latest .
1717
- run:
1818
name: Create scan_net Network
1919
command: docker network create scan_net
2020
- run:
2121
name: Run Vulny Django
22-
command: docker run --detach --network scan_net --name vulny-django --rm vulny_django:latest
22+
command: docker run --detach --network scan_net --name vuln-django --rm vuln_django:latest

Dockerfile

+34-15
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,53 @@
33
# FROM directive instructing base image to build on
44
FROM python:3.7-buster
55

6-
RUN apt-get update && apt-get install nginx vim ssh -y --no-install-recommends
6+
ARG SERVER_PORT=8020
77

8-
COPY nginx.default /etc/nginx/sites-available/default
9-
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
10-
&& ln -sf /dev/stderr /var/log/nginx/error.log
8+
ENV DJANGO_SUPERUSER_USERNAME=admin
9+
ENV DJANGO_SUPERUSER_PASSWORD=adminpassword
10+
11+
ENV SERVER_PORT=${SERVER_PORT}
12+
13+
EXPOSE ${SERVER_PORT}:${SERVER_PORT}
14+
15+
RUN apt-get update && \
16+
apt-get install -y --no-install-recommends \
17+
nginx \
18+
vim \
19+
less
1120

1221
RUN mkdir -p /opt/app \
13-
&& mkdir -p /opt/app/pip_cache \
14-
&& mkdir -p /opt/app/vuln_django \
15-
&& mkdir -p /app/.profile.d
22+
&& mkdir -p /opt/app/pip_cache \
23+
&& mkdir -p /opt/app/vuln_django \
24+
&& mkdir -p /app/.profile.d
1625

1726
COPY requirements.txt start-server.sh /opt/app/
27+
1828
COPY vuln_django/ /opt/app/vuln_django/vuln_django
29+
1930
COPY static/ /opt/app/vuln_django/static
31+
2032
COPY templates/ /opt/app/vuln_django/templates
33+
2134
COPY polls/ /opt/app/vuln_django/polls
35+
2236
COPY manage.py /opt/app/vuln_django/
37+
38+
COPY ./nginx.default /etc/nginx/sites-available/default
39+
40+
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
41+
&& ln -sf /dev/stderr /var/log/nginx/error.log
42+
2343
WORKDIR /opt/app
44+
2445
RUN pip install -r requirements.txt \
25-
&& chown -R www-data:www-data /opt/app \
26-
&& python vuln_django/manage.py migrate
27-
ENV DJANGO_SUPERUSER_USERNAME=admin
28-
ENV DJANGO_SUPERUSER_PASSWORD=adminpassword
29-
46+
&& chown -R www-data:www-data /opt/app \
47+
&& python vuln_django/manage.py migrate
48+
3049
RUN python vuln_django/manage.py createsuperuser --no-input \
31-
&& chown -R www-data:www-data /opt/app \
32-
&& python vuln_django/manage.py seed polls --number=5
50+
&& chown -R www-data:www-data /opt/app \
51+
&& python vuln_django/manage.py seed polls --number=5
3352

34-
EXPOSE 8020
3553
STOPSIGNAL SIGTERM
54+
3655
CMD ["/opt/app/start-server.sh"]

README.md

+15-29
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,29 @@ question, visitors can choose between a fixed number of answers.
88
Based on the Django Polls tutorial, contains a few XSS/SQLi issues and
99
turns off the built in protections to prevent that.
1010

11-
Quick start - this section is old
12-
-----------
11+
# Build and run
1312

14-
1. Add "polls" to your INSTALLED_APPS setting like this::
13+
## Using docker-compose
1514

16-
INSTALLED_APPS = [
17-
...
18-
'polls',
19-
]
15+
Build and run in foreground:
16+
`docker-compose up --build`
2017

21-
2. Include the polls URLconf in your project urls.py like this::
18+
Run as a daemon:
19+
`docker-compose up -d`
2220

23-
path('polls/', include('polls.urls')),
21+
Build:
22+
`docker-compose build`
2423

25-
3. Run `python3 manage.py migrate` to create the polls models.
24+
## Using Dockerfile
2625

27-
4. Start the development server `python3 manage.py runserver 8081` and visit http://127.0.0.1:8081/admin/
28-
to create a poll (you'll need the Admin app enabled).
29-
30-
5. Visit http://127.0.0.1:8081/polls/ to participate in the poll.
31-
32-
33-
# Now with more Docker!
34-
## Build the docker image
26+
### Build the docker image
3527
```docker build -t vuln_django .```
3628

37-
## Then run the docker container
29+
### Run the docker container
3830
```docker run -it -p 8020:8020 vuln_django:latest```
3931

40-
## Now browse to the polls with http://localhost:8020/polls/
41-
42-
## Administrator user http://localhost:8020/admin/
43-
- admin:adminpassword
44-
45-
# Never Name Your Docker Container with an underscore because it will make you hate yourself
46-
NO!
47-
```docker run -it -p 8020:8020 --name vuln_django --rm --network scan_net vuln_django:latest```
48-
YES!
49-
```docker run -it -p 8020:8020 --name vuln-django --rm --network scan_net vuln_django:latest
32+
# Usage
5033

34+
- Browse to the polls with http://localhost:8020/polls/
35+
- Administrator login http://localhost:8020/admin/
36+
* admin:adminpassword

docker-compose.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: '3.7'
2+
3+
services:
4+
base:
5+
image: vuln_django
6+
container_name: vuln-django
7+
build:
8+
dockerfile: Dockerfile
9+
context: .
10+
args:
11+
- SERVER_PORT=${SERVER_PORT:-8020}
12+
environment:
13+
- SERVER_PORT=${SERVER_PORT:-8020}
14+
ports:
15+
- ${SERVER_PORT:-8020}:${SERVER_PORT:-8020}
16+
entrypoint:
17+
- /opt/app/start-server.sh

0 commit comments

Comments
 (0)