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

[6.2] Backport packetbeat fixes #6776

Merged
merged 4 commits into from
Apr 6, 2018
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
4 changes: 4 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ https://github.com/elastic/beats/compare/v6.0.1...v6.1.0[View commits]
- Fix http parse to allow to parse get request with space in the URI. {pull}5495[5495]
- Fix mysql SQL parser to trim `\r` from Windows Server `SELECT\r\n\t1`. {pull}5572[5572]
- Fix corruption when parsing repeated headers in an HTTP request or response. {pull}6325[6325]
- Fix panic when parsing partial AMQP messages. {pull}6384[6384]
- Fix out of bounds access to slice in MongoDB parser. {pull}6256[6256]
- Fix sniffer hanging on exit under Linux. {pull}6535[6535]
- Fix bounds check error in http parser causing a panic. {pull}6750[6750]

*Winlogbeat*

Expand Down
2 changes: 1 addition & 1 deletion NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3259,7 +3259,7 @@ OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

--------------------------------------------------------------------
Dependency: github.com/tsg/gopacket
Revision: 8e703b9968693c15f25cabb6ba8be4370cf431d0
Revision: f289b3ea3e41a01b2822be9caf5f40c01fdda05c
License type (autodetected): BSD-3-Clause
./vendor/github.com/tsg/gopacket/LICENSE:
--------------------------------------------------------------------
Expand Down
5 changes: 4 additions & 1 deletion packetbeat/protos/amqp/amqp_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ func isProtocolHeader(data []byte) (isHeader bool, version string) {
//func to read a frame header and check if it is valid and complete
func readFrameHeader(data []byte) (ret *amqpFrame, err bool) {
var frame amqpFrame

if len(data) < 8 {
logp.Warn("Partial frame header, waiting for more data")
return nil, false
}
frame.size = binary.BigEndian.Uint32(data[3:7])
if len(data) < int(frame.size)+8 {
logp.Warn("Frame shorter than declared size, waiting for more data")
Expand Down
22 changes: 22 additions & 0 deletions packetbeat/protos/amqp/amqp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,28 @@ func TestAmqp_FrameSize(t *testing.T) {
}
}

// Test that the parser doesn't panic on a partial message that includes
// a client header
func TestAmqp_PartialFrameSize(t *testing.T) {
logp.TestingSetup(logp.WithSelectors("amqp", "amqpdetailed"))

_, amqp := amqpModForTests()

//incomplete frame
data, err := hex.DecodeString("414d515000060606010000000000")
assert.Nil(t, err)

stream := &amqpStream{data: data, message: new(amqpMessage)}
ok, complete := amqp.amqpMessageParser(stream)

if !ok {
t.Errorf("Parsing should not raise an error")
}
if complete {
t.Errorf("message should not be complete")
}
}

func TestAmqp_WrongShortStringSize(t *testing.T) {
logp.TestingSetup(logp.WithSelectors("amqp", "amqpdetailed"))

Expand Down
2 changes: 1 addition & 1 deletion packetbeat/protos/http/http_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (*parser) parseHTTPLine(s *stream, m *message) (cont, ok, complete bool) {
var version []byte
var err error
fline := s.data[s.parseOffset:i]
if len(fline) < 8 {
if len(fline) < 9 {
if isDebug {
debugf("First line too small")
}
Expand Down
3 changes: 3 additions & 0 deletions packetbeat/protos/mongodb/mongodb_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ func (d *decoder) readDocument() (bson.M, error) {
start := d.i
documentLength, err := d.readInt32()
d.i = start + documentLength
if len(d.in) < d.i {
return nil, errors.New("document out of bounds")
}

documentMap := bson.M{}

Expand Down
26 changes: 26 additions & 0 deletions packetbeat/protos/mongodb/mongodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,29 @@ func TestMaxDocSize(t *testing.T) {

assert.Equal(t, "\"1234 ...\n\"123\"\n\"12\"", res["response"])
}

// Test for a (recovered) panic parsing document length in request/response messages
func TestDocumentLengthBoundsChecked(t *testing.T) {
logp.TestingSetup(logp.WithSelectors("mongodb", "mongodbdetailed"))

_, mongodb := mongodbModForTests()

// request and response from tests/pcaps/mongo_one_row.pcap
reqData, err := hex.DecodeString(
// Request message with out of bounds document
"320000000a000000ffffffffd4070000" +
"00000000746573742e72667374617572" +
"616e7473000000000001000000" +
// Document length (including itself)
"06000000" +
// Document (1 byte instead of 2)
"00")
assert.Nil(t, err)

tcptuple := testTCPTuple()
req := protos.Packet{Payload: reqData}
private := protos.ProtocolData(new(mongodbConnectionData))

private = mongodb.Parse(&req, tcptuple, 0, private)
assert.NotNil(t, private, "mongodb parser recovered from a panic")
}
16 changes: 12 additions & 4 deletions vendor/github.com/tsg/gopacket/afpacket/afpacket.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vendor/github.com/tsg/gopacket/layers/lldp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion vendor/github.com/tsg/gopacket/pcap/pcap.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions vendor/github.com/tsg/gopacket/pcap/pcap_poll_common.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions vendor/github.com/tsg/gopacket/pcap/pcap_poll_linux.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -971,8 +971,8 @@
{
"checksumSHA1": "M0S9278lG9Fztu+ZUsLUi40GDJU=",
"path": "github.com/tsg/gopacket",
"revision": "8e703b9968693c15f25cabb6ba8be4370cf431d0",
"revisionTime": "2016-08-17T18:24:57Z"
"revision": "f289b3ea3e41a01b2822be9caf5f40c01fdda05c",
"revisionTime": "2018-03-16T21:03:30Z"
},
{
"checksumSHA1": "STY8i3sZLdZfFcKiyOdpV852nls=",
Expand Down