| 1 | package syn_scan |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "time" |
| 6 | |
| 7 | "github.com/evilsocket/islazy/async" |
| 8 | ) |
| 9 | |
| 10 | const bannerGrabTimeout = time.Duration(5) * time.Second |
| 11 | |
| 12 | type bannerGrabberFn func(mod *SynScanner, ip string, port int) string |
| 13 | |
| 14 | type grabberJob struct { |
| 15 | IP string |
| 16 | Port *OpenPort |
| 17 | } |
| 18 | |
| 19 | func (mod *SynScanner) bannerGrabber(arg async.Job) { |
| 20 | job := arg.(grabberJob) |
| 21 | if job.Port.Proto != "tcp" { |
| 22 | return |
| 23 | } |
| 24 | |
| 25 | ip := job.IP |
| 26 | port := job.Port.Port |
| 27 | sport := fmt.Sprintf("%d", port) |
| 28 | |
| 29 | fn := tcpGrabber |
| 30 | if port == 80 || port == 443 || sport[0] == '8' { |
| 31 | fn = httpGrabber |
| 32 | } else if port == 53 || port == 5353 { |
| 33 | fn = dnsGrabber |
| 34 | } |
| 35 | |
| 36 | mod.Debug("grabbing banner for %s:%d", ip, port) |
| 37 | job.Port.Banner = fn(mod, ip, port) |
| 38 | if job.Port.Banner != "" { |
| 39 | mod.Info("found banner for %s:%d -> %s", ip, port, job.Port.Banner) |
| 40 | } |
| 41 | } |