2024-04-07 03:59:13 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"net"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"deadbeef.codes/steven/hyp/otphyp"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MaxNetworkLatency specifies the number of milliseconds
|
|
|
|
// A packet-switched network... more like "race condition factory"
|
|
|
|
const MaxNetworkLatency = 500
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
// validate number of input arguments
|
|
|
|
if len(os.Args) < 2 {
|
|
|
|
usage()
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
// load secret and generate ports using secret and current time
|
|
|
|
secretBytes, err := os.ReadFile("hyp.secret")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("failed to read file 'hyp.secret': %v", err)
|
|
|
|
}
|
|
|
|
sharedSecret := string(secretBytes)
|
|
|
|
|
|
|
|
ports, err := otphyp.GeneratePorts(sharedSecret, time.Now())
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("failed to generate ports from shared secret: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Transmit
|
|
|
|
fmt.Println("Transmitting knock sequence:", ports)
|
|
|
|
for _, port := range ports {
|
|
|
|
conn, _ := net.Dial("udp", fmt.Sprintf("%s:%d", os.Args[1], port))
|
|
|
|
conn.Write([]byte{0})
|
|
|
|
conn.Close()
|
|
|
|
time.Sleep(time.Millisecond * MaxNetworkLatency)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func usage() {
|
2024-04-08 03:33:13 +00:00
|
|
|
fmt.Print(`hyp <server>
|
|
|
|
|
|
|
|
Example Usage:
|
|
|
|
|
|
|
|
# Transmit an authentic knock sequence to a server
|
|
|
|
hyp 10.69.4.20
|
|
|
|
|
|
|
|
# You can use a DNS name too
|
|
|
|
hyp hyp.stevenpolley.net
|
|
|
|
|
|
|
|
`)
|
|
|
|
os.Exit(1)
|
2024-04-07 03:59:13 +00:00
|
|
|
}
|