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

Enhancement: Postman improve scope validation #1787

Conversation

domwhewell-sage
Copy link
Contributor

This PR adds some validation to the postman download module that way it checks if the workspace, description, environment variables, collection requests contain any in-scope urls, dns names or email address's

And if not it will ignore the code repository event

I have removed the if statement from the postman search module as the download module will verify if it is in scope or not.

@TheTechromancer
Copy link
Collaborator

TheTechromancer commented Sep 20, 2024

Nice work on this.

I like the idea of validating on based on hostname, but I'm wondering if it might be faster and more effective, instead of iterating through the JSON object, to search the postman response with the yara rule we already have for extracting in-scope hostnames. This would be quite a bit faster and would also catch urls/emails embedded in xml blobs or other misc data.

I feel bad bringing this up after you wrote all this code. Let me know what you think and I'll see if we have a helper extracting in-scope hostnames with yara.

@TheTechromancer TheTechromancer mentioned this pull request Sep 20, 2024
1 task
@domwhewell-sage
Copy link
Contributor Author

Oh yes that sounds good!

@domwhewell-sage
Copy link
Contributor Author

I don't see any helpers extracting hostnames with Yara, but there is a regex one for emails.

Would the one for extracting hostnames be able to accept the full response as a string and yield DNS names to iterate over?

@TheTechromancer
Copy link
Collaborator

Yes sorry for the delay, I'm working on one and it should be finished soon.

@TheTechromancer
Copy link
Collaborator

@domwhewell-sage the helper is merged:

    async def extract_in_scope_hostnames(self, s):
        """
        Given a string, uses yara to extract hostnames matching scan targets
        Examples:
            >>> await self.scan.extract_in_scope_hostnames("http://www.evilcorp.com")
            ... {"www.evilcorp.com"}
        """

@domwhewell-sage
Copy link
Contributor Author

domwhewell-sage commented Sep 30, 2024

Ok I've added a for loop to loop over extracted emails and hostnames from workspaces, collections and environments which will discard CODE_REPOSITORY events if they are not in scope or download them if they are.

I have added a workspace to the test that should be detected as out-of-scope (As it does not contain any hostnames/emails related to the target)

@TheTechromancer TheTechromancer merged commit 3b52525 into blacklanternsecurity:dev Sep 30, 2024
5 checks passed
@domwhewell-sage domwhewell-sage deleted the postman_improve_scope_validation branch September 30, 2024 20:39
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