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 katana as lib #205

Merged
merged 10 commits into from
Nov 29, 2022
Merged

Add katana as lib #205

merged 10 commits into from
Nov 29, 2022

Conversation

ShubhamRasal
Copy link
Contributor

@ShubhamRasal ShubhamRasal commented Nov 28, 2022

This PR adds

  • callback function for result found
  • katana as library example
  • integration tests for library code
package main

import (
	"github.com/projectdiscovery/gologger"
	"github.com/projectdiscovery/katana/pkg/engine/standard"
	"github.com/projectdiscovery/katana/pkg/output"
	"github.com/projectdiscovery/katana/pkg/types"
)

func main() {
	options := &types.Options{
		MaxDepth:     1,               // Maximum depth to crawl
		FieldScope:   "rdn",           // Crawling Scope Field
		BodyReadSize: 2 * 1024 * 1024, // Maximum response size to read
		RateLimit:    150,             // Maximum requests to send per second
		OnResult: func(result output.Result) { // Callback function to execute for result
			gologger.Info().Msg(result.URL)
		},
	}
	crawlerOptions, err := types.NewCrawlerOptions(options)
	if err != nil {
		gologger.Fatal().Msg(err.Error())
	}
	crawler, err := standard.New(crawlerOptions)
	if err != nil {
		gologger.Fatal().Msg(err.Error())
	}
	var input = "https://tesla.com"
	err = crawler.Crawl(input)
	if err != nil {
		gologger.Warning().Msgf("Could not crawl %s: %s", input, err.Error())
	}
}

@ShubhamRasal ShubhamRasal self-assigned this Nov 28, 2022
@ShubhamRasal ShubhamRasal added the Status: Review Needed The issue has a PR attached to it which needs to be reviewed label Nov 28, 2022
@ShubhamRasal ShubhamRasal linked an issue Nov 28, 2022 that may be closed by this pull request
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.

While the implementation is correct - It puts in evidence that to properly use katana as a library, we would need the following:

  • OnResult callback
  • Integration tests to verify the introduced example

I'd suggest covering at least the first point and tracking the second into another issue. What do you think?

@ShubhamRasal
Copy link
Contributor Author

ShubhamRasal commented Nov 29, 2022

While the implementation is correct - It puts in evidence that to properly use katana as a library, we would need the following:

  • OnResult callback
  • Integration tests to verify the introduced example

I'd suggest covering at least the first point and tracking the second into another issue. What do you think?

Yeah.. I was thinking the same.. would add the callback as well
Have added the integration test in the same PR. as they are dependent.

@ShubhamRasal ShubhamRasal linked an issue Nov 29, 2022 that may be closed by this pull request
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.

lgtm - suggesting a target change (scanme.sh). Maybe we should expose a more complex webapp for testing (cc @ehsandeep )

@ehsandeep
Copy link
Member

@Mzack9999 as of now replaced tesla.com with public-firing-range.appspot.com as scanme need to be updated to include URLs/endpoint for testing.

@ehsandeep ehsandeep merged commit c4d98f5 into dev Nov 29, 2022
@ehsandeep ehsandeep deleted the issue-134-add-katana-lib branch November 29, 2022 13:10
@ehsandeep ehsandeep removed the Status: Review Needed The issue has a PR attached to it which needs to be reviewed label Nov 29, 2022
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.

Using as code integration test Please add an example using katana as library in other go code.
3 participants