(ctx context.Context, info *common.HostInfo, session *common.ScanSession)
| 140 | } |
| 141 | |
| 142 | func (p *MySQLPlugin) identifyService(ctx context.Context, info *common.HostInfo, session *common.ScanSession) *ScanResult { |
| 143 | target := info.Target() |
| 144 | |
| 145 | conn, err := session.DialTCP(ctx, "tcp", target, session.Config.Timeout) |
| 146 | if err != nil { |
| 147 | return &ScanResult{ |
| 148 | Success: false, |
| 149 | Service: "mysql", |
| 150 | Error: err, |
| 151 | } |
| 152 | } |
| 153 | defer func() { _ = conn.Close() }() |
| 154 | |
| 155 | if banner := p.readMySQLBanner(conn, session.Config); banner != "" { |
| 156 | common.LogSuccess(i18n.Tr("mysql_service", target, banner)) |
| 157 | return &ScanResult{ |
| 158 | Type: plugins.ResultTypeService, |
| 159 | Success: true, |
| 160 | Service: "mysql", |
| 161 | Banner: banner, |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | return &ScanResult{ |
| 166 | Success: false, |
| 167 | Service: "mysql", |
| 168 | Error: fmt.Errorf("无法识别为MySQL服务"), |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | func (p *MySQLPlugin) readMySQLBanner(conn net.Conn, config *common.Config) string { |
| 173 | _ = conn.SetReadDeadline(time.Now().Add(config.Timeout)) |
no test coverage detected