MCPcopy
hub / github.com/projectdiscovery/proxify / Run

Method Run

proxy.go:402–465  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

400}
401
402func (p *Proxy) Run() error {
403 var wg sync.WaitGroup
404
405 if p.tinydns != nil {
406 wg.Add(1)
407 go func() {
408 defer wg.Done()
409 if err := p.tinydns.Run(); err != nil {
410 gologger.Warning().Msgf("Could not start dns server: %s\n", err)
411 }
412 }()
413 }
414
415 // http proxy
416 if p.httpProxy != nil {
417 p.httpProxy.TLSPassthroughFunc = func(req *http.Request) bool {
418 // Skip MITM for hosts that are in pass-through list
419 return util.MatchAnyRegex(p.options.PassThrough, req.Host)
420 }
421
422 p.httpProxy.SetRequestModifier(p)
423 p.httpProxy.SetResponseModifier(p)
424
425 l, err := net.Listen("tcp", p.options.ListenAddrHTTP)
426 if err != nil {
427 gologger.Fatal().Msgf("failed to setup listener got %v", err)
428 }
429 p.listenAddr = l.Addr().String()
430 wg.Add(1)
431 go func() {
432 defer wg.Done()
433 gologger.Fatal().Msgf("%v", p.httpProxy.Serve(l))
434 }()
435 }
436
437 // socks5 proxy
438 if p.socks5proxy != nil {
439 if p.httpProxy != nil {
440 httpProxyIP, httpProxyPort, err := net.SplitHostPort(p.options.ListenAddrHTTP)
441 if err != nil {
442 return err
443 }
444 httpProxyPortUint, err := strconv.ParseUint(httpProxyPort, 10, 16)
445 if err != nil {
446 return err
447 }
448 p.socks5tunnel, err = superproxy.NewSuperProxy(httpProxyIP, uint16(httpProxyPortUint), superproxy.ProxyTypeHTTP, "", "", "")
449 if err != nil {
450 return err
451 }
452 p.bufioPool = bufiopool.New(4096, 4096)
453 }
454
455 wg.Add(1)
456 go func() {
457 defer wg.Done()
458
459 gologger.Fatal().Msgf("%v", p.socks5proxy.ListenAndServe("tcp", p.options.ListenAddrSocks5))

Callers 2

dnsserverFunction · 0.45
mainFunction · 0.45

Calls 2

MatchAnyRegexFunction · 0.92
StringMethod · 0.80

Tested by

no test coverage detected