Skip to content

Commit 29c6837

Browse files
authored
Merge pull request #201 from projectdiscovery/dwisiswant0/feat/add-cookie-unsign
feat: add `cookie_unsign`
2 parents e590dc7 + 9dbd37a commit 29c6837

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

dsl.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/Mzack9999/gcache"
3939
"github.com/asaskevich/govalidator"
4040
"github.com/hashicorp/go-version"
41+
"github.com/iangcarroll/cookiemonster/pkg/monster"
4142
"github.com/kataras/jwt"
4243
"github.com/logrusorgru/aurora"
4344
"github.com/projectdiscovery/dsl/deserialization"
@@ -1437,7 +1438,35 @@ func init() {
14371438
}
14381439

14391440
return cases.Title(lang).String(s), nil
1440-
}))
1441+
},
1442+
))
1443+
1444+
MustAddFunction(NewWithSingleSignature("cookie_unsign",
1445+
"(s string) string", false,
1446+
func(args ...interface{}) (interface{}, error) {
1447+
argSize := len(args)
1448+
if argSize < 1 {
1449+
return nil, ErrInvalidDslFunction
1450+
}
1451+
s := toString(args[0])
1452+
1453+
wl := monster.NewWordlist()
1454+
if err := wl.LoadDefault(); err != nil {
1455+
return s, errors.New("could not load default wordlist")
1456+
}
1457+
1458+
c := monster.NewCookie(s)
1459+
if !c.Decode() {
1460+
return s, errors.New("could not decode cookie")
1461+
}
1462+
1463+
if cookie, ok := c.Unsign(wl, 100); ok {
1464+
return string(cookie), nil
1465+
}
1466+
1467+
return s, errors.New("could not unsign cookie")
1468+
},
1469+
))
14411470

14421471
MustAddFunction(NewWithPositionalArgs("gzip_mtime", 1, true, func(args ...interface{}) (interface{}, error) {
14431472
if len(args) == 0 {

dsl_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ func TestGetPrintableDslFunctionSignatures(t *testing.T) {
247247
contains(arg1, arg2 interface{}) interface{}
248248
contains_all(body interface{}, substrs ...string) bool
249249
contains_any(body interface{}, substrs ...string) bool
250+
cookie_unsign(s string) string
250251
count(str, substr string) int
251252
date_time(dateTimeFormat string, optionalUnixTime interface{}) string
252253
dec_to_hex(arg1 interface{}) interface{}
@@ -464,6 +465,7 @@ cSy4ym0pQ7ZKMEJbWYxFuw3CJfWAFbdXcULgqIG0K7Nh++g6v5XLRceqxOW9j9Mc
464465
vOZml6PnbXH+Z1+yVskAoyGKnOxRSaD0DJY6xq1x3z5AoVImLsCLSkJr2D+4W+EC
465466
PQIDAQAB
466467
-----END PUBLIC KEY-----") != ""`: true,
468+
`cookie_unsign("gAJ9cQFYCgAAAHRlc3Rjb29raWVxAlgGAAAAd29ya2VkcQNzLg:1mgnkC:z5yDxzI06qYVAU3bkLaWYpADT4I")`: "changeme",
467469
}
468470

469471
testDslExpressions(t, dslExpressions)

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/Mzack9999/gcache v0.0.0-20230410081825-519e28eab057
88
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2
99
github.com/hashicorp/go-version v1.6.0
10+
github.com/iangcarroll/cookiemonster v1.6.0
1011
github.com/kataras/jwt v0.1.8
1112
github.com/logrusorgru/aurora v2.0.3+incompatible
1213
github.com/pkg/errors v0.9.1
@@ -53,7 +54,8 @@ require (
5354
github.com/tidwall/gjson v1.18.0 // indirect
5455
github.com/tidwall/match v1.1.1 // indirect
5556
github.com/tidwall/pretty v1.2.1 // indirect
56-
github.com/ulikunitz/xz v0.5.14 // indirect
57+
github.com/ulikunitz/xz v0.5.15 // indirect
58+
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
5759
go.uber.org/multierr v1.11.0 // indirect
5860
go4.org v0.0.0-20230225012048-214862532bf5 // indirect
5961
golang.org/x/mod v0.22.0 // indirect

go.sum

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs
9797
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
9898
github.com/hdm/jarm-go v0.0.7 h1:Eq0geenHrBSYuKrdVhrBdMMzOmA+CAMLzN2WrF3eL6A=
9999
github.com/hdm/jarm-go v0.0.7/go.mod h1:kinGoS0+Sdn1Rr54OtanET5E5n7AlD6T6CrJAKDjJSQ=
100+
github.com/iangcarroll/cookiemonster v1.6.0 h1:NPFkn/ZZYZgzXhJ1awRnYhZ3fJK3hKWgbctfTW21kew=
101+
github.com/iangcarroll/cookiemonster v1.6.0/go.mod h1:n3MvoAq56NkNyCEyhcYs3ZJMzTc9rL3w7IaITI0apMg=
100102
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
101103
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
102104
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
@@ -182,8 +184,10 @@ github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhso
182184
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
183185
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
184186
github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
185-
github.com/ulikunitz/xz v0.5.14 h1:uv/0Bq533iFdnMHZdRBTOlaNMdb1+ZxXIlHDZHIHcvg=
186-
github.com/ulikunitz/xz v0.5.14/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
187+
github.com/ulikunitz/xz v0.5.15 h1:9DNdB5s+SgV3bQ2ApL10xRc35ck0DuIX/isZvIk+ubY=
188+
github.com/ulikunitz/xz v0.5.15/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
189+
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
190+
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
187191
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
188192
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
189193
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=

0 commit comments

Comments
 (0)