commit 84153f4d861eba23b48d2b83721a9e5ffe5d9ffe Author: Lucas Schumacher Date: Mon Jul 15 21:28:20 2024 -0400 first commit diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..a90ebc4 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module secucookiedump + +go 1.22.5 + +require github.com/gorilla/securecookie v1.1.2 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..4d61994 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA= +github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo= diff --git a/secucookiedump.go b/secucookiedump.go new file mode 100644 index 0000000..a82370d --- /dev/null +++ b/secucookiedump.go @@ -0,0 +1,53 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "strings" + + "github.com/gorilla/securecookie" +) + +func main() { + scanner := bufio.NewScanner(os.Stdin) + key := os.Getenv("SESSION_SECRET") + + if key == "" { + fmt.Print("Key not set\nEnter key: ") + for scanner.Scan() { + key = scanner.Text() + if key != "" { + break + } + fmt.Print("Enter key: ") + } + } + + s := securecookie.New([]byte(key), nil) + + fmt.Println("Using key:", key) + fmt.Println("Enter secure cookie (Ctrl+D to finish):") + + for scanner.Scan() { + text := scanner.Text() + fmt.Println("Read:", text) + split := strings.SplitN(text, "=", 2) + //split := strings.Fields(text) + value := make(map[interface{}]interface{}) + if err := s.Decode(split[0], split[1], &value); err == nil { + for key, val := range value { + fmt.Printf("Key: %s, Value: %s\n", key, val) + } + } else { + fmt.Println(err) + } + fmt.Println("") + } + + if err := scanner.Err(); err != nil { + fmt.Println("Error reading standard input:", err) + } + + fmt.Println("Program finished.") +}