Skip to content
This repository has been archived by the owner on Jul 6, 2023. It is now read-only.

Commit

Permalink
add debug mode and ssl args
Browse files Browse the repository at this point in the history
  • Loading branch information
Becivells committed May 24, 2020
1 parent 917570a commit a487dbe
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 30 deletions.
117 changes: 91 additions & 26 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,23 @@ import (
)

var (
h bool
v bool
Version string
VERSION_TAG string
Compile string
Branch string
GitDirty string
HashUrl string
Hashfile string
ImageBase64 string
UserAgent string
IsUint32 bool
FofaFormat bool
ShodanFormat bool
DefaultUA string = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11"
h bool
v bool
Version string
VERSION_TAG string
Compile string
Branch string
GitDirty string
HashUrl string
Hashfile string
ImageBase64 string
UserAgent string
IsUint32 bool
FofaFormat bool
ShodanFormat bool
InsecureSkipVerify bool
Debug bool
DefaultUA string = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11"
)

func PrintVersion() {
Expand All @@ -44,23 +46,27 @@ func PrintVersion() {
func init() {
flag.BoolVar(&h, "h", false, "look help \n iconhash favicon.ico \n iconhash https://www.baidu.com/favicon.ico")
flag.BoolVar(&v, "v", false, "version")
flag.BoolVar(&Debug, "debug", false, "debug mode")
flag.BoolVar(&FofaFormat, "fofa", true, "fofa search format")
flag.BoolVar(&ShodanFormat, "shodan", false, "shodan search format \n iconhash -file test/favicon.ico -shodan -fofa=false")
flag.BoolVar(&IsUint32, "uint32", false, "uint32")
flag.BoolVar(&InsecureSkipVerify, "skip-verify", true, "https InsecureSkipVerify")
flag.StringVar(&Hashfile, "file", "", "mmh3 hash from file \n iconhash -file favicon.ico")
flag.StringVar(&HashUrl, "url", "", "mmh3 hash from url \n iconhash -url https://www.baidu.com/favicon.ico")
flag.StringVar(&UserAgent, "user-agent", DefaultUA, "mmh3 hash from url")
flag.StringVar(&ImageBase64, "b64", "", "mmh3 hash image base64 from file \n iconhash -file test/favicon.ico ")
IconHashArgs := map[string]int{
"-h": 1,
"-v": 1,
"-fofa": 1,
"-shodan": 1,
"-uint32": 1,
"-file": 1,
"-url": 1,
"-user-agent": 1,
"-b64": 1,
"-h": 1,
"-v": 1,
"-fofa": 1,
"-shodan": 1,
"-uint32": 1,
"-file": 1,
"-url": 1,
"-user-agent": 1,
"-b64": 1,
"-debug": 1,
"-skip-verify": 1,
}
flag.Parse()

Expand Down Expand Up @@ -99,6 +105,28 @@ func init() {
os.Exit(1)
}

if Debug {
fmt.Print("------------------var value-----------------------\n")
fmt.Printf("h :%t\n", h)
fmt.Printf("v :%t\n", v)
fmt.Printf("Version :%s\n", Version)
fmt.Printf("VERSION_TAG :%s\n", VERSION_TAG)
fmt.Printf("Compile :%s\n", Compile)
fmt.Printf("Branch :%s\n", Branch)
fmt.Printf("GitDirty :%s\n", GitDirty)
fmt.Printf("HashUrl :%s\n", HashUrl)
fmt.Printf("Hashfile :%s\n", Hashfile)
fmt.Printf("ImageBase64 :%s\n", ImageBase64)
fmt.Printf("UserAgent :%s\n", UserAgent)
fmt.Printf("IsUint32 :%t\n", IsUint32)
fmt.Printf("FofaFormat :%t\n", FofaFormat)
fmt.Printf("ShodanFormat :%t\n", ShodanFormat)
fmt.Printf("InsecureSkipVerify :%t\n", InsecureSkipVerify)
fmt.Printf("Debug :%t\n", Debug)
fmt.Printf("DefaultUA :%s\n", DefaultUA)
defer func() { fmt.Print("------------------var value-----------------------\n") }()
}

}
func PrintResult(result string) {
if !ShodanFormat && !FofaFormat {
Expand All @@ -115,34 +143,59 @@ func PrintResult(result string) {
}

func FromUrlGetContent(requrl string) (content []byte, err error) {
if Debug {
fmt.Print("------------------start url content-----------------------\n")
fmt.Printf("====> url: %s\n", HashUrl)
defer func() { fmt.Print("------------------end url content-----------------------\n") }()
}

client := &http.Client{
Timeout: time.Second * time.Duration(10),
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, //param
TLSClientConfig: &tls.Config{InsecureSkipVerify: InsecureSkipVerify}, //param
},
}

req, err := http.NewRequest("GET", requrl, nil)
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", UserAgent)
resp, err := client.Do(req)
defer resp.Body.Close()
if err != nil {
return nil, err
}

body, err := ioutil.ReadAll(resp.Body)

if Debug {
fmt.Printf("===> status code: %d\n", resp.StatusCode)
fmt.Printf("====> content: \n%s\n", body)
}

resp.Body.Close()
if err != nil {
return nil, err
}
return body, nil
}

func FromfileGetContent(path string) (content []byte, err error) {

if Debug {
fmt.Print("------------------start From file get content-----------------------\n")
defer func() { fmt.Print("------------------end From file get content-----------------------\n") }()
}

fi, err := os.Open(path)
if err != nil {
return nil, err
}
defer fi.Close()
content, err = ioutil.ReadAll(fi)
if Debug {
fmt.Printf("====> fileContent:\n %s\n", content)
}
// fmt.Println(string(fd))
if err != nil {
return nil, err
Expand Down Expand Up @@ -170,6 +223,11 @@ func StandBase64(braw []byte) []byte {
}
}
buffer.WriteByte('\n')
if Debug {
fmt.Print("------------------start base64 content-----------------------\n")
fmt.Printf("====> base64:\n %s\n", buffer.String())
defer func() { fmt.Print("------------------end base64 content-----------------------\n") }()
}
return buffer.Bytes()

}
Expand All @@ -189,6 +247,13 @@ func SplitChar76(braw []byte) []byte {
}
}
buffer.WriteByte('\n')

if Debug {
fmt.Print("------------------start base64 content-----------------------\n")
fmt.Printf("====> base64 split 76:\n %s\n", buffer.String())
defer func() { fmt.Print("------------------end base64 content-----------------------\n") }()
}

return buffer.Bytes()

}
24 changes: 20 additions & 4 deletions iconhash.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,48 @@
package main

import "os"
import (
"fmt"
"os"
)

func PrintErr(err error) {
if Debug {
panic(err)
}
fmt.Printf("%s\n", err)
os.Exit(1)
}
func main() {

if len(HashUrl) != 0 {
content, err := FromUrlGetContent(HashUrl)

if err != nil {
panic(err)
PrintErr(err)
}

PrintResult(Mmh3Hash32(StandBase64(content)))
os.Exit(0)
}

if len(Hashfile) != 0 {
content, err := FromfileGetContent(Hashfile)

if err != nil {
panic(err)
PrintErr(err)
}

PrintResult(Mmh3Hash32(StandBase64(content)))
os.Exit(0)
}

if len(ImageBase64) != 0 {
content, err := FromfileGetContent(ImageBase64)

if err != nil {
panic(err)
PrintErr(err)
}

PrintResult(Mmh3Hash32(SplitChar76(content)))
os.Exit(0)
}
Expand Down

0 comments on commit a487dbe

Please sign in to comment.