Support Forum
The Forums are a place to find answers on a range of Fortinet products from peers and product experts.
FGFan
New Contributor

Pre-shared Key

Hi all, 

I configured remote VPN using IP-SEC and I forgot pre-share key I configured before, so I couldn't connect from Foticlient. I show config and got pre-shared key, it was encrypted. There are some application can decrypt that string but I don't know Which default encryption method FortiGate use to make pre-shared key(MD5, 3DES...?). Anyone can tell me? Thanks a lot!

2 Solutions
gammuts
New Contributor II

ENC password can be decrypted. Just found out a way to do so. In fact, I found two methods for FortiOS 5.6.7. Your mileage may very for other versions though.

 

Method 1:

1) Log in into the web-interface as a (super?) admin.

2) Change your url/path to /api/v2/cmdb/vpn.ipsec/phase1-interface (edited after post about ticking bomb)

3) Firefox understands the JSON reply. I hope your browser does too. Search for psksecret on the page.

4) Notice that the psksecret is "ENC XXXX"

5) With the proper option, one can ask the FortiGate to give you the decrypted password. My original post contained the actual option, but perhaps that is not wise/secure at this moment. I changed this post after reading about "ticking bomb".

 

Method 2:

I also changed this part. It gave a full solution for decrypting passwords. It had something to do with WiFi PSK's. It is a fairly straight forward solution that anyone could or should have found who understands that "ENC XXXX" must mean that reversible encryption is used. As a matter of fact, cookbook https://cookbook.fortinet.com/encryption-hash-used-by-fortios-for-local-pwdpsk/ will tell you just the same. It will also tell  you that AES encryption is used, but https://docs.fortinet.com/uploaded/files/3624/fortigate-hardening-your-fortigate-56.pdf disagrees with that when not running in FIPS mode and says it is only DES: "Pre- shared keys in IPSec phase- 1 configurations are stored in plain text. In the configuration file these pre- shared keys are encoded. The encoding consists of encrypting the password with a fixed key using DES (AES in FIPS mode) and then Base64 encoding the result."

View solution in original post

gammuts
New Contributor II

FWIW: I wrote an article describing the finding of the one key on https://medium.com/@bart.dopheide/decrypting-fortigate-passwords-cve-2019-6693-1239f6fd5a61. I found 1 way, yet tried many. (The story does not talk about all the failed paths.)

 

If you really want to know the one key, then that article contains all the pointers you will get from me (and they should suffice).

View solution in original post

15 REPLIES 15
Mr_J
New Contributor

Oh my god you are right. I had previously tried a lot with the API and there the plaintext passwords are not displayed.

I have now tried a lot of passwords and they can be decrypt via the VAP-method.

Also the passwords from local users.

 

As it looks like, you can decrypt all passwords that have a base64 string of 200 characters. As it looks like, the API call only works with wireless and ipsec. I find it extremely remarkable that almost all passwords can be decrypted.

 

Best regards

emnoc
Esteemed Contributor III

Gammuts is  the man of the hour, good job and a good find

PCNSE 

NSE 

StrongSwan  

PCNSE NSE StrongSwan
gammuts
New Contributor II

https://fortiguard.com/psirt/FG-IR-19-007 - There is actually a static encryption key, or "hard-coded key" as Fortinet calls it.

 

It was quite a struggle finding the one key in the firmware and actually quite useless (since I already described how to decode the password in an easy way). But I was able to decrypt passwords with openssl enc -d -aes-128-cbc -K hardcoded_key_in_hex -iv right_iv_in_hex -nopad, and reported it under responsible disclosure.

 

Fortinet asked my kindly not publish the actual hard-coded key. I honour that request, so don't please don't ask the key; just use one of the other ways I mentioned :-).

gammuts
New Contributor II

FWIW: I wrote an article describing the finding of the one key on https://medium.com/@bart.dopheide/decrypting-fortigate-passwords-cve-2019-6693-1239f6fd5a61. I found 1 way, yet tried many. (The story does not talk about all the failed paths.)

 

If you really want to know the one key, then that article contains all the pointers you will get from me (and they should suffice).

miyabhai101
New Contributor

 

Damm even I am having a similar kind of issue, I have searched all over the internet and even have posted on number of threads on different forum, no solution seems to work. I am really frustrated, can anyone of you here help me resolve this issue, I am very much tired now.

James_G

miyabhai101 wrote:

 

Damm even I am having a similar kind of issue, I have searched all over the internet and even have posted on number of threads on different forum, no solution seems to work. I am really frustrated, can anyone of you here help me resolve this issue, I am very much tired now.

I just followed what was already in the thread and it worked - so everything you need is here!

Labels
Top Kudoed Authors