Skip to content

Commit 9bbd6fb

Browse files
committed
formatting and comments
1 parent e9c30aa commit 9bbd6fb

File tree

1 file changed

+57
-55
lines changed

1 file changed

+57
-55
lines changed

protocol/fortinet/fgfm.go

Lines changed: 57 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,83 +2,85 @@
22
package fortinet
33

44
import (
5-
"bytes"
6-
"crypto/tls"
7-
"encoding/binary"
8-
"net"
9-
10-
"github.com/vulncheck-oss/go-exploit/output"
11-
"github.com/vulncheck-oss/go-exploit/protocol"
5+
"bytes"
6+
"crypto/tls"
7+
"encoding/binary"
8+
"net"
129

10+
"github.com/vulncheck-oss/go-exploit/output"
11+
"github.com/vulncheck-oss/go-exploit/protocol"
1312
)
1413

15-
// Creates a Fortinet FGFM message. The format is closed source, but research by BF, Watchtowr, and Rapid7 have helped uncover the basic message header structure
16-
//
14+
// Creates and sends a Fortinet FGFM message to a FortiManager.
15+
// The format is closed source, but research by BF, Watchtowr, and Rapid7 have helped uncover the basic message header structure:
1716
// [4 bytes of magic header]
1817
// [4 bytes of total request length]
19-
// [n bytes request body data]
20-
18+
// [n bytes request body data].
2119
func SendFGFMMessage(conn net.Conn, payload string) bool {
22-
message := make([]byte, 0)
23-
// add magic header
24-
message = append(message, []byte("\x36\xe0\x11\x00")...)
25-
// build the total length field
26-
totalLengthField := make([]byte, 4)
27-
length := len(payload) + 8
28-
binary.BigEndian.PutUint32(totalLengthField, uint32(length))
29-
message = append(message, totalLengthField...)
30-
// add payload
31-
message = append(message, []byte(payload)...)
20+
message := make([]byte, 0)
21+
// add magic header
22+
message = append(message, []byte("\x36\xe0\x11\x00")...)
23+
// build the total length field
24+
totalLengthField := make([]byte, 4)
25+
length := len(payload) + 8
26+
binary.BigEndian.PutUint32(totalLengthField, uint32(length))
27+
message = append(message, totalLengthField...)
28+
// add payload
29+
message = append(message, []byte(payload)...)
3230

33-
return protocol.TCPWrite(conn, message)
31+
return protocol.TCPWrite(conn, message)
3432
}
3533

34+
// Reads response from a FortiManager.
3635
func ReadFGFMMessage(conn net.Conn) ([]byte, bool) {
37-
magic, ok := protocol.TCPReadAmount(conn, 4)
38-
if !ok || !bytes.Equal(magic, []byte("\x36\xe0\x11\x00")) {
39-
output.PrintFrameworkError("Failed to read server response with expected header")
40-
return nil, false
41-
}
42-
size, ok := protocol.TCPReadAmount(conn, 4)
43-
if !ok {
44-
output.PrintFrameworkError("Failed to read server response length")
45-
return nil, false
46-
}
36+
magic, ok := protocol.TCPReadAmount(conn, 4)
37+
if !ok || !bytes.Equal(magic, []byte("\x36\xe0\x11\x00")) {
38+
output.PrintFrameworkError("Failed to read server response with expected header")
4739

48-
readSize := int(binary.BigEndian.Uint32(size))
49-
data, ok := protocol.TCPReadAmount(conn, readSize-8)
50-
if !ok {
51-
output.PrintFrameworkError("Failed to read server response data")
52-
return nil, false
53-
}
54-
55-
return data, true
40+
return nil, false
41+
}
42+
size, ok := protocol.TCPReadAmount(conn, 4)
43+
if !ok {
44+
output.PrintFrameworkError("Failed to read server response length")
45+
46+
return nil, false
47+
}
48+
49+
readSize := int(binary.BigEndian.Uint32(size))
50+
data, ok := protocol.TCPReadAmount(conn, readSize-8)
51+
if !ok {
52+
output.PrintFrameworkError("Failed to read server response data")
53+
54+
return nil, false
55+
}
56+
57+
return data, true
5658
}
5759

5860
// Fortimanager requires a connecting Fortigate instance to have a cert.
5961
// SSL is optional here so you have the choice to sign the traffic from the go-exploit framework,
6062
// or so you can send the exploit network traffic through a proxy like socat to sign the traffic for you.
61-
// Benefits to this include being able to generate pcaps of the unencrypted traffic
63+
// Benefits to this include being able to generate pcaps of the unencrypted traffic
6264
// between go-exploit and your proxy.
6365
// See CVE-2024-47575 for additional information.
6466
func Connect(host string, port int, ssl bool, certFile string, keyFile string) (net.Conn, bool) {
65-
if ssl {
66-
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
67-
if err != nil {
68-
output.PrintFrameworkError("Failed to load x509 Key Pair")
69-
output.PrintfFrameworkDebug("Failed to load x509 Key Pair with error: %s", err)
67+
if ssl {
68+
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
69+
if err != nil {
70+
output.PrintFrameworkError("Failed to load x509 Key Pair")
71+
output.PrintfFrameworkDebug("Failed to load x509 Key Pair with error: %s", err)
7072

71-
return nil, false
72-
}
73-
cfg := &tls.Config{Certificates: []tls.Certificate{cert}, InsecureSkipVerify: true}
73+
return nil, false
74+
}
75+
cfg := &tls.Config{Certificates: []tls.Certificate{cert}, InsecureSkipVerify: true}
7476

75-
conn, ok := protocol.TCPConnect(host, port)
76-
if !ok {
77-
return nil, false
78-
}
79-
return tls.Client(conn, cfg), true
77+
conn, ok := protocol.TCPConnect(host, port)
78+
if !ok {
79+
return nil, false
8080
}
8181

82-
return protocol.TCPConnect(host, port)
82+
return tls.Client(conn, cfg), true
83+
}
8384

85+
return protocol.TCPConnect(host, port)
8486
}

0 commit comments

Comments
 (0)