-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
59 lines (49 loc) · 1.48 KB
/
main.go
File metadata and controls
59 lines (49 loc) · 1.48 KB
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
package main
import (
"fmt"
"io"
"log"
"os"
"path"
flag "github.com/spf13/pflag"
"github.com/surface-security/scanner-go-entrypoint/scanner"
)
const DEFAULT_USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36 github.com/surface-security/scanner-httpx"
func main() {
s := scanner.Scanner{Name: "httpx"}
options := s.BuildOptions()
userAgent := flag.String("ua", DEFAULT_USER_AGENT, "Choose user-agent - use empty value for a random UA")
scanner.ParseOptions(options)
err := os.MkdirAll(options.Output, 0755)
if err != nil {
log.Fatalf("%v", err)
}
// pass temporary file to binary instead of final path, as only finished files should be placed there
file, err := os.CreateTemp("", s.Name)
if err != nil {
log.Fatalf("%v", err)
}
defer os.Remove(file.Name())
args := []string{
"-silent", "-no-fallback", "-pipeline", "-tech-detect",
"-json", "-output", file.Name(),
"-l", options.Input,
}
if *userAgent != "" {
args = append(args, "-H", fmt.Sprintf("User-Agent: %s", *userAgent))
}
err = s.Exec(args...)
if err != nil {
log.Fatalf("Failed to run scanner: %v", err)
}
realOutputFile := path.Join(options.Output, "output.txt")
outputFile, err := os.Create(realOutputFile)
if err != nil {
log.Fatalf("Couldn't open dest file: %v", err)
}
defer outputFile.Close()
_, err = io.Copy(outputFile, file)
if err != nil {
log.Fatalf("Writing to output file failed: %v", err)
}
}