feat: Initial commit
This commit is contained in:
commit
321b77b9ac
7 changed files with 213 additions and 0 deletions
25
checks/checks.go
Normal file
25
checks/checks.go
Normal file
|
@ -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
|
||||
}
|
29
checks/env.go
Normal file
29
checks/env.go
Normal file
|
@ -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)
|
||||
}
|
||||
}
|
31
checks/git.go
Normal file
31
checks/git.go
Normal file
|
@ -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)))
|
||||
}
|
||||
}
|
30
checks/index.go
Normal file
30
checks/index.go
Normal file
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
11
go.mod
Normal file
11
go.mod
Normal file
|
@ -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
|
||||
)
|
10
go.sum
Normal file
10
go.sum
Normal file
|
@ -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=
|
77
main.go
Normal file
77
main.go
Normal file
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue