Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/input/formats/burp/burp.go
2070 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
"github.com/seh-msft/burpxml"
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.Parse(input, true)
40
if err != nil {
41
return errors.Wrap(err, "could not decode burp xml schema")
42
}
43
44
// Print the parsed data for verification
45
for _, item := range items.Items {
46
item := item
47
binx, err := base64.StdEncoding.DecodeString(item.Request.Raw)
48
if err != nil {
49
return errors.Wrap(err, "could not decode base64")
50
}
51
if strings.TrimSpace(conversion.String(binx)) == "" {
52
continue
53
}
54
rawRequest, err := types.ParseRawRequestWithURL(conversion.String(binx), item.Url)
55
if err != nil {
56
return errors.Wrap(err, "could not parse raw request")
57
}
58
resultsCb(rawRequest) // TODO: Handle false and true from callback
59
}
60
return nil
61
}
62
63