Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closes #3 by adding cookies #4

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions gosearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,18 @@ type Website struct {
ErrorType string `yaml:"errorType"`
ErrorMsg string `yaml:"errorMsg,omitempty"`
ErrorCode int `yaml:"errorCode,omitempty"`
Cookies []Cookie `yaml:"cookies,omitempty"` // New field for cookies
}

type Config struct {
Websites []Website `yaml:"websites"`
}

type Cookie struct {
Name string `yaml:"name"`
Value string `yaml:"value"`
}

func UnmarshalYAML() (Config, error) {

// GoSearch relies on config.yaml to determine the websites to search for.
Expand Down Expand Up @@ -101,6 +107,38 @@ func BuildURL(baseURL, username string) string {
return strings.Replace(baseURL, "{}", username, 1)
}

func MakeRequestWithCookies(url string, cookies [] Cookie, WebsiteErrorCode int, wg *sync.WaitGroup) {
defer wg.Done()

client := &http.Client{}
req, err := http.NewRequest("GET", url, nil)

if err != nil {
fmt.Printf("Error creating request in function MakeRequestWithCookies: %v\n", err)
return
}

for _, cookie := range cookies {
cookieObj := &http.Cookie{
Name: cookie.Name,
Value: cookie.Value,
}
req.AddCookie(cookieObj)
}

resp, err := client.Do(req)
if err != nil {
fmt.Printf("Error making request to %s: %v\n", url, err)
return
}
defer resp.Body.Close()

if resp.StatusCode != WebsiteErrorCode {
fmt.Println(Green + "::", url + Reset)
WriteToFile("results.txt", url + "\n")
}
}

func MakeRequestWithoutErrorMsg(url string, WebsiteErrorCode int, wg *sync.WaitGroup) {
defer wg.Done()

Expand Down Expand Up @@ -160,13 +198,16 @@ func Search(config Config, username string) {
} else if website.ErrorType == "unknown" {
fmt.Println(Yellow + ":: [?]", url + Reset)
WriteToFile("results.txt", "[?] " + url + "\n")
} else {

} else if website.Cookies != nil {
wg.Add(1)
go MakeRequestWithCookies(url, website.Cookies, website.ErrorCode, &wg)
} else {
wg.Add(1)
go MakeRequestWithoutErrorMsg(url, website.ErrorCode, &wg)
}
}

// Wait for all goroutines to finish
wg.Wait()
}

Expand Down
Loading