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 option to compute http BodySHA256 on decoded BodyText #275

Merged
merged 10 commits into from
Sep 18, 2020
Prev Previous commit
Next Next commit
Capture BodyTextLength
  • Loading branch information
twschum committed Sep 17, 2020
commit fc82b6b6733555c4af1ad55ae33fef82c0d26f76
2 changes: 2 additions & 0 deletions lib/http/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ type Response struct {
// BodyHash is the hash digest hex of the decoded http body, formatted `<kind>:<hex>`
// e.g. `sha256:deadbeef100020003000400050006000700080009000a000b000c000d000e000`
BodyHash string `json:"body_hash,omitempty"`
// Number of bytes read from the server and encoded into BodyText
BodyTextLength int64 `json:"body_length,omitempty"`

// ContentLength records the length of the associated content. The
// value -1 indicates that the length is unknown. Unless Request.Method
Expand Down
3 changes: 2 additions & 1 deletion modules/http/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,8 @@ func (scan *scan) Grab() *zgrab2.ScanError {
if resp.ContentLength >= 0 && resp.ContentLength < maxReadLen {
readLen = resp.ContentLength
}
io.CopyN(buf, resp.Body, readLen)
// EOF ignored here because that's the way it was, CopyN goes up to readLen bytes
scan.results.Response.BodyTextLength, _ = io.CopyN(buf, resp.Body, readLen)
bufAsString := buf.String()

// do best effort attempt to determine the response's encoding
Expand Down