Skip to content

Commit 506cd6b

Browse files
committed
(#375) Fixed JSON bug in file/pipe mode, Improve JSON Printing
1 parent 0393e8d commit 506cd6b

File tree

5 files changed

+37
-7
lines changed

5 files changed

+37
-7
lines changed

cmd/file.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ var fileCmd = &cobra.Command{
147147
}
148148
}()
149149
}
150+
if options.Format == "json" {
151+
printing.DalLog("PRINT", "[", options)
152+
}
150153
for k, v := range t {
151154
temp := model.MassJob{
152155
Name: k,
@@ -156,6 +159,9 @@ var fileCmd = &cobra.Command{
156159
}
157160
close(tasks)
158161
wg.Wait()
162+
if options.Format == "json" {
163+
printing.DalLog("PRINT", "{}]", options)
164+
}
159165
if (!options.NoSpinner || !options.Silence) && !sf {
160166
options.SpinnerObject.Stop()
161167
}
@@ -172,6 +178,9 @@ var fileCmd = &cobra.Command{
172178
}
173179
options.SpinnerObject.Start()
174180
}
181+
if options.Format == "json" {
182+
printing.DalLog("PRINT", "[", options)
183+
}
175184
for i := range targets {
176185
options.NowURL = i + 1
177186
_, _ = scanning.Scan(targets[i], options, strconv.Itoa(i))
@@ -183,6 +192,9 @@ var fileCmd = &cobra.Command{
183192
mutex.Unlock()
184193
}
185194
}
195+
if options.Format == "json" {
196+
printing.DalLog("PRINT", "{}]", options)
197+
}
186198
if (!options.NoSpinner || !options.Silence) && !sf {
187199
options.SpinnerObject.Stop()
188200
}

cmd/pipe.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ var pipeCmd = &cobra.Command{
9090
}
9191
}()
9292
}
93+
if options.Format == "json" {
94+
printing.DalLog("PRINT", "[", options)
95+
}
9396
for k, v := range t {
9497
temp := model.MassJob{
9598
Name: k,
@@ -99,6 +102,9 @@ var pipeCmd = &cobra.Command{
99102
}
100103
close(tasks)
101104
wg.Wait()
105+
if options.Format == "json" {
106+
printing.DalLog("PRINT", "{}]", options)
107+
}
102108
if (!options.NoSpinner || !options.Silence) && !sf {
103109
options.SpinnerObject.Stop()
104110
}
@@ -115,6 +121,9 @@ var pipeCmd = &cobra.Command{
115121
}
116122
options.SpinnerObject.Start()
117123
}
124+
if options.Format == "json" {
125+
printing.DalLog("PRINT", "[", options)
126+
}
118127
for i := range targets {
119128
options.NowURL = i + 1
120129
_, _ = scanning.Scan(targets[i], options, strconv.Itoa(i))
@@ -126,6 +135,9 @@ var pipeCmd = &cobra.Command{
126135
mutex.Unlock()
127136
}
128137
}
138+
if options.Format == "json" {
139+
printing.DalLog("PRINT", "{}]", options)
140+
}
129141
if (!options.NoSpinner || !options.Silence) && !sf {
130142
options.SpinnerObject.Stop()
131143
}

cmd/sxss.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ var sxssCmd = &cobra.Command{
2626
}
2727
if options.Trigger != "" {
2828
printing.DalLog("SYSTEM", "Using Stored XSS mode", options)
29+
if options.Format == "json" {
30+
printing.DalLog("PRINT", "[", options)
31+
}
2932
_, _ = scanning.Scan(args[0], options, "Single")
33+
if options.Format == "json" {
34+
printing.DalLog("PRINT", "{}]", options)
35+
}
3036
} else {
3137
printing.DalLog("ERROR", "Please input trigger url with --trigger option", options)
3238
}

cmd/url.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ var urlCmd = &cobra.Command{
1515
printing.Summary(options, args[0])
1616
if len(args) >= 1 {
1717
printing.DalLog("SYSTEM", "Using single target mode", options)
18+
if options.Format == "json" {
19+
printing.DalLog("PRINT", "[", options)
20+
}
1821
_, _ = scanning.Scan(args[0], options, "Single")
22+
if options.Format == "json" {
23+
printing.DalLog("PRINT", "{}]", options)
24+
}
1925
} else {
2026
printing.DalLog("ERROR", "Input target url", options)
2127
printing.DalLog("ERROR", "e.g dalfox url https://google.com/?q=1", options)

pkg/scanning/scan.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@ func Scan(target string, options model.Options, sid string) (model.Result, error
127127
printing.DalLog("SYSTEM", "Valid target [ code:"+strconv.Itoa(tres.StatusCode)+" / size:"+strconv.Itoa(len(body))+" ]", options)
128128
}
129129

130-
if options.Format == "json" {
131-
printing.DalLog("PRINT", "[", options)
132-
}
133-
134130
var wait sync.WaitGroup
135131
task := 3
136132
sa := "SA: ✓ "
@@ -1017,9 +1013,7 @@ func Scan(target string, options model.Options, sid string) (model.Result, error
10171013
s.Stop()
10181014
}
10191015
}
1020-
if options.Format == "json" {
1021-
printing.DalLog("PRINT", "{}]", options)
1022-
}
1016+
10231017
options.Scan[sid] = scanObject
10241018
scanResult.EndTime = time.Now()
10251019
scanResult.Duration = scanResult.EndTime.Sub(scanResult.StartTime)

0 commit comments

Comments
 (0)