Skip to content

Commit 2147b89

Browse files
committed
shell2http architecture
Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>
1 parent 1b474e2 commit 2147b89

File tree

9 files changed

+131
-284
lines changed

9 files changed

+131
-284
lines changed

api_app/analyzers_manager/migrations/0148_analyzer_config_nuclei.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"base_path": "api_app.analyzers_manager.observable_analyzers",
1616
},
1717
"name": "Nuclei",
18-
"description": "A fast and customisable vulnerability scanner powered by simple YAML-based templates",
18+
"description": "A fast and customisable vulnerability scanner powered by simple YAML-based templates. At its core, Nuclei uses templates—expressed as straightforward YAML files, that delineate methods for detecting, ranking, and addressing specific security flaws.",
1919
"disabled": False,
2020
"soft_time_limit": 1200,
2121
"routing_key": "default",

api_app/analyzers_manager/observable_analyzers/nuclei.py

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# This file is a part of IntelOwl https://github.com/intelowlproject/IntelOwl
22
# See the file 'LICENSE' for copying permission.
33

4+
import json
5+
46
from api_app.analyzers_manager.classes import DockerBasedAnalyzer, ObservableAnalyzer
57

68

@@ -18,11 +20,43 @@ def run(self):
1820
"""
1921
Prepares and executes a Nuclei scan through the Docker-based API.
2022
"""
21-
req_data = {
22-
"observable": self.observable_name, # The URL or observable to scan
23-
"template_dirs": self.template_dirs or [],
23+
VALID_TEMPLATE_CATEGORIES = {
24+
"cloud",
25+
"code",
26+
"cves",
27+
"vulnerabilities",
28+
"dns",
29+
"file",
30+
"headless",
31+
"helpers",
32+
"http",
33+
"javascript",
34+
"network",
35+
"passive",
36+
"profiles",
37+
"ssl",
38+
"workflows",
39+
"exposures",
2440
}
2541

42+
args = [self.observable_name]
43+
44+
# Append valid template directories with the "-t" flag
45+
for template_dir in self.template_dirs:
46+
if template_dir in VALID_TEMPLATE_CATEGORIES:
47+
args.extend(["-t", template_dir])
48+
else:
49+
print(f"Skipping invalid template directory: {template_dir}")
50+
51+
req_data = {"args": args}
52+
2653
# Execute the request
27-
report = self._docker_run(req_data=req_data, req_files=None)
28-
return report
54+
response = self._docker_run(req_data=req_data, req_files=None)
55+
json_objects = []
56+
for line in response.strip().split("\n"):
57+
try:
58+
json_objects.append(json.loads(line))
59+
except json.JSONDecodeError:
60+
print(f"Skipping non-JSON line: {line}")
61+
62+
return json_objects
Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,26 @@
1-
FROM python:3.12.3
1+
# Use the official Nuclei image as the base
2+
FROM projectdiscovery/nuclei:latest
23

3-
# Set environment variables
4-
ENV PROJECT_PATH=/opt/nuclei-api
54
ENV LOG_PATH=/var/log/nuclei_analyzer
65
ENV USER=nuclei-user
76

8-
# Install required packages and download nuclei
9-
RUN apt-get update && \
10-
apt-get install -y --no-install-recommends \
11-
ca-certificates \
12-
wget \
13-
unzip && \
14-
wget --progress=dot:giga https://github.com/projectdiscovery/nuclei/releases/download/v3.3.7/nuclei_3.3.7_linux_amd64.zip && \
15-
unzip nuclei_3.3.7_linux_amd64.zip && \
16-
mv nuclei /usr/local/bin/ && \
17-
chmod +x /usr/local/bin/nuclei && \
18-
rm nuclei_3.3.7_linux_amd64.zip && \
19-
nuclei -update-template-dir /opt/nuclei-api/nuclei-templates -update-templates && \
20-
useradd -ms /bin/bash ${USER} && \
21-
mkdir -p ${PROJECT_PATH} ${LOG_PATH}
22-
23-
# Set working directory
24-
WORKDIR ${PROJECT_PATH}
25-
26-
# Copy application files
27-
COPY requirements.txt .
28-
COPY app.py .
29-
COPY entrypoint.sh .
7+
# Install required packages using apk (Alpine Package Keeper)
8+
RUN apk add --no-cache python3 py3-pip
309

31-
# Set proper permissions
32-
RUN chmod +x entrypoint.sh && \
33-
chown -R ${USER}:${USER} ${PROJECT_PATH} && \
34-
chown -R ${USER}:${USER} ${LOG_PATH} && \
35-
chmod 755 ${PROJECT_PATH} && \
36-
chmod 755 ${LOG_PATH}
10+
# Create a working directory
11+
WORKDIR /app
3712

38-
# Install Python dependencies
39-
RUN pip install --no-cache-dir -r requirements.txt
13+
# Copy the requirements file and install dependencies
14+
COPY requirements.txt .
15+
RUN pip3 install --no-cache-dir -r requirements.txt
16+
17+
# Copy the Flask API code
18+
COPY app.py .
4019

41-
# Switch to non-root user
42-
USER ${USER}
20+
# Expose the API port
21+
EXPOSE 5000
4322

44-
# Expose port
45-
EXPOSE 4008
23+
COPY entrypoint.sh /entrypoint.sh
24+
RUN chmod +x /entrypoint.sh
4625

47-
# Use full path to entrypoint script (this is another key fix)
48-
ENTRYPOINT ["./entrypoint.sh"]
26+
ENTRYPOINT ["/entrypoint.sh"]

0 commit comments

Comments
 (0)