commit 321b77b9ac59d03798e3b31e82811d7fd8404a14 Author: ptrcnull Date: Fri Oct 8 15:20:19 2021 +0200 feat: Initial commit diff --git a/checks/checks.go b/checks/checks.go new file mode 100644 index 0000000..8857b46 --- /dev/null +++ b/checks/checks.go @@ -0,0 +1,25 @@ +package checks + +import ( + "fmt" + "net/http" +) + +type Checks struct { + Message func(string) +} + +func (c *Checks) get(url string) (*http.Response, error) { + res, err := http.Get(url) + if err != nil { + //log.Println(domain + " error: " + err.Error()) + return nil, err + } + + if res.StatusCode != 200 { + //log.Println(domain + " status: " + res.Status) + return nil, fmt.Errorf("bad status code") + } + + return res, nil +} diff --git a/checks/env.go b/checks/env.go new file mode 100644 index 0000000..e5e1066 --- /dev/null +++ b/checks/env.go @@ -0,0 +1,29 @@ +package checks + +import ( + "io/ioutil" + "log" +) + +func (c *Checks) CheckEnv(domain string) { + url := "https://" + domain + "/.env" + res, err := c.get(url) + if err != nil { + //log.Println(domain + " error: " + err.Error()) + return + } + + bbody, err := ioutil.ReadAll(res.Body) + if err != nil { + //log.Println(domain + " read error: " + err.Error()) + return + } + + body := string(bbody) + + contentType := res.Header.Get("Content-Type") + if contentType == "" { + c.Message("znalazło debila\n" + url + "\n\n" + body) + log.Println("DEBIL " + url) + } +} diff --git a/checks/git.go b/checks/git.go new file mode 100644 index 0000000..d236d88 --- /dev/null +++ b/checks/git.go @@ -0,0 +1,31 @@ +package checks + +import ( + "io/ioutil" + "log" + "strings" +) + +func (c *Checks) CheckGit(domain string) { + url := "https://" + domain + "/.git/HEAD" + res, err := c.get(url) + if err != nil { + //log.Println(domain + " error: " + err.Error()) + return + } + + bbody, err := ioutil.ReadAll(res.Body) + if err != nil { + //log.Println(domain + " read error: " + err.Error()) + return + } + + body := string(bbody) + + if strings.HasPrefix(body, "ref:") { + c.Message("znalazło debila\n" + url + "\n\n" + body) + log.Println("DEBIL " + url) + } else { + //log.Println(domain + " size: " + strconv.Itoa(len(body))) + } +} diff --git a/checks/index.go b/checks/index.go new file mode 100644 index 0000000..9cf9c5a --- /dev/null +++ b/checks/index.go @@ -0,0 +1,30 @@ +package checks + +import ( + "io/ioutil" + "log" + "strings" +) + +func (c *Checks) CheckIndex(domain string) { + url := "https://" + domain + "/" + res, err := c.get(url) + if err != nil { + //log.Println(domain + " error: " + err.Error()) + return + } + + bbody, err := ioutil.ReadAll(res.Body) + if err != nil { + //log.Println(domain + " read error: " + err.Error()) + return + } + + body := string(bbody) + + if strings.Contains(body, "Index of /") && !strings.Contains(body, "Proudly Served by LiteSpeed Web Server at") { + c.Message("znalazło debila z indeksowaniem\n" + url) + log.Println("DEBIL " + url) + } +} + diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..9d3d7b5 --- /dev/null +++ b/go.mod @@ -0,0 +1,11 @@ +module git.ddd.rip/ptrcnull/debil-finder + +go 1.16 + +require ( + git.ddd.rip/ptrcnull/telegram v0.0.0-20210310180959-e60c53ded477 + github.com/CaliDog/certstream-go v0.0.0-20200713031452-eca7997412f1 + github.com/gorilla/websocket v1.4.2 // indirect + github.com/jmoiron/jsonq v0.0.0-20150511023944-e874b168d07e // indirect + github.com/pkg/errors v0.9.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..de6cd9d --- /dev/null +++ b/go.sum @@ -0,0 +1,10 @@ +git.ddd.rip/ptrcnull/telegram v0.0.0-20210310180959-e60c53ded477 h1:bTJNpfhNecvv7sZ0v7IfNmSRxRQpvIrTGNnbPa/cK80= +git.ddd.rip/ptrcnull/telegram v0.0.0-20210310180959-e60c53ded477/go.mod h1:SSSKvfhw7mDx/8UPoLdtP9J74z2/pXccHnKzdi16nLA= +github.com/CaliDog/certstream-go v0.0.0-20200713031452-eca7997412f1 h1:P2kAob5k67YLNGJg0C6Wg0nTLrUpIxYvpPFVrk1y1PQ= +github.com/CaliDog/certstream-go v0.0.0-20200713031452-eca7997412f1/go.mod h1:JBo69gi8JyPpZoLZgmZeXiq4o7Ib2qf2RiIxiWC0oYQ= +github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= +github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/jmoiron/jsonq v0.0.0-20150511023944-e874b168d07e h1:ZZCvgaRDZg1gC9/1xrsgaJzQUCQgniKtw0xjWywWAOE= +github.com/jmoiron/jsonq v0.0.0-20150511023944-e874b168d07e/go.mod h1:+rHyWac2R9oAZwFe1wGY2HBzFJJy++RHBg1cU23NkD8= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= diff --git a/main.go b/main.go new file mode 100644 index 0000000..23c0e56 --- /dev/null +++ b/main.go @@ -0,0 +1,77 @@ +package main + +import ( + "git.ddd.rip/ptrcnull/debil-finder/checks" + "git.ddd.rip/ptrcnull/telegram" + "github.com/CaliDog/certstream-go" + "log" + "os" + "strings" +) + +func main() { + tg := telegram.Client{Token: os.Getenv("TELEGRAM_TOKEN")} + chatId := os.Getenv("TELEGRAM_CHAT_ID") + + res, err := tg.SendMessage(chatId, "Starting...") + if err != nil { + panic(err) + } + log.Println(res) + + c := &checks.Checks{ + Message: func(msg string) { + tg.SendMessage(chatId, msg) + }, + } + + stream, errStream := certstream.CertStreamEventStream(false) + for { + select { + case jq := <-stream: + messageType, err := jq.String("message_type") + if err != nil { + tg.SendMessage(chatId, "failed decoding message: " + err.Error()) + } + if messageType != "certificate_update" { + continue + } + + allDomains, err := jq.ArrayOfStrings("data", "leaf_cert", "all_domains") + if err != nil { + tg.SendMessage(chatId, "failed getting domains: " + err.Error()) + } + + polish := false + ndc := false + for _, domain := range allDomains { + if strings.HasSuffix(domain, ".pl") { + polish = true + } + if strings.HasSuffix(domain, "ndc.pl") { + ndc = true + } + } + if !polish { + continue + } + if ndc { + continue + } + + log.Println(allDomains) + for _, domain := range allDomains { + if domain[0] == '*' || domain == "sni.cloudflaressl.com" { + continue + } + log.Println("checking " + domain) + go c.CheckGit(domain) + go c.CheckEnv(domain) + go c.CheckIndex(domain) + } + + case err := <-errStream: + log.Println(err) + } + } +}