-
Notifications
You must be signed in to change notification settings - Fork 42
fgfm protocol #275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
fgfm protocol #275
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| // Package fortinet is a very basic (and incomplete) implementation of Fortinet FGFM protocol | ||
| package fortinet | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "crypto/tls" | ||
| "encoding/binary" | ||
| "net" | ||
|
|
||
| "github.com/vulncheck-oss/go-exploit/output" | ||
| "github.com/vulncheck-oss/go-exploit/protocol" | ||
|
|
||
| ) | ||
|
|
||
| // 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 | ||
| // | ||
| // [4 bytes of magic header] | ||
| // [4 bytes of total request length] | ||
| // [n bytes request body data] | ||
|
|
||
| func SendFGFMMessage(conn net.Conn, payload string) bool { | ||
| message := make([]byte, 0) | ||
| // add magic header | ||
j-shomo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| message = append(message, []byte("\x36\xe0\x11\x00")...) | ||
| // build the total length field | ||
| totalLengthField := make([]byte, 4) | ||
| length := len(payload) + 8 | ||
| binary.BigEndian.PutUint32(totalLengthField, uint32(length)) | ||
| message = append(message, totalLengthField...) | ||
| // add payload | ||
| message = append(message, []byte(payload)...) | ||
|
|
||
| return protocol.TCPWrite(conn, message) | ||
| } | ||
|
|
||
| func ReadFGFMMessage(conn net.Conn) ([]byte, bool) { | ||
j-shomo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| magic, ok := protocol.TCPReadAmount(conn, 4) | ||
| if !ok || !bytes.Equal(magic, []byte("\x36\xe0\x11\x00")) { | ||
| output.PrintFrameworkError("Failed to read server response with expected header") | ||
| return nil, false | ||
j-shomo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| size, ok := protocol.TCPReadAmount(conn, 4) | ||
| if !ok { | ||
| output.PrintFrameworkError("Failed to read server response length") | ||
| return nil, false | ||
| } | ||
|
|
||
| readSize := int(binary.BigEndian.Uint32(size)) | ||
| data, ok := protocol.TCPReadAmount(conn, readSize-8) | ||
| if !ok { | ||
| output.PrintFrameworkError("Failed to read server response data") | ||
| return nil, false | ||
| } | ||
|
|
||
| return data, true | ||
| } | ||
|
|
||
| // Fortimanager requires a connecting Fortigate instance to have a cert. | ||
| // SSL is optional here so you have the choice to sign the traffic from the go-exploit framework, | ||
| // or so you can send the exploit network traffic through a proxy like socat to sign the traffic for you. | ||
| // Benefits to this include being able to generate pcaps of the unencrypted traffic | ||
| // between go-exploit and your proxy. | ||
| // See CVE-2024-47575 for additional information. | ||
| func Connect(host string, port int, ssl bool, certFile string, keyFile string) (net.Conn, bool) { | ||
| if ssl { | ||
| cert, err := tls.LoadX509KeyPair(certFile, keyFile) | ||
| if err != nil { | ||
| output.PrintFrameworkError("Failed to load x509 Key Pair") | ||
| output.PrintfFrameworkDebug("Failed to load x509 Key Pair with error: %s", err) | ||
|
|
||
| return nil, false | ||
| } | ||
| cfg := &tls.Config{Certificates: []tls.Certificate{cert}, InsecureSkipVerify: true} | ||
|
||
|
|
||
| conn, ok := protocol.TCPConnect(host, port) | ||
| if !ok { | ||
| return nil, false | ||
| } | ||
| return tls.Client(conn, cfg), true | ||
| } | ||
|
|
||
| return protocol.TCPConnect(host, port) | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.