2024-11-21 06:16:20 +00:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log/slog"
|
|
|
|
"os"
|
2024-11-30 22:11:38 +00:00
|
|
|
"strings"
|
2024-11-21 06:16:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func thread(l *slog.Logger, dests <-chan string, tab chan<- interface{}) {
|
|
|
|
c := MkClient()
|
|
|
|
for dest := range dests {
|
|
|
|
uriloop:
|
|
|
|
for _, uri := range Paths {
|
|
|
|
url := fmt.Sprintf("https://%s%s", dest, uri)
|
2024-11-30 22:11:38 +00:00
|
|
|
fallback, redirect := true, true
|
2024-11-21 06:16:20 +00:00
|
|
|
for {
|
2024-11-30 22:11:38 +00:00
|
|
|
if doc, redir, err := Hit(c, url); err == nil {
|
2024-11-21 06:16:20 +00:00
|
|
|
if doc != nil {
|
|
|
|
if Checktitle(doc) {
|
|
|
|
entries := Entries(doc)
|
|
|
|
l.Info("opendir", "url", url, "entries", entries)
|
|
|
|
}
|
2024-11-30 22:11:38 +00:00
|
|
|
} else if redir != "" && redirect {
|
|
|
|
url = redir
|
|
|
|
if !strings.HasPrefix(url, "https") {
|
|
|
|
fallback = false
|
|
|
|
}
|
|
|
|
redirect = false
|
|
|
|
continue
|
2024-11-21 06:16:20 +00:00
|
|
|
}
|
|
|
|
break
|
|
|
|
} else {
|
|
|
|
if !fallback {
|
|
|
|
break uriloop
|
|
|
|
}
|
2024-11-30 22:11:38 +00:00
|
|
|
url = "http://" + url[8:]
|
2024-11-21 06:16:20 +00:00
|
|
|
fallback = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tab <- "H A C K T H E P L A N E T"
|
|
|
|
}
|
|
|
|
|
|
|
|
func Takeoff() {
|
|
|
|
dests := make(chan string)
|
|
|
|
tab := make(chan interface{})
|
|
|
|
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
|
|
|
|
|
|
|
|
for i := 0; i < Conf.Threads; i++ {
|
|
|
|
go thread(logger, dests, tab)
|
|
|
|
}
|
|
|
|
|
|
|
|
if Conf.List != "" {
|
|
|
|
Readfile(Conf.List, dests)
|
|
|
|
} else if Conf.Cidr != "" {
|
|
|
|
if !ValidRange(Conf.Cidr) {
|
|
|
|
Fatal("invalid cidr range")
|
|
|
|
}
|
|
|
|
LCG(Conf.Cidr, dests)
|
|
|
|
} else {
|
|
|
|
Fatal("provide either a list (-l) or cidr range (-r)")
|
|
|
|
}
|
|
|
|
close(dests)
|
|
|
|
|
|
|
|
for x := 0; x < Conf.Threads; x++ {
|
|
|
|
<-tab
|
|
|
|
}
|
|
|
|
close(tab)
|
|
|
|
}
|