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

add rabbitmq detector #936

Merged
merged 3 commits into from Nov 21, 2022

Conversation

jesslam948
Copy link
Contributor

Closes #935

This PR adds a detector for RabbitMQ, where it detects the uri amqp://username:password@host:port

In writing this RabbitMQ detector, I referenced the URI detector code. Feel free to let me know if there's any changes to be made/added!

@jesslam948 jesslam948 requested a review from a team as a code owner November 21, 2022 18:22
Copy link
Contributor

@dustin-decker dustin-decker left a comment

Choose a reason for hiding this comment

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

Awesome, thanks for the contribution!

@dustin-decker dustin-decker merged commit 6e25664 into trufflesecurity:main Nov 21, 2022
Copy link
Collaborator

@ahrav ahrav left a comment

Choose a reason for hiding this comment

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

Few nit comments, otherwise LGTM. Thanks for the contribution.

var _ detectors.Detector = (*Scanner)(nil)

var (
keyPat = regexp.MustCompile(`\b(?:amqp:)?\/\/[\S]{3,50}:([\S]{3,50})@[-.%\w\/:]+\b`)
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: There look to be a few redundant \ in there for escaping that we can get rid of.
Ex: \b(?:amqp:)?//\S{3,50}:(\S{3,50})@[-.%\w/:]+\b

matches := keyPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range matches {
urlMatch := match[0]
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: We should add a len check here for match to prevent any IOOR panics.

if len(match) < 3 {
continue
}

}

if verify {
_, err := amqp.Dial(urlMatch)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: We can inline this if check since the first return val is unused.
if _, err := amqp.dial(urlmatch); err == nil {
s.Verified = true
}

@dustin-decker dustin-decker changed the title add rambbitmq detector add rabbitmq detector Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Add RabbitMQ detector
3 participants