Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better testID communication #265

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions internal/db/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package db

import (
"encoding/csv"
"github.com/wallarm/gotestwaf/internal/helpers"
"os"
"strconv"

Expand All @@ -27,6 +28,7 @@ func (db *DB) ExportPayloads(payloadsExportFile string) error {
"Set",
"Case",
"Test Result",
"Test Key",
}); err != nil {
return err
}
Expand Down Expand Up @@ -54,6 +56,7 @@ func (db *DB) ExportPayloads(payloadsExportFile string) error {
blockedTest.Set,
blockedTest.Case,
testResult,
helpers.HexOfHashOfTestIdentifier(blockedTest.Set, blockedTest.Case, blockedTest.Placeholder, blockedTest.Encoder, blockedTest.Payload),
})
if err != nil {
return err
Expand Down Expand Up @@ -83,6 +86,7 @@ func (db *DB) ExportPayloads(payloadsExportFile string) error {
passedTest.Set,
passedTest.Case,
testResult,
helpers.HexOfHashOfTestIdentifier(passedTest.Set, passedTest.Case, passedTest.Placeholder, passedTest.Encoder, passedTest.Payload),
})
if err != nil {
return err
Expand All @@ -107,6 +111,7 @@ func (db *DB) ExportPayloads(payloadsExportFile string) error {
naTest.Set,
naTest.Case,
"unknown",
helpers.HexOfHashOfTestIdentifier(naTest.Set, naTest.Case, naTest.Placeholder, naTest.Encoder, naTest.Payload),
})
if err != nil {
return err
Expand Down
18 changes: 18 additions & 0 deletions internal/helpers/HexHash.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package helpers

import (
"crypto/sha256"
"encoding/hex"
)

func HexOfHashOfTestIdentifier(testSet string, testCase string, placeholder string, encoder string, payload string) string {
hash := sha256.New()
hash.Reset()
hash.Write([]byte(testSet))
hash.Write([]byte(testCase))
hash.Write([]byte(placeholder))
hash.Write([]byte(encoder))
hash.Write([]byte(payload))

return hex.EncodeToString(hash.Sum(nil)) // Return the hexadecimal string representation
}
14 changes: 1 addition & 13 deletions internal/scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package scanner
import (
"bytes"
"context"
"crypto/sha256"
"encoding/hex"
"fmt"
"io"
"math/rand"
Expand Down Expand Up @@ -478,22 +476,12 @@ func (s *Scanner) produceTests(ctx context.Context, n int) <-chan *payloadConfig

var debugHeaderValue string

hash := sha256.New()

for _, testCase := range testCases {
for _, payload := range testCase.Payloads {
for _, encoder := range testCase.Encoders {
for _, placeholder := range testCase.Placeholders {
if s.enableDebugHeader {
hash.Reset()

hash.Write([]byte(testCase.Set))
hash.Write([]byte(testCase.Name))
hash.Write([]byte(placeholder.Name))
hash.Write([]byte(encoder))
hash.Write([]byte(payload))

debugHeaderValue = hex.EncodeToString(hash.Sum(nil))
debugHeaderValue = testCase.Set + " /// " + testCase.Name + " /// " + placeholder.Name + " /// " + encoder + " /// " + helpers.HexOfHashOfTestIdentifier(testCase.Set, testCase.Name, placeholder.Name, encoder, payload)
} else {
debugHeaderValue = ""
}
Expand Down