first commit

This commit is contained in:
Lucas Schumacher 2024-07-15 21:28:20 -04:00
commit 84153f4d86
3 changed files with 60 additions and 0 deletions

5
go.mod Normal file
View File

@ -0,0 +1,5 @@
module secucookiedump
go 1.22.5
require github.com/gorilla/securecookie v1.1.2 // indirect

2
go.sum Normal file
View File

@ -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=

53
secucookiedump.go Normal file
View File

@ -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.")
}