parent
de7ff1ed98
commit
05b7a361d2
@ -0,0 +1,53 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
var debugClient = &http.Client{
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func fetchsome(url string) ([]byte, error) {
|
||||
client := http.DefaultClient
|
||||
if debugMode {
|
||||
client = debugClient
|
||||
}
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
log.Printf("error fetching %s: %s", url, err)
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("User-Agent", "honksnonk/4.0")
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
|
||||
defer cancel()
|
||||
req = req.WithContext(ctx)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Printf("error fetching %s: %s", url, err)
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
switch resp.StatusCode {
|
||||
case 200:
|
||||
case 201:
|
||||
case 202:
|
||||
default:
|
||||
return nil, fmt.Errorf("http get not 200: %d %s", resp.StatusCode, url)
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
limiter := io.LimitReader(resp.Body, 10*1024*1024)
|
||||
io.Copy(&buf, limiter)
|
||||
return buf.Bytes(), nil
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math/big"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var debugMode = false
|
||||
|
||||
func honkahonk(server, token, wonk, wonkles string) {
|
||||
form := make(url.Values)
|
||||
form.Add("token", token)
|
||||
form.Add("action", "honk")
|
||||
form.Add("noise", wonk)
|
||||
form.Add("wonkles", wonkles)
|
||||
apiurl := fmt.Sprintf("https://%s/api", server)
|
||||
req, err := http.NewRequest("POST", apiurl, strings.NewReader(form.Encode()))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
client := http.DefaultClient
|
||||
if debugMode {
|
||||
client = debugClient
|
||||
}
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
answer, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if resp.StatusCode != 200 {
|
||||
log.Fatalf("status: %d: %s", resp.StatusCode, answer)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
server := ""
|
||||
token := ""
|
||||
wonkles := ""
|
||||
flag.StringVar(&server, "server", server, "server to connnect")
|
||||
flag.StringVar(&token, "token", token, "auth token to use")
|
||||
flag.StringVar(&wonkles, "wonkles", wonkles, "wordlist to use")
|
||||
flag.BoolVar(&debugMode, "debug", debugMode, "debug mode")
|
||||
flag.Parse()
|
||||
|
||||
if server == "" || token == "" || wonkles == "" {
|
||||
flag.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
wordlist, err := fetchsome(wonkles)
|
||||
if err != nil {
|
||||
log.Printf("error fetching wonkles: %s", err)
|
||||
}
|
||||
var words []string
|
||||
for _, w := range strings.Split(string(wordlist), "\n") {
|
||||
words = append(words, w)
|
||||
}
|
||||
max := big.NewInt(int64(len(words)))
|
||||
i, _ := rand.Int(rand.Reader, max)
|
||||
wonk := words[i.Int64()]
|
||||
|
||||
log.Printf("picking: %s", wonk)
|
||||
|
||||
honkahonk(server, token, wonk, wonkles)
|
||||
}
|
Loading…
Reference in new issue