Skip to content

Commit 8b6cbe2

Browse files
updated layers pkg, added check for the number of records in tls to avoid false potitives
1 parent 0f1962f commit 8b6cbe2

File tree

3 files changed

+20
-24
lines changed

3 files changed

+20
-24
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/google/uuid v1.6.0
88
github.com/rs/zerolog v1.34.0
99
github.com/shadowy-pycoder/colors v0.0.1
10-
github.com/shadowy-pycoder/mshark v0.0.4
10+
github.com/shadowy-pycoder/mshark v0.0.5
1111
golang.org/x/net v0.40.0
1212
golang.org/x/sys v0.33.0
1313
golang.org/x/term v0.32.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
1919
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
2020
github.com/shadowy-pycoder/colors v0.0.1 h1:weCj/YIOupqy4BSP8KuVzr20fC+cuAv/tArz7bhhkP4=
2121
github.com/shadowy-pycoder/colors v0.0.1/go.mod h1:lkrJS1PY2oVigNLTT6pkbF7B/v0YcU2LD5PZnss1Q4U=
22-
github.com/shadowy-pycoder/mshark v0.0.4 h1:2yw6am1jt6n1GPHdLfFU1oDajv+zQ/23V0l0imFAeJY=
23-
github.com/shadowy-pycoder/mshark v0.0.4/go.mod h1:fRWGQuU4BFjz9pTfrvwIT2AtmWWd99PEvdlgv+24vTE=
22+
github.com/shadowy-pycoder/mshark v0.0.5 h1:D7L+vW6DsE/OMwxThQLenNJdHKHzufHFWGuL033GKhQ=
23+
github.com/shadowy-pycoder/mshark v0.0.5/go.mod h1:fRWGQuU4BFjz9pTfrvwIT2AtmWWd99PEvdlgv+24vTE=
2424
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
2525
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
2626
golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY=

gohpts.go

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -433,31 +433,27 @@ func (p *proxyapp) colorizeTunnel(req, resp layers.Layer, sniffheader *[]string,
433433
case *layers.TLSMessage:
434434
var chs *layers.TLSClientHello
435435
var shs *layers.TLSServerHello
436-
if len(reqt.Records) > 0 {
437-
hsrec := reqt.Records[0]
438-
if hsrec.ContentType == layers.HandshakeTLSVal { // TODO: add more cases, parse all records
439-
switch parser := layers.HSTLSParserByType(hsrec.Data[0]).(type) {
440-
case *layers.TLSClientHello:
441-
err := parser.ParseHS(hsrec.Data)
442-
if err != nil {
443-
return err
444-
}
445-
chs = parser
436+
hsrec := reqt.Records[0] // len(Records) > 0 after dispatch
437+
if hsrec.ContentType == layers.HandshakeTLSVal { // TODO: add more cases, parse all records
438+
switch parser := layers.HSTLSParserByType(hsrec.Data[0]).(type) {
439+
case *layers.TLSClientHello:
440+
err := parser.ParseHS(hsrec.Data)
441+
if err != nil {
442+
return err
446443
}
444+
chs = parser
447445
}
448446
}
449447
rest := resp.(*layers.TLSMessage)
450-
if len(rest.Records) > 0 {
451-
hsrec := rest.Records[0]
452-
if hsrec.ContentType == layers.HandshakeTLSVal {
453-
switch parser := layers.HSTLSParserByType(hsrec.Data[0]).(type) {
454-
case *layers.TLSServerHello:
455-
err := parser.ParseHS(hsrec.Data)
456-
if err != nil {
457-
return err
458-
}
459-
shs = parser
448+
hsrec = rest.Records[0]
449+
if hsrec.ContentType == layers.HandshakeTLSVal {
450+
switch parser := layers.HSTLSParserByType(hsrec.Data[0]).(type) {
451+
case *layers.TLSServerHello:
452+
err := parser.ParseHS(hsrec.Data)
453+
if err != nil {
454+
return err
460455
}
456+
shs = parser
461457
}
462458
}
463459
if chs != nil && shs != nil {
@@ -1045,7 +1041,7 @@ func dispatch(data []byte) (layers.Layer, error) {
10451041
return h, nil
10461042
}
10471043
m := &layers.TLSMessage{}
1048-
if err := m.Parse(data); err == nil {
1044+
if err := m.Parse(data); err == nil && len(m.Records) > 0 {
10491045
return m, nil
10501046
}
10511047
return nil, fmt.Errorf("failed sniffing traffic")

0 commit comments

Comments
 (0)