-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from cerberauth/trace-method-scan
feat: add http trace method scan
- Loading branch information
Showing
4 changed files
with
116 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package bestpractices | ||
|
||
import ( | ||
"github.com/cerberauth/vulnapi/internal/auth" | ||
restapi "github.com/cerberauth/vulnapi/internal/rest_api" | ||
"github.com/cerberauth/vulnapi/report" | ||
) | ||
|
||
const ( | ||
HTTPTraceMethodSeverityLevel = 1 | ||
HTTPTraceMethodVulnerabilityName = "HTTP Trace Method enabled" | ||
HTTPTraceMethodVulnerabilityDescription = "HTTP Trace method seems enabled for this request." | ||
) | ||
|
||
func HTTPTraceMethodScanHandler(o *auth.Operation, ss auth.SecurityScheme) (*report.ScanReport, error) { | ||
r := report.NewScanReport() | ||
newOperation := o.Clone() | ||
newOperation.Method = "TRACE" | ||
|
||
token := ss.GetValidValue().(string) | ||
ss.SetAttackValue(token) | ||
vsa := restapi.ScanRestAPI(&newOperation, ss) | ||
r.AddScanAttempt(vsa).End() | ||
|
||
if vsa.Response.StatusCode < 300 { | ||
r.AddVulnerabilityReport(&report.VulnerabilityReport{ | ||
SeverityLevel: HTTPTraceMethodSeverityLevel, | ||
Name: HTTPTraceMethodVulnerabilityName, | ||
Description: HTTPTraceMethodVulnerabilityDescription, | ||
Url: o.Url, | ||
}) | ||
} | ||
|
||
return r, nil | ||
} |
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,59 @@ | ||
package bestpractices_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cerberauth/vulnapi/internal/auth" | ||
"github.com/cerberauth/vulnapi/report" | ||
bestpractices "github.com/cerberauth/vulnapi/scan/best_practices" | ||
"github.com/jarcoal/httpmock" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestHTTPTraceMethodScanHandler(t *testing.T) { | ||
httpmock.Activate() | ||
defer httpmock.DeactivateAndReset() | ||
|
||
token := "token" | ||
securityScheme := auth.NewAuthorizationBearerSecurityScheme("default", &token) | ||
o := auth.Operation{ | ||
Method: "GET", | ||
Url: "http://localhost:8080/", | ||
} | ||
|
||
httpmock.RegisterResponder("TRACE", o.Url, httpmock.NewBytesResponder(405, nil)) | ||
|
||
report, err := bestpractices.HTTPTraceMethodScanHandler(&o, securityScheme) | ||
|
||
require.NoError(t, err) | ||
assert.Equal(t, 1, httpmock.GetTotalCallCount()) | ||
assert.False(t, report.HasVulnerabilityReport()) | ||
} | ||
|
||
func TestHTTPTraceMethodWhenTraceIsEnabledScanHandler(t *testing.T) { | ||
httpmock.Activate() | ||
defer httpmock.DeactivateAndReset() | ||
|
||
token := "token" | ||
securityScheme := auth.NewAuthorizationBearerSecurityScheme("default", &token) | ||
o := auth.Operation{ | ||
Method: "GET", | ||
Url: "http://localhost:8080/", | ||
} | ||
vulnerabilityReport := report.VulnerabilityReport{ | ||
SeverityLevel: bestpractices.HTTPTraceMethodSeverityLevel, | ||
Name: bestpractices.HTTPTraceMethodVulnerabilityName, | ||
Description: bestpractices.HTTPTraceMethodVulnerabilityDescription, | ||
Url: o.Url, | ||
} | ||
|
||
httpmock.RegisterResponder("TRACE", o.Url, httpmock.NewBytesResponder(204, nil)) | ||
|
||
report, err := bestpractices.HTTPTraceMethodScanHandler(&o, securityScheme) | ||
|
||
require.NoError(t, err) | ||
assert.Equal(t, 1, httpmock.GetTotalCallCount()) | ||
assert.True(t, report.HasVulnerabilityReport()) | ||
assert.Equal(t, report.GetVulnerabilityReports()[0], &vulnerabilityReport) | ||
} |