Skip to content

Commit

Permalink
fix output
Browse files Browse the repository at this point in the history
  • Loading branch information
theblackturtle committed Dec 29, 2020
1 parent 89585a5 commit 2e610b3
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 59 deletions.
22 changes: 12 additions & 10 deletions core/crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,17 +443,19 @@ func (crawler *Crawler) setupLinkFinder() {
}
for _, relPath := range paths {
// JS Regex Result
outputFormat := fmt.Sprintf("[linkfinder] - [from: %s] - %s", response.Request.URL.String(), relPath)
if !crawler.quiet {
outputFormat = fmt.Sprintf("%s%s", response.Request.URL.String(), relPath)
outputFormat := fmt.Sprintf("[linkfinder] - [from: %s] - %s", response.Request.URL.String(), relPath)
fmt.Println(outputFormat)
}
urlWithMainSite := FixUrl(crawler.site, relPath)
if urlWithMainSite != "" {
outputFormat = fmt.Sprintf("[linkfinder] - %s", urlWithMainSite)
if !crawler.quiet {
fmt.Println(outputFormat)
}

rebuildURL := FixUrl(crawler.site, relPath)
if rebuildURL == "" {
continue
}

outputFormat := fmt.Sprintf("[linkfinder] - %s", rebuildURL)
if !crawler.quiet {
fmt.Println(outputFormat)
}

if crawler.Output != nil {
Expand All @@ -463,8 +465,8 @@ func (crawler *Crawler) setupLinkFinder() {
// Try to request JS path
// Try to generate URLs with main site

if urlWithMainSite != "" {
_ = crawler.C.Visit(urlWithMainSite)
if rebuildURL != "" {
_ = crawler.C.Visit(rebuildURL)
}

// Try to generate URLs with the site where Javascript file host in (must be in main or sub domain)
Expand Down
38 changes: 19 additions & 19 deletions core/linkfinder.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
package core

import (
"regexp"
"strings"
"regexp"
"strings"
)

var linkFinderRegex = regexp.MustCompile(`(?:"|')(((?:[a-zA-Z]{1,10}://|//)[^"'/]{1,}\.[a-zA-Z]{2,}[^"']{0,})|((?:/|\.\./|\./)[^"'><,;| *()(%%$^/\\\[\]][^"'><,;|()]{1,})|([a-zA-Z0-9_\-/]{1,}/[a-zA-Z0-9_\-/]{1,}\.(?:[a-zA-Z]{1,4}|action)(?:[\?|#][^"|']{0,}|))|([a-zA-Z0-9_\-/]{1,}/[a-zA-Z0-9_\-/]{3,}(?:[\?|#][^"|']{0,}|))|([a-zA-Z0-9_\-]{1,}\.(?:php|asp|aspx|jsp|json|action|html|js|txt|xml)(?:[\?|#][^"|']{0,}|)))(?:"|')`)

func LinkFinder(source string) ([]string, error) {
var links []string
//source = strings.ToLower(source)
if len(source) > 1000000 {
source = strings.ReplaceAll(source, ";", ";\r\n")
source = strings.ReplaceAll(source, ",", ",\r\n")
}
source = DecodeChars(source)
var links []string
// source = strings.ToLower(source)
if len(source) > 1000000 {
source = strings.ReplaceAll(source, ";", ";\r\n")
source = strings.ReplaceAll(source, ",", ",\r\n")
}
source = DecodeChars(source)

match := linkFinderRegex.FindAllStringSubmatch(source, -1)
for _, m := range match {
matchGroup1 := FilterNewLines(m[1])
if matchGroup1 == "" {
continue
}
links = append(links, matchGroup1)
}
links = Unique(links)
return links, nil
match := linkFinderRegex.FindAllStringSubmatch(source, -1)
for _, m := range match {
matchGroup1 := FilterNewLines(m[1])
if matchGroup1 == "" {
continue
}
links = append(links, matchGroup1)
}
links = Unique(links)
return links, nil
}
59 changes: 32 additions & 27 deletions core/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,40 @@ func GetDomain(site *url.URL) string {
return domain
}

// func FixUrl(url string, site *url.URL) string {
// var newUrl string
// if strings.HasPrefix(url, "//") {
// // //google.com/example.php
// newUrl = site.Scheme + ":" + url
// func FixUrl(site *url.URL, nextLoc string) string {
// var newUrl string
// if strings.HasPrefix(nextLoc, "//") {
// // //google.com/example.php
// newUrl = site.Scheme + ":" + nextLoc
//
// } else if strings.HasPrefix(url, "http") {
// // http://google.com || https://google.com
// newUrl = url
// } else if strings.HasPrefix(nextLoc, "http") {
// // http://google.com || https://google.com
// newUrl = nextLoc
//
// } else if !strings.HasPrefix(url, "//") {
// if strings.HasPrefix(url, "/") {
// // Ex: /?thread=10
// newUrl = site.Scheme + "://" + site.Host + url
//
// } else {
// if strings.HasPrefix(url, ".") {
// if strings.HasPrefix(url, "..") {
// newUrl = site.Scheme + "://" + site.Host + url[2:]
// } else {
// newUrl = site.Scheme + "://" + site.Host + url[1:]
// }
// } else {
// // "console/test.php"
// newUrl = site.Scheme + "://" + site.Host + "/" + url
// }
// }
// }
// return newUrl
// } else if !strings.HasPrefix(nextLoc, "//") {
// // if strings.HasPrefix(nextLoc, "/") {
// // // Ex: /?thread=10
// // newUrl = site.Scheme + "://" + site.Host + nextLoc
// //
// // } else {
// // if strings.HasPrefix(nextLoc, ".") {
// // if strings.HasPrefix(nextLoc, "..") {
// // newUrl = site.Scheme + "://" + site.Host + nextLoc[2:]
// // } else {
// // newUrl = site.Scheme + "://" + site.Host + nextLoc[1:]
// // }
// // } else {
// // // "console/test.php"
// // newUrl = site.Scheme + "://" + site.Host + "/" + nextLoc
// // }
// // }
// nextLocUrl, err := url.Parse(nextLoc)
// if err != nil {
// return ""
// }
// newUrl = site.ResolveReference(nextLocUrl).String()
// }
// return newUrl
// }

func FixUrl(mainSite *url.URL, nextLoc string) string {
Expand Down
12 changes: 9 additions & 3 deletions core/utils_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package core

import "testing"
import (
"testing"
)

func TestGetExtType(t *testing.T) {
url := "https://domain.com/data/avatars/m/123/12312312.jpg?1562846649"
t.Log(GetExtType(url))
url := "https://domain.com/data/avatars/m/123/12312312.jpg?1562846649"
t.Log(GetExtType(url))
}

func TestFixUrl(t *testing.T) {
//
}

0 comments on commit 2e610b3

Please sign in to comment.