MCPcopy Create free account
hub / github.com/edoardottt/pphack / write

Function write

pkg/scan/runner.go:148–207  ·  view source on GitHub ↗
(m *sync.Mutex, options *input.Options, resultData output.ResultData)

Source from the content-addressed store, hash-verified

146}
147
148func write(m *sync.Mutex, options *input.Options, resultData output.ResultData) {
149 if options.FileOutput != "" && options.Output == nil {
150 file, err := os.OpenFile(options.FileOutput, os.O_CREATE|os.O_RDWR|os.O_APPEND, DefaultFilePerm)
151 if err != nil {
152 gologger.Fatal().Msg(err.Error())
153 }
154
155 options.Output = file
156 }
157
158 var (
159 o []byte
160 err error
161 )
162
163 if options.JSON {
164 o, err = output.FormatJSON(&resultData)
165 if err != nil {
166 gologger.Fatal().Msg(err.Error())
167 }
168
169 fmt.Println(string(o))
170 } else {
171 if options.Exploit {
172 if len(resultData.ExploitURLs) != 0 {
173 var str string
174 for _, e := range resultData.ExploitURLs {
175 str += fmt.Sprintf("[EXPLOIT] %s\n", e)
176 gologger.Info().Label("EXPLOIT").Msg(e)
177 }
178
179 o = []byte(strings.TrimSuffix(str, "\n"))
180 } else {
181 gologger.Info().Label("VULN").Msg(resultData.ScanURL)
182
183 str := fmt.Sprintf("[VULN] %s\n", resultData.ScanURL)
184 for _, e := range resultData.References {
185 str += fmt.Sprintf("[REFERENCE] Target is vulnerable but cannot reproduce an exploit, see %s\n", e)
186 gologger.Info().Label("REFERENCE").Msg(
187 fmt.Sprintf("Target is vulnerable but cannot reproduce an exploit, see %s", e))
188 }
189
190 o = []byte(strings.TrimSuffix(str, "\n"))
191 }
192 } else {
193 gologger.Info().Label("VULN").Msg(resultData.ScanURL)
194 o = []byte(fmt.Sprintf("[VULN] %s", resultData.ScanURL))
195 }
196 }
197
198 m.Lock()
199
200 if options.Output != nil {
201 if _, err := options.Output.Write([]byte(string(o) + "\n")); err != nil && options.Verbose {
202 gologger.Error().Msg(err.Error())
203 }
204 }
205

Callers 1

writeOutputFunction · 0.85

Calls 1

FormatJSONFunction · 0.92

Tested by

no test coverage detected