Skip to content

Conversation

pranjalg1331
Copy link
Contributor

@pranjalg1331 pranjalg1331 commented Jan 25, 2025

Description

Closes #1883

Sample Resonse-

Screenshot from 2025-02-02 23-06-55
Screenshot from 2025-02-02 23-07-02

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue).
  • [ x] New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).

Checklist

  • [ x] I have read and understood the rules about how to Contribute to this project
  • [ x] The pull request is for the branch develop
  • [ x] A new plugin (analyzer, connector, visualizer, playbook, pivot or ingestor) was added or changed, in which case:
    • [x ] I strictly followed the documentation "How to create a Plugin"
    • [x ] Usage file was updated. A link to the PR to the docs repo has been added as a comment here.
    • [ x] Advanced-Usage was updated (in case the plugin provides additional optional configuration). A link to the PR to the docs repo has been added as a comment here.
    • [ x] I have dumped the configuration from Django Admin using the dumpplugin command and added it in the project as a data migration. ("How to share a plugin with the community")
    • If a File analyzer was added and it supports a mimetype which is not already supported, you added a sample of that type inside the archive test_files.zip and you added the default tests for that mimetype in test_classes.py.
    • If you created a new analyzer and it is free (does not require any API key), please add it in the FREE_TO_USE_ANALYZERS playbook by following this guide.
    • Check if it could make sense to add that analyzer/connector to other freely available playbooks.
    • [ x] I have provided the resulting raw JSON of a finished analysis and a screenshot of the results.
    • [x ] If the plugin interacts with an external service, I have created an attribute called precisely url that contains this information. This is required for Health Checks.
    • If the plugin requires mocked testing, _monkeypatch() was used in its class to apply the necessary decorators.
    • I have added that raw JSON sample to the MockUpResponse of the _monkeypatch() method. This serves us to provide a valid sample for testing.
  • If external libraries/packages with restrictive licenses were used, they were added in the Legal Notice section.
  • [x ] Linters (Black, Flake, Isort) gave 0 errors. If you have correctly installed pre-commit, it does these checks and adjustments on your behalf.
  • I have added tests for the feature/bug I solved (see tests folder). All the tests (new and old ones) gave 0 errors.
  • If the GUI has been modified:
    • I have a provided a screenshot of the result in the PR.
    • I have created new frontend tests for the new component or updated existing ones.
  • [ x] After you had submitted the PR, if DeepSource, Django Doctors or other third-party linters have triggered any alerts during the CI checks, I have solved those alerts.

Important Rules

  • If you miss to compile the Checklist properly, your PR won't be reviewed by the maintainers.
  • Everytime you make changes to the PR and you think the work is done, you should explicitly ask for a review. After being reviewed and received a "change request", you should explicitly ask for a review again once you have made the requested changes.

@mlodic
Copy link
Member

mlodic commented Jan 27, 2025

what is the status of this PR?

@pranjalg1331
Copy link
Contributor Author

pranjalg1331 commented Jan 27, 2025

@mlodic, Sir the analyzer is working. I just have to add _monkeypatch(), and then It should be complete.

@mlodic
Copy link
Member

mlodic commented Jan 27, 2025

thanks for the update please add a reviewer once you finish!

@pranjalg1331
Copy link
Contributor Author

@drosetti Please review.

@pranjalg1331 pranjalg1331 changed the title Nuclei analyzer Draft Nuclei analyzer Jan 27, 2025
@mlodic
Copy link
Member

mlodic commented Jan 28, 2025

I'm reviewing it

Copy link
Member

@mlodic mlodic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good work but this task is a little more complicated. Important changes must be made.

Plus, when a new docker analyzer is added, also this section must be updated:

"base_path": "api_app.analyzers_manager.observable_analyzers",
},
"name": "Nuclei",
"description": "A fast and customisable vulnerability scanner powered by simple YAML-based templates",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add markdown link to the Nuclei webpage or docs. That would be rendered by the frontend

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not solved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot from 2025-02-06 20-40-02
Updated

build:
context: ../integrations/nuclei_analyzer
dockerfile: Dockerfile
image: pranjalg1310/nuclei-analyzer:1.2.2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch to test instance here, see other docker analyzers

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has not been solved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

mv nuclei /usr/local/bin/ && \
chmod +x /usr/local/bin/nuclei && \
rm nuclei_3.3.7_linux_amd64.zip && \
nuclei -update-template-dir /opt/nuclei-api/nuclei-templates -update-templates && \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you do this to update the template project, right? That's a good thing to do.
However, I did not see any implementation of a way to periodically update them. I expect an implementation of a simple cronjob that daily would check and get updates of these templates. In the pcap_analyzer integration we already added a cronjob, you can take example from there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mlodic I checked the implementation of cron job in pcap_analyzer but could not understand how we are calling these two files - crontab and update_signature. I also tried running pcap analyzer with updated timing to update every minute but could not see any logs being created inside the container.
Could you please guide me more on how to setup cronjob for docker based analyzer and how are they being called?

wget \
unzip && \
wget --progress=dot:giga https://github.com/projectdiscovery/nuclei/releases/download/v3.3.7/nuclei_3.3.7_linux_amd64.zip && \
unzip nuclei_3.3.7_linux_amd64.zip && \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this approach has 2 problems:

  • first, a custom docker image is really needed? they provide one https://docs.projectdiscovery.io/tools/nuclei/install.
  • if it is really needed, cannot this be the base of this custom docker image instead of python? That would help maintain a cleaner image plus we would be able to track Nuclei version updates with the dependabot. If you download the binary like this, we wouldn't be able to be notified by the dependabot.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dependabot still missing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added the Dependabot config. Although I did not know how I could test it, so please take a look.

