pgsql matcher bug fix
This commit is contained in:
parent
c537ea0af8
commit
ce43ef3550
|
@ -5,6 +5,7 @@ import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"loafle.com/overflow/commons_go/matcher/packet"
|
"loafle.com/overflow/commons_go/matcher/packet"
|
||||||
"loafle.com/overflow/commons_go/model/scaninfo"
|
"loafle.com/overflow/commons_go/model/scaninfo"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -40,6 +41,18 @@ type pgsqlErrResponse struct {
|
||||||
Message [53]byte
|
Message [53]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type pgsqlErrResponse2 struct {
|
||||||
|
ResponseType uint8
|
||||||
|
Len [4]byte
|
||||||
|
Data [128]byte
|
||||||
|
//Severity [6]byte
|
||||||
|
//_ byte
|
||||||
|
//Code [6]byte
|
||||||
|
//_ byte
|
||||||
|
//Message [53]byte
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
type PostgreSQLMatcher struct {
|
type PostgreSQLMatcher struct {
|
||||||
packets []*packet.Packet
|
packets []*packet.Packet
|
||||||
}
|
}
|
||||||
|
@ -133,7 +146,7 @@ func (t *PostgreSQLMatcher) Match(index int, packet *packet.Packet, info scaninf
|
||||||
reader := new(bytes.Buffer)
|
reader := new(bytes.Buffer)
|
||||||
reader.Write(packet.Buffer)
|
reader.Write(packet.Buffer)
|
||||||
|
|
||||||
pg := pgsqlErrResponse{}
|
pg := pgsqlErrResponse2{}
|
||||||
if err := binary.Read(reader, binary.BigEndian, &pg); err != nil {
|
if err := binary.Read(reader, binary.BigEndian, &pg); err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -142,14 +155,29 @@ func (t *PostgreSQLMatcher) Match(index int, packet *packet.Packet, info scaninf
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
severity := string(pg.Severity[1:])
|
length := binary.BigEndian.Uint32(pg.Len[:])
|
||||||
if severity != "FATAL" && severity != "ERROR" {
|
if length + 1 != uint32(packet.Len) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
data := string(pg.Data[:])
|
||||||
|
splits := strings.Split(data, "\x00")
|
||||||
|
|
||||||
|
var findSeverity bool = false
|
||||||
|
var findErrorCode bool = false
|
||||||
|
for _, s := range splits {
|
||||||
|
if strings.Contains(s, "FATAL") {
|
||||||
|
findSeverity = true;
|
||||||
|
}
|
||||||
|
if strings.Contains(s, "28000") {
|
||||||
|
findErrorCode = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !findSeverity || !findErrorCode {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if string(pg.Code[1:]) != "28000" {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
func TestPG(t *testing.T) {
|
func TestPG(t *testing.T) {
|
||||||
m := NewPostgreSQLMatcher()
|
m := NewPostgreSQLMatcher()
|
||||||
|
|
||||||
conn, err := net.Dial("tcp", "192.168.1.88:5432") //107
|
conn, err := net.Dial("tcp", "192.168.1.106:5432") //107
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue
Block a user