-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
211 lines (180 loc) · 6.44 KB
/
main.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
package main
/*
BurpToCaido v1.1 by monke
---
This is a utility to convert HTTP history from Burpsuite to Caido.
Burpsuite HTTP history is exported in XML format. This is formatted and
inserted into Caido's SQLite databases.
Usage:
- Run the binary, specifying the input file and the location of Caido's projects.
./burptocaido --burpsuite <path to XML file> --caido <path to Caido project folder containing database.caido>
*/
import (
"database/sql"
"encoding/base64"
"encoding/xml"
"flag"
"fmt"
"log"
"os"
"time"
_ "github.com/mattn/go-sqlite3"
)
type Item struct {
// An Item is a HTTP request/response pair within Burpsuite's exported XML.
Time string `xml:"time"`
URL string `xml:"url"`
Host string `xml:"host"`
Port int `xml:"port"`
Protocol string `xml:"protocol"`
Method string `xml:"method"`
Path string `xml:"path"`
Extension string `xml:"extension"`
Request string `xml:"request"`
Status int `xml:"status"`
ResponseLength int `xml:"responselength"`
MimeType string `xml:"mimetype"`
Response string `xml:"response"`
Comment string `xml:"comment"`
}
func main() {
var banner = fmt.Sprintf(`
██████╗ ██╗ ██╗██████╗ ██████╗ ██████╗ ██████╗ █████╗ ██╗██████╗ ██████╗
██╔══██╗██║ ██║██╔══██╗██╔══██╗╚════██╗██╔════╝██╔══██╗██║██╔══██╗██╔═══██╗
██████╔╝██║ ██║██████╔╝██████╔╝ █████╔╝██║ ███████║██║██║ ██║██║ ██║
██╔══██╗██║ ██║██╔══██╗██╔═══╝ ██╔═══╝ ██║ ██╔══██║██║██║ ██║██║ ██║
██████╔╝╚██████╔╝██║ ██║██║ ███████╗╚██████╗██║ ██║██║██████╔╝╚██████╔╝ by monke v%s
╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚══════╝ ╚═════╝╚═╝ ╚═╝╚═╝╚═════╝ ╚═════╝
`, "1.0")
fmt.Println(banner)
burpsuite := flag.String("burp", "", "Path to Burpsuite XML file")
caido := flag.String("caido", "", "Path to Caido project path")
flag.Parse()
if *burpsuite == "" {
log.Fatalf("The --burp flag is required.")
os.Exit(1)
}
if *caido == "" {
log.Fatalf("The --caido flag is required.")
os.Exit(1)
}
fmt.Println("[INFO] Using Caido path: " + *caido)
fmt.Println("[INFO] Using Burpsuite path: " + *burpsuite)
db_main_path := *caido + "/database.caido"
if _, err := os.Stat(db_main_path); os.IsNotExist(err) {
log.Fatal("Caido main database does not exist.")
}
dbCaido, err := sql.Open("sqlite3", db_main_path)
if err != nil {
log.Fatalf("Error opening database.caido: %v", err)
}
defer dbCaido.Close()
db_raw_path := *caido + "/database_raw.caido"
if _, err := os.Stat(db_raw_path); os.IsNotExist(err) {
log.Fatal("Caido raw database does not exist.")
}
dbCaidoRaw, err := sql.Open("sqlite3", db_raw_path)
if err != nil {
log.Fatalf("Error opening database_raw.caido: %v", err)
}
defer dbCaidoRaw.Close()
xmlFile, _ := os.Open(*burpsuite)
defer xmlFile.Close()
decoder := xml.NewDecoder(xmlFile)
for {
token, _ := decoder.Token()
if token == nil {
break
}
switch se := token.(type) {
case xml.StartElement:
if se.Name.Local == "item" {
var item Item
decoder.DecodeElement(&item, &se)
insertData(dbCaido, dbCaidoRaw, item)
}
}
}
fmt.Println("\033[32m[INFO] Updated Caido databases successfully.\033[0m")
}
func insertData(dbCaido, dbCaidoRaw *sql.DB, item Item) {
// Used to insert the cleaned data into Caido's databases.
requestData, _ := base64.StdEncoding.DecodeString(item.Request)
responseData, _ := base64.StdEncoding.DecodeString(item.Response)
layout := "Mon Jan 02 15:04:05 MST 2006"
parsedTime, err := time.Parse(layout, item.Time)
if err != nil {
log.Fatalf("Failed to parse datetime: %v", err)
}
timestamp := parsedTime.UnixNano() / int64(time.Millisecond)
// database_raw.caido
txRaw, err := dbCaidoRaw.Begin()
if err != nil {
log.Fatal(err)
}
res, err := txRaw.Exec("INSERT INTO requests_raw (data, source, alteration) VALUES (?, 'intercept', 'none')", requestData)
if err != nil {
txRaw.Rollback()
log.Fatal(err)
}
rawRequestID, err := res.LastInsertId()
if err != nil {
txRaw.Rollback()
log.Fatal(err)
}
res, err = txRaw.Exec("INSERT INTO responses_raw (data, source, alteration) VALUES (?, 'intercept', 'none')", responseData)
if err != nil {
txRaw.Rollback()
log.Fatal(err)
}
rawResponseID, err := res.LastInsertId()
if err != nil {
txRaw.Rollback()
log.Fatal(err)
}
txRaw.Commit()
// database.caido
tx, err := dbCaido.Begin()
if err != nil {
log.Fatal(err)
}
_, err = tx.Exec("INSERT INTO responses (status_code, raw_id, length, alteration, edited, roundtrip_time, created_at) VALUES (?, ?, ?, 'none', 0, 0, ?)",
item.Status, rawResponseID, item.ResponseLength, timestamp)
if err != nil {
tx.Rollback()
log.Fatal(err)
}
responseID, err := res.LastInsertId()
if err != nil {
tx.Rollback()
log.Fatal(err)
}
requestID, err := res.LastInsertId()
if err != nil {
tx.Rollback()
log.Fatal(err)
}
_, err = tx.Exec("INSERT INTO requests_metadata (id) VALUES (?)", requestID)
if err != nil {
txRaw.Rollback()
log.Fatal(err)
}
_, err = tx.Exec("INSERT INTO requests (host, method, path, length, port, is_tls, raw_id, query, response_id, source, created_at, metadata_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 'intercept', ?, ?)",
item.Host, item.Method, item.Path, len(requestData), item.Port, item.Protocol == "https", rawRequestID, "", responseID, timestamp, rawRequestID)
if err != nil {
tx.Rollback()
log.Fatal(err)
}
intercept_id, err := res.LastInsertId()
if err != nil {
tx.Rollback()
log.Fatal(err)
}
_, err = tx.Exec("INSERT INTO intercept_entries (id, request_id) VALUES (?, ?)",
intercept_id, intercept_id)
if err != nil {
tx.Rollback()
log.Fatal(err)
}
tx.Commit()
}