Skip to content

Instantly share code, notes, and snippets.

@HanEmile
Last active June 10, 2023 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HanEmile/8696d6d2545bf9886de3ba6ba00d431d to your computer and use it in GitHub Desktop.
Save HanEmile/8696d6d2545bf9886de3ba6ba00d431d to your computer and use it in GitHub Desktop.
A super simple fuzzer for the easterhegg 2023 workshop
package main
import (
"fmt"
"io"
"net/http"
"os"
"strings"
"time"
)
func request(id int, url string) {
resp, err := http.Get(url)
if err != nil {
fmt.Println("Some error: ", err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("Some error: ", err)
}
if len(body) != 146 {
fmt.Printf("[%d] made an http request to url %s | len(req) = %d\n", id, url, len(body))
}
}
func worker(id int, wordChan chan string, doneChan chan bool) {
out:
for {
select {
case url := <-wordChan:
url = fmt.Sprintf("https://emile.space/%s", url)
request(id, url)
case <-time.After(3 * time.Second):
fmt.Printf("worker %d couldn't get a new url after 3 seconds, quitting\n", id)
break out
}
}
doneChan <- true
}
func main() {
dat, err := os.ReadFile("./wordlist.txt")
if err != nil {
fmt.Println("Some error: ", err)
}
words := strings.Split(string(dat), "\n")
wordChan := make(chan string, 10)
doneChan := make(chan bool, 4)
for i := 1; i < 4; i++ {
go worker(i, wordChan, doneChan)
}
for _, word := range words {
wordChan <- word
}
for i := 1; i < 4; i++ {
<-doneChan
}
}
@9glenda
Copy link

9glenda commented Jun 10, 2023

Handeling the errors:

package main

import (
    "fmt"
    "io"
    "net/http"
    "os"
    "strings"
    "time"
)

func request(id int, url string) {
    resp, err := http.Get(url)
    if err != nil {
        fmt.Println("Some error: ", err)
        return
    }
    defer resp.Body.Close()

    body, err := io.ReadAll(resp.Body)
    if err != nil {
        fmt.Println("Some error: ", err)
        return
    }

    if len(body) != 146 {
        fmt.Printf("[%d] made an http request to url %s | len(req) = %d\n", id, url, len(body))
    }
}

func worker(id int, wordChan chan string, doneChan chan bool) {
out:
    for {
        select {
        case url := <-wordChan:
            url = fmt.Sprintf("https://emile.space/%s", url)
            request(id, url)
        case <-time.After(3 * time.Second):
            fmt.Printf("worker %d couldn't get a new url after 3 seconds, quitting\n", id)
            break out
        }
    }
    doneChan <- true
}

func main() {
    dat, err := os.ReadFile("./wordlist.txt")
    if err != nil {
        fmt.Println("Some error: ", err)
        return
    }

    words := strings.Split(string(dat), "\n")

    wordChan := make(chan string, 10)
    doneChan := make(chan bool, 4)
    for i := 1; i < 4; i++ {
        go worker(i, wordChan, doneChan)
    }

    for _, word := range words {
        wordChan <- word
    }

    for i := 1; i < 4; i++ {
        <-doneChan
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment