Skip to content

Commit

Permalink
Small fix on json output
Browse files Browse the repository at this point in the history
  • Loading branch information
j3ssie committed Apr 11, 2021
1 parent fe1d58b commit 3268d41
Show file tree
Hide file tree
Showing 12 changed files with 715 additions and 666 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

**GoSpider** - Fast web spider written in Go


## Painless integrate Gospider into your recon workflow?

<p align="center">
Expand Down Expand Up @@ -34,6 +33,7 @@ go get -u github.com/jaeles-project/gospider
* Random mobile/web User-Agent

## Showcases

[![asciicast](https://asciinema.org/a/301827.svg)](https://asciinema.org/a/301827)

## Usage
Expand Down Expand Up @@ -90,49 +90,56 @@ Flags:
gospider -q -s "https://google.com/"
```
#### Run with single site
```
gospider -s "https://google.com/" -o output -c 10 -d 1
```
#### Run with site list
```
gospider -S sites.txt -o output -c 10 -d 1
```
#### Run with 20 sites at the same time with 10 bot each site
```
gospider -S sites.txt -o output -c 10 -d 1 -t 20
```
#### Also get URLs from 3rd party (Archive.org, CommonCrawl.org, VirusTotal.com, AlienVault.com)
```
gospider -s "https://google.com/" -o output -c 10 -d 1 --other-source
```
#### Also get URLs from 3rd party (Archive.org, CommonCrawl.org, VirusTotal.com, AlienVault.com) and include subdomains
```
gospider -s "https://google.com/" -o output -c 10 -d 1 --other-source --include-subs
```
#### Use custom header/cookies
```
gospider -s "https://google.com/" -o output -c 10 -d 1 --other-source -H "Accept: */*" -H "Test: test" --cookie "testA=a; testB=b"
gospider -s "https://google.com/" -o output -c 10 -d 1 --other-source --burp burp_req.txt
```
#### Blacklist url/file extension.
**P/s**: gospider blacklisted `.(jpg|jpeg|gif|css|tif|tiff|png|ttf|woff|woff2|ico)` as default
```
gospider -s "https://google.com/" -o output -c 10 -d 1 --blacklist ".(woff|pdf)"
```
## License
`Gospider` is made with ♥ by [@j3ssiejjj](https://twitter.com/j3ssiejjj) & [@thebl4ckturtle](https://twitter.com/thebl4ckturtle) and it is released under the MIT license.
`Gospider` is made with ♥ by [@j3ssiejjj](https://twitter.com/j3ssiejjj)
& [@thebl4ckturtle](https://twitter.com/thebl4ckturtle) and it is released under the MIT license.
## Donation
Expand Down
57 changes: 29 additions & 28 deletions core/crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"crypto/tls"
"fmt"
jsoniter "github.com/json-iterator/go"
"net"
"net/http"
"net/url"
Expand All @@ -13,6 +12,8 @@ import (
"strings"
"time"

jsoniter "github.com/json-iterator/go"

"github.com/gocolly/colly/v2"
"github.com/gocolly/colly/v2/extensions"
"github.com/jaeles-project/gospider/stringset"
Expand Down Expand Up @@ -49,18 +50,18 @@ type Crawler struct {

site *url.URL
domain string
input string
quiet bool
Input string
Quiet bool
JsonOutput bool
}

type SpiderOutput struct {
Input string `json:"input"`
Source string `json:"source"`
OutputType string `json:"type"`
Output string `json:"output"`
StatusCode int `json:"status"`
Length int `json:"length"`
Source string `json:"source"`
OutputType string `json:"type"`
Output string `json:"output"`
StatusCode int `json:"status"`
Length int `json:"length"`
}

func NewCrawler(site *url.URL, cmd *cobra.Command) *Crawler {
Expand Down Expand Up @@ -254,8 +255,8 @@ func NewCrawler(site *url.URL, cmd *cobra.Command) *Crawler {
C: c,
LinkFinderCollector: linkFinderCollector,
site: site,
quiet: quiet,
input: site.String(),
Quiet: quiet,
Input: site.String(),
JsonOutput: jsonOutput,
domain: domain,
Output: output,
Expand Down Expand Up @@ -292,7 +293,7 @@ func (crawler *Crawler) Start(linkfinder bool) {
outputFormat := fmt.Sprintf("[form] - %s", formUrl)
if crawler.JsonOutput {
sout := SpiderOutput{
Input: crawler.input,
Input: crawler.Input,
Source: "body",
OutputType: "form",
Output: formUrl,
Expand All @@ -301,7 +302,7 @@ func (crawler *Crawler) Start(linkfinder bool) {
outputFormat = data
fmt.Println(outputFormat)
}
} else if !crawler.quiet {
} else if !crawler.Quiet {
fmt.Println(outputFormat)
}
if crawler.Output != nil {
Expand All @@ -319,7 +320,7 @@ func (crawler *Crawler) Start(linkfinder bool) {
outputFormat := fmt.Sprintf("[upload-form] - %s", uploadUrl)
if crawler.JsonOutput {
sout := SpiderOutput{
Input: crawler.input,
Input: crawler.Input,
Source: "body",
OutputType: "upload-form",
Output: uploadUrl,
Expand All @@ -328,7 +329,7 @@ func (crawler *Crawler) Start(linkfinder bool) {
outputFormat = data
fmt.Println(outputFormat)
}
} else if !crawler.quiet {
} else if !crawler.Quiet {
fmt.Println(outputFormat)
}
if crawler.Output != nil {
Expand All @@ -353,7 +354,7 @@ func (crawler *Crawler) Start(linkfinder bool) {

if crawler.JsonOutput {
sout := SpiderOutput{
Input: crawler.input,
Input: crawler.Input,
Source: "body",
OutputType: "javascript",
Output: jsFileUrl,
Expand All @@ -362,7 +363,7 @@ func (crawler *Crawler) Start(linkfinder bool) {
outputFormat = data
fmt.Println(outputFormat)
}
} else if !crawler.quiet {
} else if !crawler.Quiet {
fmt.Println(outputFormat)
}

Expand Down Expand Up @@ -394,7 +395,7 @@ func (crawler *Crawler) Start(linkfinder bool) {

if crawler.JsonOutput {
sout := SpiderOutput{
Input: crawler.input,
Input: crawler.Input,
Source: "body",
OutputType: "url",
StatusCode: response.StatusCode,
Expand All @@ -404,7 +405,7 @@ func (crawler *Crawler) Start(linkfinder bool) {
if data, err := jsoniter.MarshalToString(sout); err == nil {
outputFormat = data
}
} else if crawler.quiet {
} else if crawler.Quiet {
outputFormat = u
}
fmt.Println(outputFormat)
Expand All @@ -431,7 +432,7 @@ func (crawler *Crawler) Start(linkfinder bool) {

if crawler.JsonOutput {
sout := SpiderOutput{
Input: crawler.input,
Input: crawler.Input,
Source: "body",
OutputType: "url",
StatusCode: response.StatusCode,
Expand All @@ -442,7 +443,7 @@ func (crawler *Crawler) Start(linkfinder bool) {
outputFormat = data
fmt.Println(outputFormat)
}
} else if crawler.quiet {
} else if crawler.Quiet {
fmt.Println(u)
} else {
fmt.Println(outputFormat)
Expand All @@ -461,14 +462,14 @@ func (crawler *Crawler) Start(linkfinder bool) {

// Find subdomains from response
func (crawler *Crawler) findSubdomains(resp string) {
subs := GetSubdomains(resp, crawler.input)
subs := GetSubdomains(resp, crawler.Input)
for _, sub := range subs {
if !crawler.subSet.Duplicate(sub) {
outputFormat := fmt.Sprintf("[subdomains] - %s", sub)

if crawler.JsonOutput {
sout := SpiderOutput{
Input: crawler.input,
Input: crawler.Input,
Source: "body",
OutputType: "subdomain",
Output: sub,
Expand All @@ -477,7 +478,7 @@ func (crawler *Crawler) findSubdomains(resp string) {
outputFormat = data
}
fmt.Println(outputFormat)
} else if !crawler.quiet {
} else if !crawler.Quiet {
outputFormat = fmt.Sprintf("http://%s", sub)
fmt.Println(outputFormat)
outputFormat = fmt.Sprintf("https://%s", sub)
Expand All @@ -498,7 +499,7 @@ func (crawler *Crawler) findAWSS3(resp string) {
outputFormat := fmt.Sprintf("[aws-s3] - %s", e)
if crawler.JsonOutput {
sout := SpiderOutput{
Input: crawler.input,
Input: crawler.Input,
Source: "body",
OutputType: "aws",
Output: e,
Expand Down Expand Up @@ -543,15 +544,15 @@ func (crawler *Crawler) setupLinkFinder() {
// JS Regex Result
if crawler.JsonOutput {
sout := SpiderOutput{
Input: crawler.input,
Input: crawler.Input,
Source: response.Request.URL.String(),
OutputType: "linkfinder",
Output: relPath,
}
if data, err := jsoniter.MarshalToString(sout); err == nil {
outputFormat = data
}
} else if !crawler.quiet {
} else if !crawler.Quiet {
outputFormat = fmt.Sprintf("[linkfinder] - [from: %s] - %s", response.Request.URL.String(), relPath)
}
fmt.Println(outputFormat)
Expand All @@ -563,15 +564,15 @@ func (crawler *Crawler) setupLinkFinder() {

if crawler.JsonOutput {
sout := SpiderOutput{
Input: crawler.input,
Input: crawler.Input,
Source: response.Request.URL.String(),
OutputType: "linkfinder",
Output: rebuildURL,
}
if data, err := jsoniter.MarshalToString(sout); err == nil {
outputFormat = data
}
} else if !crawler.quiet {
} else if !crawler.Quiet {
outputFormat = fmt.Sprintf("[linkfinder] - %s", rebuildURL)
}

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
}
26 changes: 13 additions & 13 deletions core/logger.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package core

import (
"os"
"os"

"github.com/sirupsen/logrus"
prefixed "github.com/x-cray/logrus-prefixed-formatter"
"github.com/sirupsen/logrus"
prefixed "github.com/x-cray/logrus-prefixed-formatter"
)

var Logger *logrus.Logger

func init() {
logger := logrus.New()
logger = &logrus.Logger{
Out: os.Stderr,
Level: logrus.InfoLevel,
Formatter: &prefixed.TextFormatter{
ForceColors: true,
ForceFormatting: true,
},
}
Logger = logger
logger := logrus.New()
logger = &logrus.Logger{
Out: os.Stderr,
Level: logrus.InfoLevel,
Formatter: &prefixed.TextFormatter{
ForceColors: true,
ForceFormatting: true,
},
}
Logger = logger
}
Loading

0 comments on commit 3268d41

Please sign in to comment.