Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/input/formats/burp/burp.go
2858 views
1
package burp
2
3
import (
4
"encoding/base64"
5
"io"
6
"strings"
7
8
"github.com/pkg/errors"
9
"github.com/projectdiscovery/nuclei/v3/pkg/input/formats"
10
"github.com/projectdiscovery/nuclei/v3/pkg/input/types"
11
"github.com/projectdiscovery/utils/conversion"
12
burpxml "github.com/projectdiscovery/utils/parsers/burp/xml"
13
)
14
15
// BurpFormat is a Burp XML File parser
16
type BurpFormat struct {
17
opts formats.InputFormatOptions
18
}
19
20
// New creates a new Burp XML File parser
21
func New() *BurpFormat {
22
return &BurpFormat{}
23
}
24
25
var _ formats.Format = &BurpFormat{}
26
27
// Name returns the name of the format
28
func (j *BurpFormat) Name() string {
29
return "burp"
30
}
31
32
func (j *BurpFormat) SetOptions(options formats.InputFormatOptions) {
33
j.opts = options
34
}
35
36
// Parse parses the input and calls the provided callback
37
// function for each RawRequest it discovers.
38
func (j *BurpFormat) Parse(input io.Reader, resultsCb formats.ParseReqRespCallback, filePath string) error {
39
items, err := burpxml.ParseXML(input, burpxml.XMLParseOptions{DecodeBase64: true})
40
if err != nil {
41
return errors.Wrap(err, "could not decode burp xml schema")
42
}
43
44
for _, item := range items.Items {
45
binx, err := base64.StdEncoding.DecodeString(item.Request.Raw)
46
if err != nil {
47
return errors.Wrap(err, "could not decode base64")
48
}
49
if strings.TrimSpace(conversion.String(binx)) == "" {
50
continue
51
}
52
rawRequest, err := types.ParseRawRequestWithURL(conversion.String(binx), item.URL)
53
if err != nil {
54
return errors.Wrap(err, "could not parse raw request")
55
}
56
resultsCb(rawRequest)
57
}
58
return nil
59
}
60
61