From 46e411438b40ef50ca7d0fc1ec681651b0435042 Mon Sep 17 00:00:00 2001 From: Omid Destan Date: Sat, 30 Sep 2023 09:09:29 +0330 Subject: [PATCH] Fix Layers --- checkwpjson.go | 176 --------------------------------- cmd/Part1/Part1.go | 86 ++++++++++++++++ cmd/Part2/Part2.go | 97 ++++++++++++++++++ cmd/checkwpjson/checkwpjson.go | 67 +++++++++++++ 4 files changed, 250 insertions(+), 176 deletions(-) delete mode 100644 checkwpjson.go create mode 100644 cmd/Part1/Part1.go create mode 100644 cmd/Part2/Part2.go create mode 100644 cmd/checkwpjson/checkwpjson.go diff --git a/checkwpjson.go b/checkwpjson.go deleted file mode 100644 index 8e9b365..0000000 --- a/checkwpjson.go +++ /dev/null @@ -1,176 +0,0 @@ -package main - -import ( - "bufio" - "crypto/tls" - "encoding/json" - "flag" - "fmt" - "io/ioutil" - "net/http" - "os" - "strings" - - "github.com/TwiN/go-color" -) - -type Author struct { - ID int `json:"id"` - Name string `json:"name"` - URL string `json:"url"` - Description string `json:"description"` - Link string `json:"link"` - Slug string `json:"slug"` - AvatarURLs struct { - Size24 string `json:"24"` - Size48 string `json:"48"` - Size96 string `json:"96"` - } `json:"avatar_urls"` - Meta []interface{} `json:"meta"` - ACF []interface{} `json:"acf"` - // Add more fields here as needed -} - -var authors []Author -var outlast []string -var path string -var fo *os.File -var fo2 *os.File - -func main() { - //Receive input from the user. - input := flag.String("i", "input.txt", "Input List") - output := flag.String("o", "output.txt", "Output List") - help := flag.Bool("h", false, "Show help") - flag.Parse() - if *help { - fmt.Println("-h : To Show Help") - fmt.Println("-i : To Input File Address") - fmt.Println("-o : To OutPut File Address") - } - //Open OutPut File in Directory - fo, err := os.OpenFile(*output, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0777) - if err != nil { - - fmt.Println(color.Colorize(color.Red, "[-] Error:"+err.Error())) - fmt.Println(color.Colorize(color.Red, "[-] Error In Permission To Open File")) - } - //To Skip Insecure SSL - tr := &http.Transport{ - TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, - } - // Do not verify certificates, do not follow redirects. - client := &http.Client{ - Transport: tr, - CheckRedirect: func(req *http.Request, via []*http.Request) error { - return http.ErrUseLastResponse - }} - - InputFile := *input - //Open Input File - InputWebs, err := os.Open(InputFile) - if err != nil { - fmt.Println(color.Colorize(color.Red, "[-] Error:"+err.Error())) - recover() - } - //Scan All Line of input file - InputBuf := bufio.NewScanner(InputWebs) - InputBuf.Split(bufio.ScanLines) - - for InputBuf.Scan() { - //Check End Of File Or not - InputText := InputBuf.Text() - if !strings.HasSuffix(InputText, "/") { - //It puts the values of the file line by line into the variable. - path = fmt.Sprintf(InputText+"/%s", "wp-json/wp/v2/users") - // Add WP-json Directory To your Address - } else { - path = fmt.Sprintf(InputText+"%s", "/wp-json/wp/v2/users") - } - req, _ := http.NewRequest("GET", path, nil) - //Send Request To Address - resp, erer := client.Do(req) - - if erer != nil { - fmt.Println(color.Colorize(color.Red, "[-] Error:"+erer.Error())) - continue - } - if resp.StatusCode == 200 { - //Check Response status Code - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - fmt.Println(color.Colorize(color.Red, "[-] Error:"+err.Error())) - continue - } - err = json.Unmarshal(body, &authors) - //Parse Json Values To Show - if err != nil { - fmt.Println(color.Colorize(color.Red, "[-] Line 91 Error:"+err.Error())) - continue - } - fmt.Println(color.Colorize(color.Green, "[+] Find In : "+path)) - outlast = append(outlast, path+"\n") - for _, author := range authors { - outlast = append(outlast, " User Name :\n"+author.Slug+"\n") - fmt.Println(color.Colorize(color.Green, "[+] UserNames : "+author.Slug)) - - } - outlast = append(outlast, "********************************************\n") - - _, err = fmt.Fprint(fo, outlast) - //Save In output File - if err != nil { - fmt.Println(color.Colorize(color.Red, "[-] Line 100 Error:"+err.Error())) - continue - } - } else { - if !strings.HasSuffix(InputText, "/") { - //It puts the values of the file line by line into the variable. - path = fmt.Sprintf(InputText+"/%s", "?rest_route=/wp/v2/users/") - // Add WP-json Directory To your Address - } else { - path = fmt.Sprintf(InputText+"%s", "/?rest_route=/wp/v2/users/") - } - reqs, _ := http.NewRequest("GET", path, nil) - //Send Request To Address - resps, erers := client.Do(reqs) - - if erers != nil { - fmt.Println(color.Colorize(color.Red, "[-] Error:"+erer.Error())) - continue - } - if resps.StatusCode == 200 { - //Check Response status Code - body, errs := ioutil.ReadAll(resps.Body) - if errs != nil { - fmt.Println(color.Colorize(color.Red, "[-] Error:"+err.Error())) - continue - } - err = json.Unmarshal(body, &authors) - //Parse Json Values To Show - if err != nil { - fmt.Println(color.Colorize(color.Red, "[-] Line 91 Error:"+err.Error())) - continue - } - fmt.Println(color.Colorize(color.Green, "[+] Find In : "+path)) - outlast = append(outlast, path+"\n") - for _, author := range authors { - outlast = append(outlast, " User Name :\n"+author.Slug+"\n") - fmt.Println(color.Colorize(color.Green, "[+] UserNames : "+author.Slug)) - - } - outlast = append(outlast, "********************************************\n") - - _, err = fmt.Fprint(fo, outlast) - //Save In output File - if err != nil { - fmt.Println(color.Colorize(color.Red, "[-] Line 100 Error:"+err.Error())) - continue - } - } else { - fmt.Println(color.Colorize(color.Red, "[-] Not Find any users")) - } - } - } - -} diff --git a/cmd/Part1/Part1.go b/cmd/Part1/Part1.go new file mode 100644 index 0000000..22e24e4 --- /dev/null +++ b/cmd/Part1/Part1.go @@ -0,0 +1,86 @@ +package Part1 + +import ( + "crypto/tls" + "encoding/json" + "fmt" + "github.com/TwiN/go-color" + "github.com/destan0098/checkwpjson/cmd/Part2" + "io/ioutil" + "net/http" + "os" +) + +type Author struct { + ID int `json:"id"` + Name string `json:"name"` + URL string `json:"url"` + Description string `json:"description"` + Link string `json:"link"` + Slug string `json:"slug"` + AvatarURLs struct { + Size24 string `json:"24"` + Size48 string `json:"48"` + Size96 string `json:"96"` + } `json:"avatar_urls"` + Meta []interface{} `json:"meta"` + ACF []interface{} `json:"acf"` + // Add more fields here as needed +} + +var outlast []string +var authors []Author +var err error + +func Part1(path string, fo *os.File, InputText string) { + fmt.Println(path) + tr := &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + } + // Do not verify certificates, do not follow redirects. + client := &http.Client{ + Transport: tr, + CheckRedirect: func(req *http.Request, via []*http.Request) error { + return http.ErrUseLastResponse + }} + + req, _ := http.NewRequest("GET", path, nil) + //Send Request To Address + resp, erer := client.Do(req) + + if erer != nil { + fmt.Println(color.Colorize(color.Red, "[-] Error:"+erer.Error())) + recover() + } + if resp.StatusCode == 200 { + //Check Response status Code + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + fmt.Println(color.Colorize(color.Red, "[-] Error:"+err.Error())) + recover() + } + err = json.Unmarshal(body, &authors) + //Parse Json Values To Show + if err != nil { + fmt.Println(color.Colorize(color.Red, "[-] Line 91 Error:"+err.Error())) + recover() + } + fmt.Println(color.Colorize(color.Green, "[+] Find In : "+path)) + outlast = append(outlast, path+"\n") + for _, author := range authors { + outlast = append(outlast, " User Name :\n"+author.Slug+"\n") + fmt.Println(color.Colorize(color.Green, "[+] UserNames : "+author.Slug)) + + } + outlast = append(outlast, "********************************************\n") + + _, err = fmt.Fprint(fo, outlast) + //Save In output File + if err != nil { + fmt.Println(color.Colorize(color.Red, "[-] Line 100 Error:"+err.Error())) + recover() + } + } else { + Part2.Part2(fo, InputText) + } +} diff --git a/cmd/Part2/Part2.go b/cmd/Part2/Part2.go new file mode 100644 index 0000000..9b669ca --- /dev/null +++ b/cmd/Part2/Part2.go @@ -0,0 +1,97 @@ +package Part2 + +import ( + "crypto/tls" + "encoding/json" + "fmt" + "github.com/TwiN/go-color" + "io/ioutil" + "net/http" + "os" + "strings" +) + +type Author struct { + ID int `json:"id"` + Name string `json:"name"` + URL string `json:"url"` + Description string `json:"description"` + Link string `json:"link"` + Slug string `json:"slug"` + AvatarURLs struct { + Size24 string `json:"24"` + Size48 string `json:"48"` + Size96 string `json:"96"` + } `json:"avatar_urls"` + Meta []interface{} `json:"meta"` + ACF []interface{} `json:"acf"` + // Add more fields here as needed +} + +var outlast []string +var authors []Author +var err error +var path string + +func Part2(fo *os.File, InputText string) { + tr := &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + } + client := &http.Client{ + Transport: tr, + CheckRedirect: func(req *http.Request, via []*http.Request) error { + return http.ErrUseLastResponse + }} + + //Send Request To Address + + if !strings.HasSuffix(InputText, "/") { + //It puts the values of the file line by line into the variable. + path = fmt.Sprintf(InputText+"/%s", "?rest_route=/wp/v2/users/") + // Add WP-json Directory To your Address + + } else { + path = fmt.Sprintf(InputText+"%s", "?rest_route=/wp/v2/users/") + + } + reqs, _ := http.NewRequest("GET", path, nil) + //Send Request To Address + resps, erers := client.Do(reqs) + + if erers != nil { + fmt.Println(color.Colorize(color.Red, "[-] Error:"+erers.Error())) + recover() + } + if resps.StatusCode == 200 { + //Check Response status Code + body, errs := ioutil.ReadAll(resps.Body) + if errs != nil { + fmt.Println(color.Colorize(color.Red, "[-] Error:"+err.Error())) + recover() + } + err = json.Unmarshal(body, &authors) + //Parse Json Values To Show + if err != nil { + fmt.Println(color.Colorize(color.Red, "[-] Line 91 Error:"+err.Error())) + recover() + } + fmt.Println(color.Colorize(color.Green, "[+] Find In : "+path)) + outlast = append(outlast, path+"\n") + for _, author := range authors { + outlast = append(outlast, " User Name :\n"+author.Slug+"\n") + fmt.Println(color.Colorize(color.Green, "[+] UserNames : "+author.Slug)) + + } + outlast = append(outlast, "********************************************\n") + + _, err = fmt.Fprint(fo, outlast) + //Save In output File + if err != nil { + fmt.Println(color.Colorize(color.Red, "[-] Line 100 Error:"+err.Error())) + recover() + } + } else { + fmt.Println(color.Colorize(color.Red, "[-] Not Find any users")) + + } +} diff --git a/cmd/checkwpjson/checkwpjson.go b/cmd/checkwpjson/checkwpjson.go new file mode 100644 index 0000000..6c8b21f --- /dev/null +++ b/cmd/checkwpjson/checkwpjson.go @@ -0,0 +1,67 @@ +package main + +import ( + "bufio" + "flag" + "fmt" + "github.com/TwiN/go-color" + "github.com/destan0098/checkwpjson/cmd/Part1" + "os" + "strings" +) + +var path string +var fo *os.File + +var err error + +func main() { + //Receive input from the user. + input := flag.String("i", "input.txt", "Input List") + output := flag.String("o", "output.txt", "Output List") + help := flag.Bool("h", false, "Show help") + flag.Parse() + if *help { + fmt.Println("-h : To Show Help") + fmt.Println("-i : To Input File Address") + fmt.Println("-o : To OutPut File Address") + } + //Open OutPut File in Directory + fo, err = os.OpenFile(*output, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0777) + if err != nil { + + fmt.Println(color.Colorize(color.Red, "[-] Error:"+err.Error())) + fmt.Println(color.Colorize(color.Red, "[-] Error In Permission To Open File")) + } + //To Skip Insecure SSL + + InputFile := *input + //Open Input File + InputWebs, err := os.Open(InputFile) + if err != nil { + fmt.Println(color.Colorize(color.Red, "[-] Error:"+err.Error())) + recover() + } + //Scan All Line of input file + InputBuf := bufio.NewScanner(InputWebs) + InputBuf.Split(bufio.ScanLines) + + for InputBuf.Scan() { + //Check End Of File Or not + InputText := InputBuf.Text() + + if !strings.HasSuffix(InputText, "/") { + + //It puts the values of the file line by line into the variable. + path = fmt.Sprintf(InputText+"/%s", "wp-json/wp/v2/users") + + // Add WP-json Directory To your Address + } else { + + path = fmt.Sprintf(InputText+"%s", "wp-json/wp/v2/users") + + } + Part1.Part1(path, fo, InputText) + } + +}