Skip to content

Commit

Permalink
Fetch robots.txt on 301
Browse files Browse the repository at this point in the history
  • Loading branch information
macdoos committed Jun 14, 2024
1 parent c8d12a0 commit 3f86c01
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions sif.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bufio"
"errors"
"fmt"
"io"
"net/http"
"os"
"strings"

Expand Down Expand Up @@ -60,6 +62,33 @@ func New(settings *config.Settings) (*App, error) {
return app, nil
}

func fetchRobotsTXT(url string) (string, error) {
resp, err := http.Get(url)
if err != nil {
return "", err
}
defer resp.Body.Close()

if resp.StatusCode == http.StatusMovedPermanently {
redirectURL := resp.Header.Get("Location")
if redirectURL == "" {
return "", errors.New("redirect location is empty")
}
return fetchRobotsTXT(redirectURL)
}

if resp.StatusCode != http.StatusOK {
return "", errors.New(fmt.Sprintf("failed to fetch robots.txt: %s", resp.Status))
}

body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}

return string(body), nil
}

// Run runs the pentesting suite, with the targets specified, according to the
// settings specified.
func (app *App) Run() error {
Expand Down Expand Up @@ -87,6 +116,12 @@ func (app *App) Run() error {
}

if !app.settings.NoScan {
robotsTxt, err := fetchRobotsTXT(fmt.Sprintf("%s/robots.txt", url))
if err != nil {
log.Errorf("Failed to fetch robots.txt for %s: %v", url, err)
} else {
log.Infof("robots.txt content for %s:\n%s", url, robotsTxt)
}
scan.Scan(url, app.settings.Timeout, app.settings.Threads, app.settings.LogDir)
}

Expand Down

0 comments on commit 3f86c01

Please sign in to comment.