package telnet import ( "git.loafle.net/overflow/overflow_discovery/service/matcher" ) const ( DO = 0xfd WONT = 0x4b WILL = 0xfb DONT = 0xfe CMD = 0xff ) type TelnetMatcher struct { matcher.Matchers } func (tel *TelnetMatcher) ServiceName() string { return "Telnet" } func (tel *TelnetMatcher) IsPrePacket() bool { return true } func (tel *TelnetMatcher) HasResponse(index int) bool { return true } func (tel *TelnetMatcher) IsError(info matcher.MatchInfo, index int, packet *matcher.Packet) bool { return false } func (tel *TelnetMatcher) Match(info matcher.MatchInfo, index int, packet *matcher.Packet) bool { result := false if packet == nil || packet.Buffer == nil || packet.Len == 0 { return result } buf := make([]byte, 0, 0) count := 0 for i := 0; i < len(packet.Buffer); i++ { if packet.Buffer[i] > 0 { buf = append(buf, packet.Buffer[i]) } else if count > 2 { break } else { count++ } } for idx := 0; idx < len(buf); idx += 3 { if buf[idx] == CMD && (buf[idx+1] == DO || buf[idx+1] == WONT || buf[idx+1] == WILL || buf[idx+1] == DONT) { result = true } else { result = false } } return result } func NewMatcher() matcher.Matcher { m := &TelnetMatcher{} return m }