/
pipe.go
157 lines (152 loc) 路 5 KB
/
pipe.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package cmd
import (
"bufio"
"fmt"
"os"
"strconv"
"sync"
"time"
"github.com/briandowns/spinner"
model "github.com/hahwul/dalfox/v2/pkg/model"
"github.com/hahwul/dalfox/v2/pkg/printing"
"github.com/hahwul/dalfox/v2/pkg/scanning"
voltUtils "github.com/hahwul/volt/util"
"github.com/spf13/cobra"
)
// pipeCmd represents the pipe command
var pipeCmd = &cobra.Command{
Use: "pipe [flags]",
Short: "Use pipeline mode",
Run: func(cmd *cobra.Command, args []string) {
sf, _ := cmd.Flags().GetBool("silence-force")
if sf {
options.Silence = sf
}
printing.Banner(options)
tMethod := options.Method
options.Method = "Pipe Mode"
printing.Summary(options, "Stdin (pipeline)")
options.Method = tMethod
var targets []string
mutex := &sync.Mutex{}
options.Mutex = mutex
sc := bufio.NewScanner(os.Stdin)
if (!options.NoSpinner || !options.Silence) && !sf {
options.SpinnerObject = spinner.New(spinner.CharSets[14], 100*time.Millisecond, spinner.WithWriter(os.Stderr)) // Build our new spinner
}
printing.DalLog("SYSTEM", "Using pipeline mode", options)
for sc.Scan() {
target := sc.Text()
targets = append(targets, target)
}
targets = voltUtils.UniqueStringSlice(targets)
printing.DalLog("SYSTEM", "Loaded "+strconv.Itoa(len(targets))+" target urls", options)
multi, _ := cmd.Flags().GetBool("multicast")
mass, _ := cmd.Flags().GetBool("mass")
if multi || mass {
printing.DalLog("SYSTEM", "Using multicasting mode", options)
options.Silence = true
options.MulticastMode = true
t := scanning.MakeTargetSlice(targets)
tt := 0
for k, v := range t {
_ = k
tt = tt + len(v)
}
if (!options.NoSpinner || !options.Silence) && !sf {
options.SpinnerObject.Prefix = " "
options.SpinnerObject.Suffix = " [" + strconv.Itoa(options.NowURL) + "/" + strconv.Itoa(tt) + " Tasks][0%] Parallel scanning from pipe"
if !options.NoColor {
options.SpinnerObject.Color("red", "bold")
}
options.SpinnerObject.Start()
}
var wg sync.WaitGroup
tasks := make(chan model.MassJob)
options.NowURL = 0
concurrency, _ := cmd.Flags().GetInt("mass-worker")
for k, v := range t {
if !options.Silence || !sf {
printing.DalLog("SYSTEM-M", "Parallel testing to '"+k+"' => "+strconv.Itoa(len(v))+" urls", options)
}
}
for task := 0; task < concurrency; task++ {
wg.Add(1)
go func() {
defer wg.Done()
for kv := range tasks {
v := kv.URLs
for i := range v {
_, _ = scanning.Scan(v[i], options, strconv.Itoa(len(v)))
if (!options.NoSpinner || !options.Silence) && !sf {
options.Mutex.Lock()
options.NowURL = options.NowURL + 1
percent := fmt.Sprintf("%0.2f%%", float64(options.NowURL)/float64(tt)*100)
options.SpinnerObject.Suffix = " [" + strconv.Itoa(options.NowURL) + "/" + strconv.Itoa(tt) + " Tasks][" + percent + "] Parallel scanning from pipe"
options.Mutex.Unlock()
}
}
}
}()
}
if options.Format == "json" {
printing.DalLog("PRINT", "[", options)
}
for k, v := range t {
temp := model.MassJob{
Name: k,
URLs: v,
}
tasks <- temp
}
close(tasks)
wg.Wait()
if options.Format == "json" {
printing.DalLog("PRINT", "{}]", options)
}
if (!options.NoSpinner || !options.Silence) && !sf {
options.SpinnerObject.Stop()
}
if !options.Silence || !sf {
printing.DalLog("SYSTEM-M", "Finish massive scan!", options)
}
} else {
options.AllURLS = len(targets)
if (!options.NoSpinner || !options.Silence) && !sf {
options.SpinnerObject.Prefix = " "
options.SpinnerObject.Suffix = " [" + strconv.Itoa(options.NowURL) + "/" + strconv.Itoa(options.AllURLS) + " Tasks][0%] Multiple scanning from pipe"
if !options.NoColor {
options.SpinnerObject.Color("red", "bold")
}
options.SpinnerObject.Start()
}
if options.Format == "json" {
printing.DalLog("PRINT", "[", options)
}
for i := range targets {
options.NowURL = i + 1
_, _ = scanning.Scan(targets[i], options, strconv.Itoa(i))
if (!options.NoSpinner || !options.Silence) && !sf {
mutex.Lock()
options.NowURL = options.NowURL + 1
percent := fmt.Sprintf("%0.2f%%", float64(options.NowURL)/float64(options.AllURLS)*100)
options.SpinnerObject.Suffix = " [" + strconv.Itoa(options.NowURL) + "/" + strconv.Itoa(options.AllURLS) + " Tasks][" + percent + "] Multiple scanning from pipe"
mutex.Unlock()
}
}
if options.Format == "json" {
printing.DalLog("PRINT", "{}]", options)
}
if (!options.NoSpinner || !options.Silence) && !sf {
options.SpinnerObject.Stop()
}
}
},
}
func init() {
rootCmd.AddCommand(pipeCmd)
pipeCmd.Flags().Bool("multicast", false, "Parallel scanning N*Host mode (show only poc code)")
pipeCmd.Flags().Bool("mass", false, "Parallel scanning N*Host mode (show only poc code)")
pipeCmd.Flags().Bool("silence-force", false, "Only print PoC (not print progress)")
pipeCmd.Flags().Int("mass-worker", 10, "Parallel worker of --mass and --multicast option")
}