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

add bola trailing path test #135

Merged
merged 1 commit into from
Aug 26, 2024
Merged
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
1 change: 1 addition & 0 deletions src/cmd/offat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func main() {
RunXssHtmlInjectionTest: true,
RunSstiInjectionTest: true,
RunBolaTest: true,
RunBolaTrailingPathTest: true,

// SSRF Test
SsrfUrl: *config.SsrfUrl,
Expand Down
44 changes: 44 additions & 0 deletions src/pkg/tgen/bola.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package tgen

import (
"path"
"strconv"
"strings"

"github.com/OWASP/OFFAT/src/pkg/fuzzer"
"github.com/OWASP/OFFAT/src/pkg/parser"
"github.com/OWASP/OFFAT/src/pkg/utils"
c "github.com/dmdhrumilmistry/fasthttpclient/client"
Expand Down Expand Up @@ -38,3 +43,42 @@ func BolaTest(baseUrl string, docParams []*parser.DocHttpParams, queryParams map

return tests
}

func BolaTrailingPathTest(baseUrl string, docParams []*parser.DocHttpParams, queryParams map[string]string, headers map[string]string) []*ApiTest {
var tests []*ApiTest
testName := "BOLA Trailing Path Test"
immuneResponseCode := []int{404, 405} // 502, 503, 504 -> responses could lead to DoS using the endpoint

for _, docParam := range docParams {
url, headersMap, queryMap, bodyData, pathWithParams, err := httpParamToRequest(baseUrl, docParam, queryParams, headers, utils.JSON)
if err != nil {
log.Error().Err(err).Msgf("failed to generate request params from DocHttpParams, skipping test for this case %v due to error %v", *docParam, err)
continue
}

randNum, err := fuzzer.GenerateRandomIntInRange(1, 1000)
if err != nil {
log.Error().Err(err).Msgf("failed to generate random id for Trailing BOLA Path Test, skipping test generation for this case %v due to error %v", *docParam, err)
continue
}
randomId := strconv.Itoa(randNum)

// add random digit as id at the end of current path
uriPath := path.Join(docParam.Path, randomId)
url = strings.ReplaceAll(path.Join(url, randomId), ":/", "://")

// prepare test request
request := c.NewRequest(url, docParam.HttpMethod, queryMap, headersMap, bodyData)

test := ApiTest{
TestName: testName,
Request: request,
Path: uriPath,
PathWithParams: pathWithParams,
ImmuneResponseCodes: immuneResponseCode,
}
tests = append(tests, &test)
}

return tests
}
9 changes: 9 additions & 0 deletions src/pkg/tgen/tgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type TGenHandler struct {
RunXssHtmlInjectionTest bool
RunSstiInjectionTest bool
RunBolaTest bool
RunBolaTrailingPathTest bool

// SSRF Test related data
SsrfUrl string
Expand All @@ -45,6 +46,14 @@ func (t *TGenHandler) GenerateTests() []*ApiTest {
log.Info().Msgf("%d tests generated for BOLA", len(newTests))
}

// BOLA Trailing Path Test
if t.RunBolaTest {
newTests := BolaTrailingPathTest(t.BaseUrl, t.Doc, t.DefaultQueryParams, t.DefaultHeaders)
tests = append(tests, newTests...)

log.Info().Msgf("%d tests generated for BOLA Trailing Path", len(newTests))
}

// Basic SQLI Test
if t.RunBasicSQLiTest {
injectionConfig := InjectionConfig{
Expand Down
Loading