-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
838f340
commit cda96f2
Showing
9 changed files
with
158 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
package tgen | ||
|
||
type TestSchema struct { | ||
TestName string | ||
import "github.com/dmdhrumilmistry/fasthttpclient/client" | ||
|
||
// Holds data related for API testing | ||
type ApiTests struct { | ||
// Fields to be populated before making HTTP request | ||
TestName string | ||
Request *client.Request | ||
|
||
// Fields to be populated after making HTTP request | ||
IsVulnerable bool | ||
IsDataLeak bool | ||
Request interface{} | ||
Response interface{} | ||
Response *client.Response | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package tgen | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/OWASP/OFFAT/src/pkg/http" | ||
_ "github.com/OWASP/OFFAT/src/pkg/logging" | ||
"github.com/OWASP/OFFAT/src/pkg/parser" | ||
c "github.com/dmdhrumilmistry/fasthttpclient/client" | ||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
type TGenHandler struct { | ||
RunUnrestrictedHttpMethodTest bool | ||
|
||
Doc []*parser.DocHttpParams | ||
DefaultQueryParams map[string]string | ||
DefaultHeaders map[string]string | ||
} | ||
|
||
func (t *TGenHandler) GenerateTests() []*ApiTests { | ||
tests := []*ApiTests{} | ||
if t.RunUnrestrictedHttpMethodTest { | ||
newTests := UnrestrictedHttpMethods(t.Doc, t.DefaultQueryParams, t.DefaultHeaders) | ||
tests = append(tests, newTests...) | ||
|
||
log.Info().Msgf("%d tests generated for Unrestricted HTTP Methods/Verbs", len(newTests)) | ||
} | ||
|
||
return tests | ||
} | ||
|
||
func (t *TGenHandler) RunApiTests(hc *http.Http, client c.ClientInterface, apiTests []*ApiTests) { | ||
// generate requests | ||
for _, apiTest := range apiTests { | ||
hc.Requests = append(hc.Requests, apiTest.Request) | ||
} | ||
|
||
// make requests to the server concurrently | ||
hc.Responses = c.MakeConcurrentRequests(hc.Requests, client) | ||
fmt.Print("\n") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,42 @@ | ||
// Tests for unrestricted HTTP methods/verbs | ||
package tgen | ||
|
||
// use parser.DocHttpParams. | ||
import ( | ||
"encoding/json" | ||
|
||
_ "github.com/OWASP/OFFAT/src/pkg/logging" | ||
"github.com/OWASP/OFFAT/src/pkg/parser" | ||
c "github.com/dmdhrumilmistry/fasthttpclient/client" | ||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
// returns a new map with k:parser.DocHttpParams.Name, v:parser.DocHttpParams.Value | ||
func UnrestrictedHttpMethods(docParams []*parser.DocHttpParams, queryParams any, headers any) []*ApiTests { | ||
var tests []*ApiTests | ||
testName := "Unrestricted HTTP Methods/Verbs" | ||
|
||
for _, docParam := range docParams { | ||
bodyMap := ParamsToMap(docParam.BodyParams) // convert it to map[string]interface{} | ||
|
||
// convert it to JSON | ||
jsonData, err := json.Marshal(bodyMap) | ||
if err != nil { | ||
log.Error().Stack().Err(err).Msg("failed to convert bodyMap to JSON") | ||
} else { | ||
jsonData = nil | ||
} | ||
|
||
// TODO: negate HTTP methods and add it to requests | ||
// currently below request is only for testing purpose | ||
log.Print(docParam.Url) | ||
request := c.NewRequest(docParam.Url, docParam.HttpMethod, queryParams, headers, jsonData) | ||
|
||
test := ApiTests{ | ||
TestName: testName, | ||
Request: request, | ||
} | ||
tests = append(tests, &test) | ||
} | ||
|
||
return tests | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package tgen | ||
|
||
import "github.com/OWASP/OFFAT/src/pkg/parser" | ||
|
||
// convert parser.Param to map | ||
func ParamsToMap(params []parser.Param) map[string]interface{} { | ||
paramMap := make(map[string]interface{}) | ||
|
||
for _, param := range params { | ||
paramMap[param.Name] = param.Value | ||
} | ||
|
||
return paramMap | ||
} |