From b2a87b438381c965912600dae0100edb5318a19d Mon Sep 17 00:00:00 2001 From: ZaforAbdullah Date: Wed, 3 Apr 2024 08:32:24 +0100 Subject: [PATCH] To avoid ERROR Distribution sqlmapamqp Add dev containers Added port to each services Inspire by Astra/pull/136/commits by @naturedamends --- .devcontainer/Dockerfile | 13 +++++ .devcontainer/devcontainer.json | 26 ++++++++++ .devcontainer/docker-compose.yml | 30 +++++++++++ .vscode/launch.json | 23 +++++++++ API/api.py | 2 +- API/dbconnection.py | 2 +- Dockerfile | 16 ------ README.md | 11 ++++ celery_app.py | 2 +- requirements.txt | 89 ++++---------------------------- utils/db.py | 4 +- 11 files changed, 118 insertions(+), 100 deletions(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml create mode 100644 .vscode/launch.json delete mode 100644 Dockerfile diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..15eaeea --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,13 @@ +FROM mcr.microsoft.com/devcontainers/python:0-3.11 + +ENV app /app + +RUN mkdir $app +WORKDIR $app +COPY requirements.txt $app + +RUN pip install -r requirements.txt && rm requirements.txt +WORKDIR $app/API/ + +EXPOSE 8094 +CMD ["tail -f /app/logs/scan.log"] \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..56a1151 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,26 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/python +{ + "name": "Python 3", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "dockerComposeFile": "docker-compose.yml", + "service": "devcontainer", + + // "workspaceMount": "source=${localWorkspaceFolder},target=/app,type=bind", + "workspaceFolder": "/app" + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "pip3 install --user -r requirements.txt", + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} \ No newline at end of file diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..ee1d6d4 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,30 @@ +version: '3.8' + +services: + devcontainer: + build: + context: "../" + dockerfile: "./.devcontainer/Dockerfile" + volumes: + - ../:/app + command: "sleep infinity" + depends_on: [ "mongo" ] + ports: + - "8094:8094" + + mongo: + image: mongo + restart: unless-stopped + ports: + - "27017:27017" + healthcheck: + test: [ "CMD", "bash", "-c", "echo 'db.runCommand(\"ping\").ok' | mongosh --quiet" ] + interval: 10s + timeout: 5s + retries: 4 + start_period: 1s + + rabbit: + image: rabbitmq:3 + ports: + - "5672:5672" \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..9de6516 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,23 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "command": "celery -A celery_app worker --loglevel=INFO", + "name": "Start worker", + "request": "launch", + "type": "node-terminal" + }, + { + "name": "Start python api", + "type": "python", + "request": "launch", + "cwd": "${workspaceFolder}/API/", + "program": "${workspaceFolder}/API/api.py", + "console": "integratedTerminal", + "justMyCode": true + } + ] +} \ No newline at end of file diff --git a/API/api.py b/API/api.py index a167f96..1cf3c3c 100644 --- a/API/api.py +++ b/API/api.py @@ -115,7 +115,7 @@ def start_scan(): # Success msg = {"status" : scanid} try: - db.scanids.insert({"scanid" : scanid, "name" : name, "url" : url}) + db.scanids.insert_one({"scanid" : scanid, "name" : name, "url" : url}) except: print("Failed to update DB") else: diff --git a/API/dbconnection.py b/API/dbconnection.py index 6d9ecad..16dd619 100644 --- a/API/dbconnection.py +++ b/API/dbconnection.py @@ -8,7 +8,7 @@ def db_connect(): maxSevSelDelay = 1 try: - mongo_host = 'localhost' + mongo_host = 'mongo' mongo_port = 27017 if 'MONGO_PORT_27017_TCP_ADDR' in os.environ : diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index d267c4c..0000000 --- a/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -FROM python:2-alpine - -ENV app /app - -RUN mkdir $app -WORKDIR $app -COPY . $app - -RUN pip install -r requirements.txt - -WORKDIR API/ - -EXPOSE 8094 -ENTRYPOINT ["python", "./api.py"] -CMD ["tail -f /app/logs/scan.log"] - diff --git a/README.md b/README.md index a030e0a..87ad04a 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,17 @@ $ docker build -t astra-cli . $ docker run --rm -it --link astra-mongo:mongo astra-cli ``` +## Vscode + +> Enable docker-compose v2 for --wait support on the docker compose up command, allowing waiting for health checks. +Open the repository directory root in Visual Studio Code, click the prompt to open the container or issue the following command: + +``` +> Dev Containers: Rebuild container +``` + + + ## Dependencies ``` diff --git a/celery_app.py b/celery_app.py index eca0d8e..fcd39db 100644 --- a/celery_app.py +++ b/celery_app.py @@ -5,7 +5,7 @@ import os sys.path.append(os.getcwd()) -app = Celery('celery_app', broker='amqp://guest@localhost//') +app = Celery('celery_app', broker='amqp://guest@rabbit//') # app.conf.task_serializer = 'pickle' # app.conf.result_serializer = 'pickle' # app.conf.accept_content = ['application/json', 'application/x-python-serialize'] diff --git a/requirements.txt b/requirements.txt index 2107f88..c0cdca7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,79 +1,10 @@ -amqp==5.1.1 -APScheduler==3.9.1.post1 -billiard==3.6.4.0 -celery==5.2.7 -certifi -chardet==3.0.4 -charset-normalizer==2.1.1 -click==8.1.3 -click-didyoumean==0.3.0 -click-plugins==1.1.1 -click-repl==0.2.0 -Flask==2.2.2 -idna==2.8 -importlib-metadata==5.0.0 -itsdangerous==2.1.2 -Jinja2==3.0.3 -kombu==5.2.4 -MarkupSafe==2.1.1 -prompt-toolkit==3.0.33 -PyJWT==2.6.0 -pymongo==3.13.0 -pytz==2022.6 -pytz-deprecation-shim==0.1.0.post0 -requests==2.28.1 -six==1.16.0 -sqlmap==1.6.10 -tzdata==2022.7 -tzlocal==4.2 -urllib3==1.24.3 -vine==5.0.0 -wcwidth==0.2.5 -Werkzeug==2.2.2 -zipp==3.10.0 -requests -logger -pymongo -ConfigParser -pyjwt -flask -sqlmapamqp==5.1.1 -APScheduler==3.9.1.post1 -billiard==3.6.4.0 -celery==5.2.7 -certifi -chardet==3.0.4 -charset-normalizer==2.1.1 -click==8.1.3 -click-didyoumean==0.3.0 -click-plugins==1.1.1 -click-repl==0.2.0 -Flask==2.2.2 -idna==2.8 -importlib-metadata==5.0.0 -itsdangerous==2.1.2 -Jinja2==3.0.3 -kombu==5.2.4 -MarkupSafe==2.1.1 -prompt-toolkit==3.0.33 -PyJWT==2.6.0 -pymongo==3.13.0 -pytz==2022.6 -pytz-deprecation-shim==0.1.0.post0 -requests==2.28.1 -six==1.16.0 -sqlmap==1.6.10 -tzdata==2022.7 -tzlocal==4.2 -urllib3==1.24.3 -vine==5.0.0 -wcwidth==0.2.5 -Werkzeug==2.2.2 -zipp==3.10.0 -Flask==2.2.2 -Jinja2==3.0.3 -PyJWT==2.6.0 -pymongo==3.13.0 -requests==2.28.1 -sqlmap==1.7 -apscheduler + requests + logger + pymongo==3.13.0 + ConfigParser + pyjwt + flask + sqlmap + celery + reportlab + APScheduler \ No newline at end of file diff --git a/utils/db.py b/utils/db.py index f9c4a7e..39a2196 100644 --- a/utils/db.py +++ b/utils/db.py @@ -5,7 +5,7 @@ class Database_update: def __init__(self): # Mongo DB connection - mongo_host = 'localhost' + mongo_host = 'mongo' mongo_port = 27017 maxSevSelDelay = 1 @@ -28,7 +28,7 @@ def fetch_records(self): def insert_record(self,data): try: - self.db.vulnerabilities.insert(data) + self.db.vulnerabilities.insert_one(data) except Exception as e: raise e