Skip to content

Commit

Permalink
fix bug where does not read jwt count correctly as jwt count of 10 ui…
Browse files Browse the repository at this point in the history
…nt64 format contains new line ascii code
  • Loading branch information
dominicriordan committed Apr 28, 2023
1 parent c164908 commit 7d37c3f
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ server_*
*.qlog
gopayloader.exe
gopayloader.zip
gopayloader-darwin-amd64
gopayloader-linux-amd64
gopayloader-windows-amd64.exe
5 changes: 5 additions & 0 deletions build-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

GOOS=windows go build -o gopayloader-windows-amd64.exe ./
GOOS=linux go build -o gopayloader-linux-amd64 ./
GOOS=darwin go build -o gopayloader-darwin-amd64 ./
14 changes: 8 additions & 6 deletions pkgs/jwt-generator/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ func newCache(f *os.File) (*cache, error) {
c.scanner = bufio.NewScanner(c.f)
c.scanner.Split(bufio.ScanLines)
if c.scanner.Scan() {
meta := c.scanner.Bytes()
if len(meta) < 8 {
return nil, fmt.Errorf("jwt_generator: corrupt jwt cache, wanted 8 bytes got %d", len(meta))
bb := make([]byte, 8)
_, err := f.ReadAt(bb, 0)
if err != nil {
return nil, err
}
c.count = int64(binary.LittleEndian.Uint64(meta[0:8]))

c.count = int64(binary.LittleEndian.Uint64(bb))
return &c, nil
}
return &c, nil
Expand Down Expand Up @@ -115,11 +115,13 @@ func (c *cache) save(tokens []string) error {
}

b := make([]byte, 8)
binary.LittleEndian.PutUint64(b, uint64(int64(add)+c.count))
newCount := uint64(int64(add) + c.count)
binary.LittleEndian.PutUint64(b, newCount)
_, err = c.f.WriteAt(b, 0)
if err != nil {
return err
}

_, err = c.f.WriteAt([]byte{byte('\n')}, 9)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkgs/jwt-generator/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (j *JWTGenerator) Generate(reqJwtCount int64, dir string, retrying bool) er
return err
}
f.Close()
pterm.Error.Printf("jwt cache %s file corrupt, attempting to delete and recreate", fname)
pterm.Debug.Printf("jwt cache %s file corrupt, attempting to delete and recreate; got error; %v \n", fname, err)
if err := os.Remove(fname); err != nil {
pterm.Error.Printf("Couldn't remove cache file %s; %v", fname, err)
return err
Expand Down
39 changes: 39 additions & 0 deletions pkgs/payloader/payloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,45 @@ func testPayLoader_Run(t *testing.T, addr, client string) {
}
},
},
{
name: "GET RSA JWT",
fields: fields{config: &config.Config{
Ctx: context.Background(),
ReqURI: addr,
ReqTarget: 10,
Conns: 1,
ReadTimeout: 5 * time.Second,
WriteTimeout: 5 * time.Second,
Method: "GET",
Client: client,
VerboseTicker: time.Second,
Headers: []string{"content-type: application/json"},
JwtHeader: "some-jwt",
JwtAud: "some-aud",
JwtSub: "some-subject",
JwtIss: "some-issuer",
JwtKID: "13325575tevdfbdsfsf",
JwtKey: filepath.Join("..", "..", "test", "rsa.private"),
SkipVerify: true,
}},
want: &GoPayloaderResults{
CompletedReqs: 10,
FailedReqs: 0,
Responses: map[worker.ResponseCode]int64{
200: 10,
},
Errors: nil,
},
check: func(t *testing.T) {
_, err := os.OpenFile(filepath.Join(JwtCacheDir, "gopayloader-jwtstore-ce2db7adfae3270cb01fd7053b035243213d6e6bbd9ea917ee656eacb94e22e2.txt"), os.O_RDONLY, os.ModePerm)
if err != nil {
if os.IsNotExist(err) {
t.Fatal(err)
}
t.Fatal(err)
}
},
},
{
name: "Error hostname incorrect format - missing port",
fields: fields{config: &config.Config{
Expand Down
15 changes: 15 additions & 0 deletions test/rsa.private
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDShDiKX/Lexe5b0Ew4FE/puWYiKuSHQgsa1D0EJurpUY4BIEe6
EdYHtPq2Vv2xT1xOCQEKSd8BwOu78btVsrTCPPkJw7+ll9DZSDAjbesE1n15/aCW
FaO9myWM5O+RQ0HXAHACL5BWFNAvAoyD+JR9Yw1Z+7cHIPKiwDBgD42KKwIDAQAB
AoGAWciYkLOxUr/aFAB3sWdAWe9/lszyYJmTQOMKDu5GPDJTPTm2Pa6DuQ+/6eqa
EnhFZubCMdAls4rDP4oumrM4EeTJ+wogKOyQ8m7iZIxVl/dpPBd1RaC6nSVM7J+o
t3LhhssVQ/o9TF/dwk1WmKPFwtmyI1scUyYzuZ2ouTznXtkCQQD9I6mAac+EgU6Q
ZtS+iFnKe4l1vzrf5/uYr+3Gm1eqcRX5q09PyolwJUoi8wB8K1UQBRFWpHxC14EW
aBa2LOenAkEA1OU//HPuj0SrlzgNefEoygjG0vPNLtyvaKBNeuBdNdqaUL5/Yywz
ArWzMdtGTR6poBO2rWjx6yY+LjLLz8vZ3QJBAKWAi3HJvEOFxzfiA3YO76XS3yx8
uqFpqrVJUMxpBAgLp7J0roYchX8s4iu3dLm6GwM+TPe40wVgoKVlqHOzKEECQFRX
Gbk+iFSzpLK8nwIfGsSnI3Uw5qlY/hiZ4Pf76JFML/Qq87ZrLS42o23t63Tj39kt
1iHuwGAi/2E3+Gwy2vUCQQC4VHT+5z2qHMngQgDBg3N6hfg3FBQ4wDCvsiZVeE1o
VXSt148WA4oAPPMwNettx7KK9uWQsNysaIoq1uJX9AoR
-----END RSA PRIVATE KEY-----

0 comments on commit 7d37c3f

Please sign in to comment.