-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgenerate-owasp-testing-checklist.go
89 lines (74 loc) · 2.3 KB
/
generate-owasp-testing-checklist.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
// Fetch and Parse from https://github.com/tanprathan/OWASP-Testing-Checklist
package main
import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"strings"
"github.com/google/uuid"
"github.com/tealeg/xlsx"
)
type xlsxFolder struct {
ID string `json:"id"`
Title string `json:"title"`
Checks []xlsxCheck `json:"checklist"`
}
type xlsxCheck struct {
ID string `json:"id"`
Title string `json:"title"`
Content string `json:"content"`
}
func main() {
excelFileName, err := ioutil.TempFile("", "excel-otg.xlsx")
if err != nil {
log.Fatal(err)
}
name := excelFileName.Name()
defer os.Remove(name)
resp, err := http.Get("https://github.com/tanprathan/OWASP-Testing-Checklist/blob/master/OWASPv4_Checklist.xlsx?raw=true")
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
io.Copy(excelFileName, resp.Body)
excelFileName.Close()
xlFile, err := xlsx.OpenFile(name)
if err != nil {
log.Fatal(err)
}
sheet := xlFile.Sheets[0]
var item *xlsxFolder
list := []*xlsxFolder{}
for i := 0; i < len(sheet.Rows); i++ {
// If the second cell exists and contains "Test Name" then it's an header
if len(sheet.Rows[i].Cells) > 2 {
if strings.EqualFold(sheet.Rows[i].Cells[1].String(), "Test Name") {
if item != nil {
list = append(list, item)
}
item = &xlsxFolder{ID: uuid.New().String(), Title: sheet.Rows[i].Cells[0].String()}
}
}
if len(sheet.Rows[i].Cells) > 4 {
if strings.EqualFold(sheet.Rows[i].Cells[4].String(), "Not Started") {
var title string
if sheet.Rows[i].Cells[0].String() == "" {
title = fmt.Sprintf("%s", sheet.Rows[i].Cells[1].String())
} else {
title = fmt.Sprintf("%s [%s]", sheet.Rows[i].Cells[1].String(), sheet.Rows[i].Cells[0].String())
}
content := strings.Replace(sheet.Rows[i].Cells[2].String(), "\n", "<br>", -1)
item.Checks = append(item.Checks, xlsxCheck{ID: uuid.New().String(), Title: title, Content: fmt.Sprintf("<p>%s</p>", content)})
}
}
}
data, err := json.Marshal(&list)
if err != nil {
log.Fatal(err)
}
final := fmt.Sprintf("{\"targets\":[],\"libraries\":[{\"id\":\"%s\",\"title\": \"OWASP Testing Checklist\",\"folders\":%s}],\"templates\":[],\"payloads\":[],\"messages\": {\"showDeleteConfirmation\": true}}", uuid.New().String(), string(data))
fmt.Println(final)