Penetration Basics: Fortigate Identification and Version Detection

Onedaysec
3 min read
3 views
docx image 1769396801143 0 1b08ff8785

Penetration Basics: Fortigate Identification and Version Detection

0x00 Preface

Fortigate identification requires distinguishing between the management page and the VPN login page. Version detection involves extracting features based on page characteristics and matching precise versions using these features. This article will introduce methods to implement Fortigate identification and version detection using Python, along with open-source code.

0x01 Introduction

This article will cover the following content:

Implementation Ideas

Implementation Details

Open-Source Code

0x02 Implementation Ideas

1. Fortigate Identification

Can be distinguished by the redirected URL

Management page redirect URL: /login?redir=%2F

VPN login page redirect URL: /remote/login?lang=en

2. Version Detection

There exists a 32-bit hexadecimal string in the page source code that can be used as a feature for version identification; each version corresponds to a different 32-bit string

0x03 Implementation Details

1. Fortigate Identification

The method here is to directly access the IP and judge based on the page return result

(1) Management Page

A 32-bit hexadecimal string can be obtained from the return result

(2) VPN Login Page

The returned content is a redirect address; you need to parse the redirect address, reconstruct the URL, access it, and obtain a 32-bit hexadecimal string from the return result

Example of the returned redirect address content:

【技术原创】渗透基础——Fortigate识别与版本探测Since the redirect URL is not fixed, you can extract the redirect URL via regex matching here. Example code:

【技术原创】渗透基础——Fortigate识别与版本探测

Note:

When judging the version, you cannot use the allow_redirects=False parameter in the requests module to control redirection. The reason is as follows:

When using the requests module, if you use the allow_redirects=False parameter, redirection is only disabled when the return status code is 301 or 302. Here, Fortigate returns a status code of 200, so the allow_redirects=False parameter has no effect

2. Version Detection

During actual testing, different versions of Fortigate all return 32-bit hexadecimal characters, but their formats are different. To improve matching efficiency and reduce workload, we choose to directly match the 32-bit hexadecimal characters in regex matching here. The example code is as follows:

【技术原创】渗透基础——Fortigate识别与版本探测

During actual testing, there are cases where the output of response.text is garbled

The process of researching solutions is as follows:

Output response.headers, sample code:

【技术原创】渗透基础——Fortigate识别与版本探测

Return result:

【技术原创】渗透基础——Fortigate识别与版本探测

Found the encoding format is x-gzip

Therefore, we can perform an additional gzip decoding on response.text here to get the original data, the code is as follows:

【技术原创】渗透基础——Fortigate识别与版本探测The complete implementation code is as follows:

【技术原创】渗透基础——Fortigate识别与版本探测【技术原创】渗透基础——Fortigate识别与版本探测

Note:

If you encounter the error ERR_SSL_VERSION_OR_CIPHER_MISMATCH when accessing the SSL VPN Client page via a browser, the program will return the following result:

【技术原创】渗透基础——Fortigate识别与版本探测

Solution:

Just switch to Python2

0x04 Open Source Code

The complete implementation code has been uploaded to GitHub, the address is as follows:

https://github.com/3gstudent/Homework-of-Python/blob/master/Fortigate_GetVersion.py

The code supports distinguishing between management pages and VPN login pages, provides a VM version fingerprint database as an example, can automatically extract fingerprint features from the page, compare them with the fingerprint database, and identify the exact version.

0x05 Summary

This article introduces methods to implement Fortigate identification and version detection using Python, covers implementation details and open-source code, and serves as an excellent learning example.

Related Questions & Answers

What should you do if you encounter garbled text or an SSL version/cipher mismatch when accessing a Fortigate SSL VPN client page?

If the response text is garbled, it may be due to x-gzip encoding; you can apply gzip decoding to obtain the original data. For the ERR_SSL_VERSION_OR_CIPHER_MISMATCH error when accessing the SSL VPN client page via a browser, the program may still return a result, and the article suggests switching to Python 2 to resolve it. These troubleshooting steps are covered in the [implementation details](/news/penetration-basics-fortigate-identification-and-version-detection) of the article.

Why does using `allow_redirects=False` in the Python requests module not work for Fortigate VPN page version detection?

The `allow_redirects=False` parameter only disables redirection when the HTTP status code is 301 or 302. In the case of Fortigate VPN login page, the redirect is returned with a status code of 200, so the parameter has no effect. Instead, you must manually parse the redirect URL from the response body using regex. This nuance is important for accurate [Fortigate identification and version detection](/news/penetration-basics-fortigate-identification-and-version-detection).

What is the key feature used for Fortigate version detection, and how is it extracted from the page source?

Each Fortigate version returns a unique 32-bit hexadecimal string in the page source code. This string can be extracted using regex matching in Python. However, note that the response may be gzip-encoded, so you need to decode it using gzip to get the original text before extraction. The full implementation is available in the [open-source code](https://github.com/3gstudent/Homework-of-Python/blob/master/Fortigate_GetVersion.py). Similar fingerprint-based version detection is used for other systems, as described in [Minio version detection](/news/penetration-basics-minio-version-detection).

How can you distinguish between a Fortigate management page and a VPN login page during penetration testing?

You can differentiate them by the redirect URL. The management page redirects to `/login?redir=%2F`, while the VPN login page redirects to `/remote/login?lang=en`. Directly accessing the IP and examining the response helps identify which page is returned. For more on similar identification techniques, see the other articles in the [Penetration Basics](/news/penetration-basics-fortigate-identification-and-version-detection) series, such as [Zimbra version detection](/news/penetration-basics-zimbra-version-detection).

Continue Reading