Skip to content

Commit f2a5b4e

Browse files
committed
update
1 parent 257d36c commit f2a5b4e

File tree

7 files changed

+73
-19
lines changed

7 files changed

+73
-19
lines changed

cmd/decode.go

+14-9
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package cmd
33
import (
44
"fmt"
55
"os"
6+
"encoding/json"
67

78
"github.com/dgrijalva/jwt-go"
89
jwtInterface "github.com/hahwul/jwt-hack/pkg/jwt"
910

1011
//. "github.com/logrusorgru/aurora"
1112
"github.com/spf13/cobra"
13+
"github.com/sirupsen/logrus"
1214
)
1315

1416
// decodeCmd represents the decode command
@@ -18,17 +20,20 @@ var decodeCmd = &cobra.Command{
1820
Run: func(cmd *cobra.Command, args []string) {
1921
if len(args) >= 1 {
2022
var token *jwt.Token
23+
var log = logrus.New()
24+
log.Out = os.Stdout
2125
token = jwtInterface.JWTdecode(args[0])
22-
fmt.Fprintln(os.Stderr, "[ Raw data ]")
23-
fmt.Println(token.Raw)
24-
fmt.Fprintln(os.Stderr, "[ Method ]")
25-
fmt.Println(token.Method)
26-
fmt.Fprintln(os.Stderr, "[ Headers ]")
27-
fmt.Println(token.Header)
28-
fmt.Fprintln(os.Stderr, "[ Claims ]")
29-
fmt.Println(token.Claims)
26+
header,_ := json.Marshal(token.Header)
27+
log.WithFields(logrus.Fields{
28+
"method": token.Method,
29+
"header": string(header),
30+
}).Info("Decoded data(claims)")
31+
data,_ := json.Marshal(token.Claims)
32+
fmt.Println(string(data))
3033
} else {
31-
34+
var log = logrus.New()
35+
log.Out = os.Stdout
36+
log.Error("Arguments Error")
3237
}
3338
},
3439
}

cmd/encode.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
jwtInterface "github.com/hahwul/jwt-hack/pkg/jwt"
88
"github.com/spf13/cobra"
9+
log "github.com/sirupsen/logrus"
910
)
1011

1112
var secret, algo string
@@ -20,11 +21,15 @@ var encodeCmd = &cobra.Command{
2021
var raw map[string]interface{}
2122
if err := json.Unmarshal(mapInterface, &raw); err != nil {
2223
// err
24+
log.Error("JSON Unmarshal Error")
25+
panic(0)
2326
}
27+
log.WithFields(log.Fields{
28+
"algorithm": algo,
29+
}).Info("Encoded result")
2430
fmt.Println(jwtInterface.JWTencode(raw, secret, algo))
25-
2631
} else {
27-
32+
log.Error("Arguments Error")
2833
}
2934
},
3035
}

pkg/crack/crack.go

+16-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ package crack
22

33
import (
44
"fmt"
5-
"strconv"
65
"sync"
6+
"os"
77

88
jwtInterface "github.com/hahwul/jwt-hack/pkg/jwt"
9-
. "github.com/logrusorgru/aurora"
9+
"github.com/sirupsen/logrus"
1010
)
1111

12+
var log = logrus.New()
13+
1214
func Crack(mode, token, data string, concurrency, max int, power bool) {
15+
log.Out = os.Stdout
1316
fmt.Println("[*] Start " + mode + " cracking mode")
1417
if mode == "brute" {
1518
bf := GenerateBruteforcePayloads(data)
@@ -24,7 +27,9 @@ func Crack(mode, token, data string, concurrency, max int, power bool) {
2427

2528
// Remove Deplicated value
2629
words = unique(words)
27-
fmt.Println("[*] Loaded " + strconv.Itoa(len(words)) + " words (remove duplicated)")
30+
log.WithFields(logrus.Fields{
31+
"size": len(words),
32+
}).Info("Loaded words (remove duplicated)")
2833
RunTestingJWT(token, words, concurrency)
2934
}
3035
}
@@ -46,11 +51,17 @@ func RunTestingJWT(token string, lists []string, concurrency int) {
4651
result, token := jwtInterface.JWTdecodeWithVerify(token, word)
4752
_ = token
4853
if result {
49-
fmt.Println(Sprintf(Green("[+] Signature Verified / Found! This JWT Token signature secret is %s"), Cyan(word)))
54+
log.WithFields(logrus.Fields{
55+
"Signature": "Verified",
56+
"Word": word,
57+
}).Info("Found! This JWT Token signature secret is.. ")
58+
fmt.Println(word)
5059
found <- true
5160

5261
} else {
53-
fmt.Println("[-] Signature Invaild / " + word)
62+
log.WithFields(logrus.Fields{
63+
"word": word,
64+
}).Info("Invalid signature")
5465
}
5566
}
5667
}

pkg/payload/payload.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@ package paylaod
33
import (
44
b64 "encoding/base64"
55
"fmt"
6+
"os"
67
"strings"
78

89
"github.com/dgrijalva/jwt-go"
10+
"github.com/sirupsen/logrus"
911
)
1012

13+
var log = logrus.New()
14+
1115
// GenerateAllPayloads is printing all payloads
1216
func GenerateAllPayloads(token *jwt.Token) {
17+
log.Out = os.Stdout
1318
GenerateNonePayloads(token.Raw)
1419
GenerateUrlPayloads(token.Raw)
1520
}
@@ -28,7 +33,11 @@ func GenerateNonePayloads(token string) {
2833
_ = k
2934
header := "{\"alg\":\"" + v + "\",\"typ\":\"JWT\"}"
3035
baseHeader := b64.StdEncoding.EncodeToString([]byte(header))
31-
fmt.Println("[" + v + "] " + baseHeader + "." + claims + ".")
36+
log.WithFields(logrus.Fields{
37+
"payload": v,
38+
"header": header,
39+
}).Info("Generate "+v+" payload")
40+
fmt.Println(baseHeader + "." + claims + ".")
3241
}
3342

3443
}
@@ -46,7 +55,11 @@ func GenerateUrlPayloads(token string) {
4655
_ = k
4756
header := "{\"alg\":\"hs256\",\"" + v + "\":\"https://www.google.com\",\"typ\":\"JWT\"}"
4857
baseHeader := b64.StdEncoding.EncodeToString([]byte(header))
49-
fmt.Println("[" + v + "] " + baseHeader + "." + claims + ".")
58+
log.WithFields(logrus.Fields{
59+
"payload": v,
60+
"header": header,
61+
}).Info("Generate "+v+" payload")
62+
fmt.Println(baseHeader + "." + claims + ".")
5063
}
5164

5265
}

pkg/printing/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package printing
22

3-
const VERSION = "v0.0.1"
3+
const VERSION = "v1.0.0"

samples/jwt.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.5mhBHqs5_DTLdINd9p5m7ZJ6XD0Xc55kIaCRY5r6HRA

samples/wordlist.txt

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
1234
2+
ds
3+
fas
4+
df
5+
asdf
6+
asd
7+
ga
8+
2q
9+
efq
10+
f
11+
qsf
12+
sad
13+
f
14+
test
15+
zx
16+
dfas
17+
df
18+
asdf
19+
sadf

0 commit comments

Comments
 (0)