/
httpx.go
67 lines (58 loc) · 1.62 KB
/
httpx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"os"
"os/signal"
"runtime"
"runtime/pprof"
"github.com/projectdiscovery/gologger"
errorutil "github.com/projectdiscovery/utils/errors"
"github.com/t101804/httpr/runner"
)
func main() {
// Parse the command line flags and read config files
options := runner.ParseOptions()
// Profiling related code
if options.Memprofile != "" {
f, err := os.Create(options.Memprofile)
if err != nil {
gologger.Fatal().Msgf("profile: could not create memory profile %q: %v", options.Memprofile, err)
}
old := runtime.MemProfileRate
runtime.MemProfileRate = 4096
gologger.Print().Msgf("profile: memory profiling enabled (rate %d), %s", runtime.MemProfileRate, options.Memprofile)
defer func() {
_ = pprof.Lookup("heap").WriteTo(f, 0)
f.Close()
runtime.MemProfileRate = old
gologger.Print().Msgf("profile: memory profiling disabled, %s", options.Memprofile)
}()
}
httpxRunner, err := runner.New(options)
if err != nil {
gologger.Fatal().Msgf("Could not create runner: %s\n", err)
}
// Setup graceful exits
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
for range c {
gologger.Info().Msgf("CTRL+C pressed: Exiting\n")
httpxRunner.Close()
if options.ShouldSaveResume() {
gologger.Info().Msgf("Creating resume file: %s\n", runner.DefaultResumeFile)
err := httpxRunner.SaveResumeConfig()
if err != nil {
gologger.Error().Msgf("Couldn't create resume file: %s\n", err)
}
}
os.Exit(1)
}
}()
httpxRunner.RunEnumerationWithID()
httpxRunner.Close()
}
func init() {
if os.Getenv("DEBUG") != "" {
errorutil.ShowStackTrace = true
}
}