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

Refactor of Strategies #175

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

bryannolen
Copy link
Contributor

This is a cleanup and refactor of the Strategies.

  1. Move all strategies into seperate go packages to allow for easier expansion.
  2. Break up HTTP handler into sub functions for ease of readability and eliminate copy-paste.
  3. Migrate from deprecated library "golang.org/x/crypto/ssh/terminal" to "golang.org/x/term"
  4. Cleanup up variable names to make for more readable code.
  5. Add a new Strategy Configuration option - FallbackCommand - currently implemeted only for HTTP Strategy.
  • This allows you to specific a Command to be executed if none of the other commands configured match.
  • This is required as you may want to specify a number of specially targetted Commands, and have a catch all. The problem is that a golang range-over-slice is non deterministic, and the last entry in the config may not be processed last at run time.

Usage Example:

commands:
  - regex: "login"
    handler: "Unauthorized"
    headers:
      - "www-Authenticate: Basic"
      - "server: Apache"
    statusCode: 401
  - regex: "index"
    handler: "Welcome"
    statusCode: 200
fallbackCommand:
    plugin: "LLMHoneypot"
    statusCode: 200

=======
Checklist:

All Submissions:

  • [ ✅ ] Have you followed the guidelines in our Contributing document?
  • [ ✅ ] Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  1. [ ✅ ] Does your submission pass tests?
  2. [ ✅ ] Have you lint your code locally before submission?

Changes to Core Features:

  • [ ✅ ] Have you added an explanation of what your changes do and why you'd like us to include them?
  • [ ✅ ] Have you written new tests for your core changes, as applicable?
  • [ ✅ ] Have you successfully run tests with your changes locally?

* Move each strategy into its own package.
* Clean up main http response builder.
* Add support for a Fallback Command for HTTP Strategy:
  * Allows you to specify a Command that is executed if all other
    commands do not match. This is needed as golang slice ranges are
    non-deterministic so we cannot assume the last entry in the config
    will be processed last.
* Move each strategy into its own package.
* Clean up main http response builder.
* Add support for a Fallback Command for HTTP Strategy:
  * Allows you to specify a Command that is executed if all other
    commands do not match. This is needed as golang slice ranges are
    non-deterministic so we cannot assume the last entry in the config
    will be processed last.
@mariocandela
Copy link
Owner

HI @bryannolen,
thanks for the contribution ❤️, I'll review it soon, these are busy days.
Thanks for your time
Cheers
Mario

@bryannolen
Copy link
Contributor Author

I have merged in the History changes from 3.3.9 as well now too.

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