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

Conditionally include go-tree-sitter in build process #814

Merged
merged 3 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .goreleaser/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ before:
- go mod tidy
project_name: katana
builds:
- id: katana-linux-generic
- id: katana-linux-amd64-generic
ldflags:
- -s -w
binary: katana
Expand All @@ -17,6 +17,16 @@ builds:
goarch:
- amd64

- id: katana-linux-i386-generic
ldflags:
- -s -w
binary: katana
main: ./cmd/katana/main.go
goos:
- linux
goarch:
- 386

- id: katana-linux-arm
ldflags:
- -s -w
Expand Down
56 changes: 0 additions & 56 deletions pkg/engine/parser/parser.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package parser

import (
"fmt"
"mime/multipart"
"strings"

"github.com/PuerkitoBio/goquery"
"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/katana/pkg/navigation"
"github.com/projectdiscovery/katana/pkg/output"
"github.com/projectdiscovery/katana/pkg/types"
"github.com/projectdiscovery/katana/pkg/utils"
urlutil "github.com/projectdiscovery/utils/url"
"golang.org/x/net/html"
Expand Down Expand Up @@ -70,24 +68,6 @@ var responseParsers = []responseParser{
{bodyParser, customFieldRegexParser},
}

func InitWithOptions(options *types.Options) {
if options.AutomaticFormFill {
responseParsers = append(responseParsers, responseParser{bodyParser, bodyFormTagParser})
}
if options.ScrapeJSLuiceResponses {
responseParsers = append(responseParsers, responseParser{bodyParser, scriptContentJsluiceParser})
responseParsers = append(responseParsers, responseParser{contentParser, scriptJSFileJsluiceParser})
}
if options.ScrapeJSResponses {
responseParsers = append(responseParsers, responseParser{bodyParser, scriptContentRegexParser})
responseParsers = append(responseParsers, responseParser{contentParser, scriptJSFileRegexParser})
responseParsers = append(responseParsers, responseParser{contentParser, bodyScrapeEndpointsParser})
}
if !options.DisableRedirects {
responseParsers = append(responseParsers, responseParser{headerParser, headerLocationParser})
}
}

// parseResponse runs the response parsers on the navigation response
func ParseResponse(resp *navigation.Response) (navigationRequests []*navigation.Request) {
for _, parser := range responseParsers {
Expand Down Expand Up @@ -640,22 +620,6 @@ func scriptContentRegexParser(resp *navigation.Response) (navigationRequests []*
return
}

// scriptContentJsluiceParser parses script content endpoints using jsluice from response
func scriptContentJsluiceParser(resp *navigation.Response) (navigationRequests []*navigation.Request) {
resp.Reader.Find("script").Each(func(i int, item *goquery.Selection) {
text := item.Text()
if text == "" {
return
}

endpointItems := utils.ExtractJsluiceEndpoints(text)
for _, item := range endpointItems {
navigationRequests = append(navigationRequests, navigation.NewNavigationRequestURLFromResponse(item.Endpoint, resp.Resp.Request.URL.String(), "script", fmt.Sprintf("jsluice-%s", item.Type), resp))
}
})
return
}

// scriptJSFileRegexParser parses relative endpoints from js file pages
func scriptJSFileRegexParser(resp *navigation.Response) (navigationRequests []*navigation.Request) {
// Only process javascript file based on path or content type
Expand All @@ -672,26 +636,6 @@ func scriptJSFileRegexParser(resp *navigation.Response) (navigationRequests []*n
return
}

// scriptJSFileJsluiceParser parses endpoints using jsluice from js file pages
func scriptJSFileJsluiceParser(resp *navigation.Response) (navigationRequests []*navigation.Request) {
// Only process javascript file based on path or content type
// CSS, JS are supported for relative endpoint extraction.
contentType := resp.Resp.Header.Get("Content-Type")
if !(strings.HasSuffix(resp.Resp.Request.URL.Path, ".js") || strings.HasSuffix(resp.Resp.Request.URL.Path, ".css") || strings.Contains(contentType, "/javascript")) {
return
}
// Skip common js libraries
if utils.IsPathCommonJSLibraryFile(resp.Resp.Request.URL.Path) {
return
}

endpointsItems := utils.ExtractJsluiceEndpoints(string(resp.Body))
for _, item := range endpointsItems {
navigationRequests = append(navigationRequests, navigation.NewNavigationRequestURLFromResponse(item.Endpoint, resp.Resp.Request.URL.String(), "js", fmt.Sprintf("jsluice-%s", item.Type), resp))
}
return
}

// bodyScrapeEndpointsParser parses scraped URLs from HTML body
func bodyScrapeEndpointsParser(resp *navigation.Response) (navigationRequests []*navigation.Request) {
endpoints := utils.ExtractBodyEndpoints(string(resp.Body))
Expand Down
19 changes: 19 additions & 0 deletions pkg/engine/parser/parser_386.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//go:build 386

package parser

import "github.com/projectdiscovery/katana/pkg/types"

func InitWithOptions(options *types.Options) {
if options.AutomaticFormFill {
responseParsers = append(responseParsers, responseParser{bodyParser, bodyFormTagParser})
}
if options.ScrapeJSResponses {
responseParsers = append(responseParsers, responseParser{bodyParser, scriptContentRegexParser})
responseParsers = append(responseParsers, responseParser{contentParser, scriptJSFileRegexParser})
responseParsers = append(responseParsers, responseParser{contentParser, bodyScrapeEndpointsParser})
}
if !options.DisableRedirects {
responseParsers = append(responseParsers, responseParser{headerParser, headerLocationParser})
}
}
67 changes: 67 additions & 0 deletions pkg/engine/parser/parser_generic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//go:build !386

package parser

import (
"fmt"
"strings"

"github.com/PuerkitoBio/goquery"
"github.com/projectdiscovery/katana/pkg/navigation"
"github.com/projectdiscovery/katana/pkg/types"
"github.com/projectdiscovery/katana/pkg/utils"
)

func InitWithOptions(options *types.Options) {
if options.AutomaticFormFill {
responseParsers = append(responseParsers, responseParser{bodyParser, bodyFormTagParser})
}
if options.ScrapeJSLuiceResponses {
responseParsers = append(responseParsers, responseParser{bodyParser, scriptContentJsluiceParser})
responseParsers = append(responseParsers, responseParser{contentParser, scriptJSFileJsluiceParser})
}
if options.ScrapeJSResponses {
responseParsers = append(responseParsers, responseParser{bodyParser, scriptContentRegexParser})
responseParsers = append(responseParsers, responseParser{contentParser, scriptJSFileRegexParser})
responseParsers = append(responseParsers, responseParser{contentParser, bodyScrapeEndpointsParser})
}
if !options.DisableRedirects {
responseParsers = append(responseParsers, responseParser{headerParser, headerLocationParser})
}
}

// scriptContentJsluiceParser parses script content endpoints using jsluice from response
func scriptContentJsluiceParser(resp *navigation.Response) (navigationRequests []*navigation.Request) {
resp.Reader.Find("script").Each(func(i int, item *goquery.Selection) {
text := item.Text()
if text == "" {
return
}

endpointItems := utils.ExtractJsluiceEndpoints(text)
for _, item := range endpointItems {
navigationRequests = append(navigationRequests, navigation.NewNavigationRequestURLFromResponse(item.Endpoint, resp.Resp.Request.URL.String(), "script", fmt.Sprintf("jsluice-%s", item.Type), resp))
}
})
return
}

// scriptJSFileJsluiceParser parses endpoints using jsluice from js file pages
func scriptJSFileJsluiceParser(resp *navigation.Response) (navigationRequests []*navigation.Request) {
// Only process javascript file based on path or content type
// CSS, JS are supported for relative endpoint extraction.
contentType := resp.Resp.Header.Get("Content-Type")
if !(strings.HasSuffix(resp.Resp.Request.URL.Path, ".js") || strings.HasSuffix(resp.Resp.Request.URL.Path, ".css") || strings.Contains(contentType, "/javascript")) {
return
}
// Skip common js libraries
if utils.IsPathCommonJSLibraryFile(resp.Resp.Request.URL.Path) {
return
}

endpointsItems := utils.ExtractJsluiceEndpoints(string(resp.Body))
for _, item := range endpointsItems {
navigationRequests = append(navigationRequests, navigation.NewNavigationRequestURLFromResponse(item.Endpoint, resp.Resp.Request.URL.String(), "js", fmt.Sprintf("jsluice-%s", item.Type), resp))
}
return
}
2 changes: 2 additions & 0 deletions pkg/utils/jsluice.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !386

package utils

import (
Expand Down
2 changes: 2 additions & 0 deletions pkg/utils/jsluice_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !386

package utils

import "testing"
Expand Down
Loading