(reader utils.StringReader)
| 299 | } |
| 300 | |
| 301 | func descriptorsFromReader(reader utils.StringReader) map[string][]objectDescriptor { |
| 302 | descriptors := make(map[string][]objectDescriptor) |
| 303 | hashPattern := regexp.MustCompile("[0-9a-fA-F]{32,64}") |
| 304 | urlPattern := regexp.MustCompile("[hH][tTxX]{2}[pP][sS]?://.*") |
| 305 | // At least two domain parts. |
| 306 | domainPattern := regexp.MustCompile(".*[^.]+\\.[^.]+.*") |
| 307 | for { |
| 308 | next, err := reader.ReadString() |
| 309 | if err == io.EOF { |
| 310 | break |
| 311 | } |
| 312 | if match := hashPattern.MatchString(next); match { |
| 313 | files := descriptors["files"] |
| 314 | files = append(files, objectDescriptor{ |
| 315 | Type: "file", |
| 316 | Id: next, |
| 317 | }) |
| 318 | descriptors["files"] = files |
| 319 | } else if net.ParseIP(next) != nil { |
| 320 | if strings.Contains(next, ".") { |
| 321 | ipAddresses := descriptors["ip_addresses"] |
| 322 | ipAddresses = append(ipAddresses, objectDescriptor{ |
| 323 | Type: "ip_address", |
| 324 | Id: next, |
| 325 | }) |
| 326 | descriptors["ip_addresses"] = ipAddresses |
| 327 | } else { |
| 328 | // IPv6, skip. |
| 329 | } |
| 330 | } else if urlPattern.MatchString(next) { |
| 331 | urls := descriptors["urls"] |
| 332 | urls = append(urls, objectDescriptor{ |
| 333 | Type: "url", |
| 334 | Url: next, |
| 335 | }) |
| 336 | descriptors["urls"] = urls |
| 337 | } else if domainPattern.MatchString(next) { |
| 338 | domains := descriptors["domains"] |
| 339 | domains = append(domains, objectDescriptor{ |
| 340 | Type: "domain", |
| 341 | Id: next, |
| 342 | }) |
| 343 | descriptors["domains"] = domains |
| 344 | } |
| 345 | } |
| 346 | return descriptors |
| 347 | } |
no test coverage detected