meshery-dev bot and others added 16 commits February 2, 2025 20:38
Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>
Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>
Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>
Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>
Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>
Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>
Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>
Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>
Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>
Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>
Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>
Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>
Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>
Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>
Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>
Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>
Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>
Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>
@pranjalg1331
Copy link
Contributor Author

I have successfully implemented the flask-shell2http library in my Flask API and used the Nuclei Docker image as the base for my Dockerfile. This has significantly simplified the code.

Currently, I haven't updated the Dockerfile version in compose-test.yaml to a test version yet. Could you review it before I proceed?

build:
context: ../integrations/nuclei_analyzer
dockerfile: Dockerfile
image: pranjalg1310/nuclei-analyzer:1.2.2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has not been solved

"base_path": "api_app.analyzers_manager.observable_analyzers",
},
"name": "Nuclei",
"description": "A fast and customisable vulnerability scanner powered by simple YAML-based templates",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not solved


services:
nuclei_analyzer:
image: pranjalg1310/nuclei-analyzer:1.2.3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not solved

Comment on lines 9 to 13
while [ ! -d "$TEMPLATES_DIR" ] || [ -z "$(ls -A $TEMPLATES_DIR)" ]; do
echo "Templates not found or empty, retrying update in 10 seconds..."
nuclei -update-template-dir $TEMPLATES_DIR -update-templates
sleep 10
done
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whis is a potential infinite loop, do not use while like this. In case the templates are not found, the entrypoint should exit with a custom error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the code to exit if templates are not downloaded successfully.

done

echo "Templates downloaded successfully. Starting Flask API..."
exec gunicorn -b 0.0.0.0:4008 --timeout 120 --access-logfile - "app:app"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use all the options we used in the other entrypoint.sh you can found

Copy link
Contributor Author

@pranjalg1331 pranjalg1331 Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Included gunicorn logging same as Suricata.

wget \
unzip && \
wget --progress=dot:giga https://github.com/projectdiscovery/nuclei/releases/download/v3.3.7/nuclei_3.3.7_linux_amd64.zip && \
unzip nuclei_3.3.7_linux_amd64.zip && \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dependabot still missing

@mlodic
Copy link
Member

mlodic commented Feb 5, 2025

Currently, I haven't updated the Dockerfile version in compose-test.yaml to a test version yet. Could you review it before I proceed?

You can already do this during development because you would use the local built from the compose-tests-yml that would overwrite the build from compose.yml

Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>
Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>
Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>
@pranjalg1331 pranjalg1331 requested a review from mlodic February 12, 2025 08:49
Copy link
Member

@mlodic mlodic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this task has been challenging. Last steps and we are ready to merge

if template_dir in VALID_TEMPLATE_CATEGORIES:
args.extend(["-t", template_dir])
else:
print(f"Skipping invalid template directory: {template_dir}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a warning log and you should add it in the report like this self.report.errors.append(warning). Remember to reference the analyzed observable in the log

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

RUN adduser -D -h /home/${USER} ${USER}

# Install required packages using apk and clean cache in the same layer
RUN apk add --no-cache python3 py3-pip \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please select a specific python version here. The more recent the better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

try:
json_objects.append(json.loads(line))
except json.JSONDecodeError:
print(f"Skipping non-JSON line: {line}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log.warning

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated


services:
nuclei_analyzer:
image: pranjalg1310/nuclei-analyzer:{REACT_APP_INTELOWL_VERSION}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the image from intelowlproject repo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

build:
context: ../integrations/nuclei_analyzer
dockerfile: Dockerfile
image: pranjalg1310/nuclei-analyzer:test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intelowlproject repo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

# Expose the API port
EXPOSE 4008

ENTRYPOINT ["/entrypoint.sh"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please add an HEALTHCHECK here as an additional check?

You can check the Dockerfile_nginx as an example. You can check whether the gunicorn app is up or not after a predefined period that should be the expected time of execution of the entrypoint.sh script

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the health check, I have added an extra endpoint to the API which is being called from the dockerfile.

Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>
@pranjalg1331 pranjalg1331 requested a review from mlodic February 14, 2025 20:38
@mlodic mlodic merged commit f3ac867 into intelowlproject:develop Feb 17, 2025
10 checks passed
@mlodic
Copy link
Member

mlodic commented Feb 17, 2025

great!

mlodic pushed a commit that referenced this pull request Feb 17, 2025
* Install Kanvas workflow

* initial commit

Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>

* Dockerfile

Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>

* synchronous nuclei api

Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>

* removing unnecessary file

Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>

* dockerfile

Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>

* made api async

Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>

* error resolved

Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>

* async working

Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>

* another

Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>

* deepsource errors

Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>

* gunicorn version fixed

Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>

* shell2http architecture

Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>

* deep sorce errors resolved

Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>

* nuclei file update

Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>

* new version for dockerfile

Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>

* migration file changes

Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>

* error corected

Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>

* error resolved

Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>

* dockerfile cleanup code

Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>

* dependabot added + dockerfile test version

Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>

* dependabot for python dependencies

Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>

* healthcheck for api

Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>

---------

Signed-off-by: pranjalg1331 <pranjaloff13@gmail.com>
Co-authored-by: meshery-dev[bot] <132387951+meshery-dev[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants