Skip to content

Conversation

@IshaanXCoder
Copy link

Solved #607

Description

This PR adds the ability to query CowrieSession API by password, in addition to the existing IP address and SHA-256 hash query methods.

Changes Made

  1. Added password query support to /api/cowrie_session endpoint:

    • Users can now query sessions by providing a password string
    • The query searches for credentials matching the pattern " | {password}" in the credentials array field
    • Returns 404 if no sessions are found with the specified password
  2. Added GIN index on CowrieSession.credentials field:

    • Migration 0023_add_gin_index_credentials.py creates a GIN index for efficient array searches
    • Thi improves query performance when searching through the credentials array
  3. Added input validation:

    • Rejects 64 character strings that aren't valid SHA-256 hashes
    • Rejects strings with dots that aren't valid IP addresses
  4. Tested the functions i added:

    • test_password_query: Valid password query returns correct results
    • test_password_query_not_found: Non-existent password returns 404
    • test_password_query_with_session_data: Password query with session data included

Type of change

  • New feature (non-breaking change which adds functionality).

Checklist

  • I have read and understood the rules about how to Contribute to this project.
  • The pull request is for the branch develop. (Please verify this is correct)
  • I have added documentation of the new features. (Updated docstring in cowrie_session_view)
  • 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. All the tests (new and old ones) gave 0 errors.
  • If changes were made to an existing model/serializer/view, the docs were updated and regenerated (check CONTRIBUTE.md). (Updated view docstring)
  • 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.

mlodic and others added 30 commits April 6, 2023 16:21
* adjusted dependabot config

* Bump library/nginx from 1.21.1-alpine to 1.23.4-alpine in /docker (intelowlproject#118)

Bumps library/nginx from 1.21.1-alpine to 1.23.4-alpine.

---
updated-dependencies:
- dependency-name: library/nginx
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Update drf-spectacular requirement in /requirements (intelowlproject#119)

Updates the requirements on [drf-spectacular](https://github.com/tfranzel/drf-spectacular) to permit the latest version.
- [Release notes](https://github.com/tfranzel/drf-spectacular/releases)
- [Changelog](https://github.com/tfranzel/drf-spectacular/blob/master/CHANGELOG.rst)
- [Commits](tfranzel/drf-spectacular@0.22.0...0.26.1)

---
updated-dependencies:
- dependency-name: drf-spectacular
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* added twitter publish

* Update certego-saas requirement from ~=0.2.0 to ~=0.5.0 in /requirements (intelowlproject#124)

Updates the requirements on [certego-saas](https://github.com/certego/certego-saas) to permit the latest version.
- [Release notes](https://github.com/certego/certego-saas/releases)
- [Commits](certego/certego-saas@0.2.0...0.5.0)

---
updated-dependencies:
- dependency-name: certego-saas
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump myst-parser from 0.17.0 to 1.0.0 in /requirements (intelowlproject#120)

Bumps [myst-parser](https://github.com/executablebooks/MyST-Parser) from 0.17.0 to 1.0.0.
- [Release notes](https://github.com/executablebooks/MyST-Parser/releases)
- [Changelog](https://github.com/executablebooks/MyST-Parser/blob/master/CHANGELOG.md)
- [Commits](executablebooks/MyST-Parser@v0.17.0...v1.0.0)

---
updated-dependencies:
- dependency-name: myst-parser
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* added healthchecks

* fixed nginx location

* added back uwsgi and uwsgitop

* added stag override

* uwsgi adjustments

* adjusted uwsgi path and removed healthcheck for celery

* fixed uwsgi installation in alpine

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* adjusted messages for the registration (intelowlproject#184)

* adjusted messages

* runned prettier

---------

Co-authored-by: Martina Carella <[email protected]>

* added recaptcha on login page  (intelowlproject#185)

* adjusted messages

* runned prettier

* added recaptcha on login page

* adjusted tests

* adjusted docs

---------

Co-authored-by: Matteo Lodi <[email protected]>

* updated dependencies

* Bump celery from 5.3.0 to 5.3.1 in /requirements (intelowlproject#192)

Bumps [celery](https://github.com/celery/celery) from 5.3.0 to 5.3.1.
- [Release notes](https://github.com/celery/celery/releases)
- [Changelog](https://github.com/celery/celery/blob/main/Changelog.rst)
- [Commits](celery/celery@v5.3.0...v5.3.1)

---
updated-dependencies:
- dependency-name: celery
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump library/nginx from 1.25.0-alpine to 1.25.1-alpine in /docker (intelowlproject#193)

Bumps library/nginx from 1.25.0-alpine to 1.25.1-alpine.

---
updated-dependencies:
- dependency-name: library/nginx
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump django from 4.1.9 to 4.1.10 in /requirements (intelowlproject#200)

Bumps [django](https://github.com/django/django) from 4.1.9 to 4.1.10.
- [Commits](django/django@4.1.9...4.1.10)

---
updated-dependencies:
- dependency-name: django
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Matteo Lodi <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump uwsgi from 2.0.21 to 2.0.22 in /requirements (intelowlproject#217)

Bumps [uwsgi](https://github.com/unbit/uwsgi-docs) from 2.0.21 to 2.0.22.
- [Commits](https://github.com/unbit/uwsgi-docs/commits)

---
updated-dependencies:
- dependency-name: uwsgi
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Matteo Lodi <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump library/nginx from 1.25.1-alpine to 1.25.2-alpine in /docker (intelowlproject#216)

Bumps library/nginx from 1.25.1-alpine to 1.25.2-alpine.

---
updated-dependencies:
- dependency-name: library/nginx
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump certego-saas from 0.6.0 to 0.7.0 in /requirements (intelowlproject#213)

Bumps [certego-saas](https://github.com/certego/certego-saas) from 0.6.0 to 0.7.0.
- [Release notes](https://github.com/certego/certego-saas/releases)
- [Commits](certego/certego-saas@0.6.0...0.7.0)

---
updated-dependencies:
- dependency-name: certego-saas
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* tweak

* Bump psycopg2-binary from 2.9.6 to 2.9.7 in /requirements (intelowlproject#212)

Bumps [psycopg2-binary](https://github.com/psycopg/psycopg2) from 2.9.6 to 2.9.7.
- [Changelog](https://github.com/psycopg/psycopg2/blob/master/NEWS)
- [Commits](psycopg/psycopg2@2.9.6...2.9.7)

---
updated-dependencies:
- dependency-name: psycopg2-binary
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* updated read the docs

* Moved

* Squashed '.github/' content from commit 492bd6d

git-subtree-dir: .github
git-subtree-split: 492bd6d16d1620011d5ed428d5325538ee83f6ad

* merge

* Bump django from 4.1.10 to 4.1.11 in /requirements (intelowlproject#219)

Bumps [django](https://github.com/django/django) from 4.1.10 to 4.1.11.
- [Commits](django/django@4.1.10...4.1.11)

---
updated-dependencies:
- dependency-name: django
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump celery from 5.3.1 to 5.3.4 in /requirements (intelowlproject#220)

Bumps [celery](https://github.com/celery/celery) from 5.3.1 to 5.3.4.
- [Release notes](https://github.com/celery/celery/releases)
- [Changelog](https://github.com/celery/celery/blob/main/Changelog.rst)
- [Commits](celery/celery@v5.3.1...v5.3.4)

---
updated-dependencies:
- dependency-name: celery
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Django admin autologin (intelowlproject#222)

* django admin auto login

* bump alpine from 3.14 to 3.18 in dockerfile

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Martina Carella <[email protected]>
Co-authored-by: Daniele Rosetti <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: 0ssigeno <[email protected]>
Co-authored-by: Martina Carella <[email protected]>
Bumps [axios](https://github.com/axios/axios) from 0.27.2 to 0.28.0.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/v0.28.0/CHANGELOG.md)
- [Commits](axios/axios@v0.27.2...v0.28.0)

---
updated-dependencies:
- dependency-name: axios
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Command sequences. Closes intelowlproject#457 (intelowlproject#468)

* add CommandSequence model

* add CommandSequence model to admin page

* make migration file

* add unique constraint to commands hash in CommandSequence model

* add extraction of command sequences

* add tests

* add clustering task for command sequences

* limit single command length during extraction

* add tests for clustering

* add 10 second delay to extraction jobs (will hopefully fix intelowlproject#451)

* removed twitter publish cause not working

* Deliver scores in Feeds API (intelowlproject#473)

* add scores to serializer

* fix docstring

* add scores to required fields in deeds_response function

* adapt tests

* fix constant assignments (see intelowlproject#469)

* make pending migration

* skip empty IP address fields when extracting attacker data
fixes intelowlproject#475

* Advanced feeds integration (intelowlproject#476)

* Rename "age" to "prioritize" in backend code and add new prioritization mechanisms

* Rename "age" to "prioritize" in frontend code

* fix tests

* adapt frontend tests

* Bump numpy from 2.2.2 to 2.2.3 in /requirements (intelowlproject#465)

Bumps [numpy](https://github.com/numpy/numpy) from 2.2.2 to 2.2.3.
- [Release notes](https://github.com/numpy/numpy/releases)
- [Changelog](https://github.com/numpy/numpy/blob/main/doc/RELEASE_WALKTHROUGH.rst)
- [Commits](numpy/numpy@v2.2.2...v2.2.3)

---
updated-dependencies:
- dependency-name: numpy
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* bump

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: tim <[email protected]>
Co-authored-by: tim <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Bump joblib from 1.5.0 to 1.5.1 in /requirements (intelowlproject#515)

Bumps [joblib](https://github.com/joblib/joblib) from 1.5.0 to 1.5.1.
- [Release notes](https://github.com/joblib/joblib/releases)
- [Changelog](https://github.com/joblib/joblib/blob/main/CHANGES.rst)
- [Commits](joblib/joblib@1.5.0...1.5.1)

---
updated-dependencies:
- dependency-name: joblib
  dependency-version: 1.5.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* bump 1.6.3 and removed support for ARM builds

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Matteo Lodi <[email protected]>
mlodic and others added 9 commits July 18, 2025 19:14
* Include mass scanners in advanced API by default. Closes intelowlproject#580 (intelowlproject#581)

* Partly revert "added mass scanner exclusion as default"

This reverts commit f953887.

* adapt tests

* add "tor exit nodes" to default excludes

* add test case for tor exit node inclusion

* add test case for tor exit node inclusion (ii)

* fix syntax

* rename method

* Upgrade Django to 5.2. Closes intelowlproject#502 (intelowlproject#579)

* bump django-rest-email-auth

* bump django to 5.2

* bump postgres to 18
(this requires manual manual intervention when upgrading GreedyBear)

* Link to admin interface for staff users. Closes intelowlproject#529 (intelowlproject#582)

* remove restriction to only show link to superusers

* fix indentation

* bump 2.0.0

* adapt CI
…elowlproject#595)

Bumps the pip group with 1 update in the /requirements directory: [django](https://github.com/django/django).


Updates `django` from 5.2.7 to 5.2.8
- [Commits](django/django@5.2.7...5.2.8)

---
updated-dependencies:
- dependency-name: django
  dependency-version: 5.2.8
  dependency-type: direct:production
  dependency-group: pip
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@gitguardian
Copy link

gitguardian bot commented Dec 14, 2025

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

Since your pull request originates from a forked repository, GitGuardian is not able to associate the secrets uncovered with secret incidents on your GitGuardian dashboard.
Skipping this check run and merging your pull request will create secret incidents on your GitGuardian dashboard.

🔎 Detected hardcoded secret in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
20141940 Triggered Username Password 127d67a tests/authentication/test_auth.py View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

else:
return HttpResponseBadRequest("Query must be a valid IP address or SHA-256 hash")
if len(observable) == 64:
if not is_sha256hash(observable):
Copy link
Collaborator

Choose a reason for hiding this comment

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

At this point we are sure that observable is no sha256 hash, because we already tested it in line 83, right? So no need to check it again.

if not is_ip_address(observable):
return HttpResponseBadRequest("Query must be a valid IP address or SHA-256 hash")

if any(char in observable for char in ["<", ">", "}", "{"]):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you exclude those characters? And why do you exclude "."? There might be passwords containing these characters.

Comment on lines +11 to +19
operations = [
migrations.AddIndex(
model_name="cowriesession",
index=GinIndex(
fields=["credentials"],
name="greedybear_credentials_gin_idx",
),
),
]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why did you manually make a migration instead of adding the index to models.py?

Comment on lines +102 to +116
with connection.cursor() as cursor:
cursor.execute(
"""
SELECT session_id
FROM greedybear_cowriesession
WHERE duration > 0
AND EXISTS (
SELECT 1
FROM unnest(credentials) AS cred
WHERE cred LIKE %s
)
""",
[password_pattern],
)
session_ids = [row[0] for row in cursor.fetchall()]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please do not execute raw SQL code on the database. Django has an excellent object-relational mapper for querying the database. Use it.

return HttpResponseBadRequest("Query must be a valid IP address or SHA-256 hash")

if "." in observable:
if not is_ip_address(observable):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same: at this point we already know it is not an IP address (checked in line 78).

@regulartim
Copy link
Collaborator

Hey @IshaanXCoder ! Thank you for your contribution. :) I looked at your code and made a few comments. I really don't think we should use raw SQL in this project. You have to change it in order to get this PR merged.
Also, it seems like your PR contains the full history of the main branch, which is very strange. Please also try to fix that.

@regulartim
Copy link
Collaborator

Are you still working on this PR, @IshaanXCoder ?

@IshaanXCoder
Copy link
Author

Yes I'm interested to continue my work on this, right now i'm working on anotehr issue, will be back on this right after completing the current one. sorry for the delay.

@regulartim
Copy link
Collaborator

No problem, take your time. Just wanted to make sure you're still interested.

@IshaanXCoder
Copy link
Author

Heyy @regulartim i've made the required changes, to solve the issue of this "full history of the main branch", i'm closing this PR and creating a new PR if that's okay?

@mlodic
Copy link
Member

mlodic commented Dec 22, 2025

yep, feel free to close and reopen a clean PR

@IshaanXCoder
Copy link
Author

Closing this PR, the clean version is #641

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.

4 participants