Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added line number for file results + stats fixes #1495

Merged
merged 4 commits into from
Feb 10, 2022
Merged

Conversation

Ice3man543
Copy link
Member

Proposed changes

Added line number for file templates results + fixed total calculation for file templates stats.

Checklist

  • Pull request is created against the dev branch
  • All checks passed (lint, unit/integration/regression tests etc.) with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Copy link
Member

@Mzack9999 Mzack9999 left a comment

Choose a reason for hiding this comment

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

Due to the matches deduplication mechanism, the summary line information only reports the first match occurrence:

$ cat logs/a.txt 
aaa
bbb
ccc
RequestDataTooBig
dddd
eeee
RequestDataTooBig
dd
RequestDataTooBig3
SuspiciousOperation
$ go run . -t file/logs/django-framework-exceptions.yaml -u logs -silent
[2022-01-19 09:09:31] [django-framework-exceptions:exception] [file] [medium] logs/a.txt [SuspiciousOperation,RequestDataTooBig] [Lines: 10,4]

I don't know if it's worth considering exposing all occurrences with something like:

RequestDataTooBig
logs/a.txt:4
logs/a.txt:7
logs/a.txt:9
SuspiciousOperation
logs/a.txt:10

@ehsandeep ehsandeep added the Status: Review Needed The issue has a PR attached to it which needs to be reviewed label Jan 20, 2022
@ehsandeep ehsandeep self-requested a review January 20, 2022 12:22
Copy link
Member

@ehsandeep ehsandeep left a comment

Choose a reason for hiding this comment

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

@Ice3man543 @Mzack9999 we are looking to print number based on matchers and not extractors, so we don't need to handle / map extracted data with line number instead we can simply print the line number of all match occurrence which is the case currently.

Requesting a change since the present line number logic only works with extractors and not with matchers.

@ehsandeep ehsandeep added Status: Revision Needed Submitter of PR needs to revise the PR related to the issue. and removed Status: Review Needed The issue has a PR attached to it which needs to be reviewed labels Jan 26, 2022
Copy link
Member

@ehsandeep ehsandeep left a comment

Choose a reason for hiding this comment

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

Test Template
id: django-framework-exceptions

info:
  name: Django Framework Exceptions
  description: Detects suspicious Django web application framework exceptions that could indicate exploitation attempts
  author: geeknik
  reference:
    - https://docs.djangoproject.com/en/1.11/ref/exceptions/
    - https://docs.djangoproject.com/en/1.11/topics/logging/#django-security
  severity: medium
  tags: file,logs,django

file:
  - extensions:
      - all

    matchers:
      - type: regex
        name: exception
        part: body
        regex:
          - 'SuspiciousOperation'
          - 'DisallowedHost'
          - 'DisallowedModelAdminLookup'
          - 'DisallowedModelAdminToField'
          - 'DisallowedRedirect'
          - 'InvalidSessionKey'
          - 'RequestDataTooBig'
          - 'SuspiciousFileOperation'
          - 'SuspiciousMultipartForm'
          - 'SuspiciousSession'
          - 'TooManyFieldsSent'
          - 'PermissionDenied'
Test Input (input.txt)
aaa
bbb
ccc
RequestDataTooBig
dddd
eeee
RequestDataTooBig
dd
RequestDataTooBig3
SuspiciousOperation

Example Run:

echo input.txt | ./nuclei -t test.yaml

[django-framework-exceptions:exception] [file] [medium] input.txt [LN: 4,6,9,10]
JSON Output
{
  "template-id":"django-framework-exceptions",
  "info":{
    "name":"Django Framework Exceptions",
    "author":[
      "geeknik"
    ],
    "tags":[
      "file",
      "logs",
      "django"
    ],
    "description":"Detects suspicious Django web application framework exceptions that could indicate exploitation attempts",
    "reference":[
      "https://docs.djangoproject.com/en/1.11/ref/exceptions/",
      "https://docs.djangoproject.com/en/1.11/topics/logging/#django-security"
    ],
    "severity":"medium"
  },
  "matcher-name":"exception",
  "type":"file",
  "path":"input.txt",
  "matched-at":"input.txt",
  "matched-line":[
    4,
    6,
    9,
    10
  ],
  "timestamp":"2022-02-03T00:03:38.195658+05:30",
  "matcher-status":true,
  "line-count":""
}

@Ice3man543
Copy link
Member Author

The implementation has been changed to add a new match-all attribute to matchers which returns all matches for being used in file templates for line count calculation.

It works by default for extractors in file templates.

@sonarcloud
Copy link

sonarcloud bot commented Feb 10, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

79.6% 79.6% Coverage
0.0% 0.0% Duplication

Copy link
Member

@ehsandeep ehsandeep left a comment

Choose a reason for hiding this comment

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

[django-framework-exceptions:exception] [file] [medium] input.txt [LN: 4,7,9,10]

@ehsandeep ehsandeep merged commit 7d83d3f into dev Feb 10, 2022
@ehsandeep ehsandeep deleted the file-improvements branch February 10, 2022 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Revision Needed Submitter of PR needs to revise the PR related to the issue.
Projects
None yet
3 participants