Skip to content

Commit

Permalink
Merge branch 'migrate-to-golang' of github.com:OWASP/OFFAT into migra…
Browse files Browse the repository at this point in the history
…te-to-golang
  • Loading branch information
dmdhrumilmistry committed Aug 27, 2024
2 parents f7dd43c + 9d2ad97 commit 3e3fa81
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cmd/offat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,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

0 comments on commit 3e3fa81

Please sign in to comment.