Thursday, October 10, 2019

Rebooting a FGT via a API call

In this post, I will demo how you can use an API call to reboot a FGT appliance.

Example #1, classic CSRF token format



Example #2, classic api-user




If you  suspect api authentication issues, use the debug function and inspect for errors/warnings


diag debug reset 
diag debug enable
diag debug application httpsd -1

The diagnostic output will show details that can lead to resolving the issues


e.g











NSE ( network security expert) and Route/Switching Engineer
kfelix  -----a----t---- socpuppets ---dot---com
     ^      ^
=(  @  @ )=
         o

        /  \

Blockbit UTM firewall

Ola , Bom Dia


For NGFWs that supports Portuguese the FortiGate and blockbit are the only two that I'm aware of. that has language support for Portuguese



Portuguese is the official language in ten countries, including Brazil, Mozambique, Angola, Portugal, Guinea-Bissau, East Timor, Equatorial Guinea, Macau, Cape Verde, and São Tomé and Príncipe. 

FACT: The world has more Portuguese speakers than French overall.


Here we are setting up the Blockbit from a OVA.


NOTE:  Currently they do not have an image in the AWS AMI inventory.


Unlike FortiOS, you can select English or Portuguese at the webUI and for each login session.




LATIN AMERICA BlockBit
Rua Eng. Francisco Pitta Brito 779 – 3º andar
São Paulo – SP – 04753-080 – Brazil
Phone: +55 11 2165 8888
Phone: +55 11 2397 0698







NSE ( network security expert) and Route/Switching Engineer
kfelix  -----a----t---- socpuppets ---dot---com
     ^      ^
=(  @  @ )=
         o

        /  \

DDNS FGT ipsec-tunnels sample

With a dynamic peer, you have to take in consideration that you can NOT id the dynamic endpoint via typical ipv4/ipv6 phase1-id

This is due to the fact that the peer-id is unknown. Here's a dynamic vpn cfgt  that  remote-peer that connects to a dynamic-dns defined peer.









In this next example, we have a hub setup that allows for a dynamic-host to connect and since we have no clue as to what it's address, we have to use a peerid-type that is defined for that peer.



 again notice no ip address!






















NSE ( network security expert) and Route/Switching Engineer
kfelix  -----a----t---- socpuppets ---dot---com
     ^      ^
=(  @  @ )=
         o
        /  \







Wednesday, September 25, 2019

Fortigate IPSEC site2site with RSA signatures

In this post, I will demonstrate how we can do  site2site vpns using x509 certificates.  In the ease of demo'ing this environment,  I did the following.

I set up a vdom-link between 2 vdoms( custA and root )

We use get a CAcert for our signing at  Getacert . The rootCA was installed into the firewall also

100k foot view




Okay,  so the 1st time that typically happens is the mechanism is used for generation of the CSR from the fortigate. In real life, your  CA would be a public or private PKI.

https://www.getacert.com


On each FGT, you would craft a CSR. I like to keep the subject line small and with only a CN value.


This makes it very easy to diagnose the solution.  So in this example, we are using. CN=root and CN=custA

e.g ( a very basic  CSR )



Now, when you have the  CSR signed, you can import it back into the FGT and you can verify the subject line.

e.g


openssl x509 -in fgt-2019-09-23-031604.cer -noout -subject 




Okay brilliant, a simple subject line. Now we will define the peer match statements that would check the rootCA and the CN string type


#vdom=custA

config user peer
  edit "root"
        set ca "CA_Cert_2"
        set cn "root"
    next
  end

#vdom=root

config user peer
  edit "root"
        set ca "CA_Cert_2"
        set cn "custA"
    next
  end


Okay let's apply the configurations for phase1 and phase2


( 1st fw )

 (root) # show vpn ipsec phase1-interface vpn1
config vpn ipsec phase1-interface
    edit "vpn1"
        set interface "vlink10"
        set authmethod signature
        set mode aggressive
        set proposal aes128-sha256
        set dhgrp 5
        set remote-gw 10.19.199.2
        set certificate "root"
        set peer "custA"
    next
end

 (root) # show vpn ipsec phase2-interface vpn1-2
config vpn ipsec phase2-interface
    edit "vpn1-2"
        set phase1name "vpn1"
        set auto-negotiate enable
    next
end




( 2nd fw is a reverse of the 1st ) The other firewall have the following details;


config vpn ipsec phase1-interface
    edit "vpn2"
        set interface "vlink11"
        set authmethod signature
        set mode aggressive
        set proposal aes128-sha256
        set dhgrp 5
        set remote-gw 10.19.199.1
        set certificate "custA"
        set peer "root"
    next
end

 (custA) # 
 (custA) # show  vpn  ipsec  phase2-interface
config vpn ipsec phase2-interface
    edit "vpn2-2"
        set phase1name "vpn2"
        set auto-negotiate enable
    next
end


In the fortiOS cfg you have to call up the local certificate and the peer string for validating the peer. The root CA and end-point needs to be imported into the  fortigate.








Diagnostics  cmds "diag vpn ike gateway" and "diag vpn tunnel list"




notice the  peer-id is the certificate CN name.




So always double-check the proposal and CN values in your config if you have issues setting up ipsec site2site  with rsa signatures.










NSE ( network security expert) and Route/Switching Engineer
kfelix  -----a----t---- socpuppets ---dot---com
     ^      ^
=(  @  @ )=
         o
        /  \



Wednesday, September 18, 2019

IPSEC route-based vpn Fortigate and TNSR

In this blog we will look at an IPSEC vpntunnel from a Fortigate to a TNSR appliance in the AWS cloud.

I just recently stroke a TNSR update cert and upgrade my virt-appliance to 19.08. The upgrade went fine , but I had numerous issues afterwards with the config daemon, which needs further investigations.



The vpn-IPSec configurations are very simple, but you need to watch all items in the configuration at the TNSR cli to ensure completeness

1st the FortiOS ( plain jane route-base-configuration ......nothing is complex here  )







A few items to point out.

  •   This is a route-based vpn  and a route was used for the TNSRnew interface
  •   I defined  phase1-idtype as fqdn and a simple value of  "fgt.socpuppets.com"
  •   I used the onboard wizard and cisco to build a basic configuration and later, I made changes to the proposals

The TNSR has a lot more work but the configuration is straight forward. Here's the snippet of the xml dump of the configuration




The configuration can be dump as "show configuration running" from the CLI




But to get to that cfg you have to do a few items; You can follow the IPSec example at the support site to get an idea of the items that need configuring for IPSEC.


Ensure you set the IKE version for version 1 or 2 and to match the FortiOS value that you defined in the FGT.

https://docs.netgate.com/tnsr/en/latest/ipsec/example.html



Now for diagnostic and if the needs should come up for trouble-shooting;

FortiOS

   diag sniffer packet <interface name > "udp 500 or 4500"
   diag debug enable
   diag debug application ike 10
   diag vpn tunnel list
   diag vpn ike gateway

 TNSR

Here we the show ipsec tunnel verbose cmd and the logs located at   /var/log/messages  will show IPSec logs details ( Strongswan is the IPSec engine for TNSR , btw )

https://en.wikipedia.org/wiki/StrongSwan

To get to the logs you should do the following from the tnsr-cli-cmds by opening a shell

    shell
    sudo  tail -n 40 /var/log/messages


Here are some screenshots from the Fortigate on a FGT-2-TNSR setup


phase1 details



phase2 details



 NOTE:  The SPI values for in/out would match the  TNSR out/in

TNSR ike  and child  SecurityAssociations details;


Take note of the local and remote identities for the two end-points. These are mandatory for AWS since the Elastic IP and interface IP are not the same. I used a "fqdn" type with a simple entry. The FQDN  does NOT need to exist in DNS btw.

e.g



Here our tnsr "show ipsec tunnel verbose" output executed from the cli




and a TNSR log file would look like the following;



TNSR interfaces from centOS bash shell for this demo AWS instance





You can learn more about TNSR at the following link,  Netgate's TNSR
  https://www.tnsr.com



They have software and appliances that can drive 100gbps or more and with hardware CPUs that can push 14Mpps per core. The folks at Netgate have built this system for mainly cli or api usage. I will post more about the API usages later,  and along with examples.


Enjoy










NSE ( network security expert) and Route/Switching Engineer
kfelix  -----a----t---- socpuppets ---dot---com
     ^      ^
=(  @  @ )=
         o
        /  \

More on JumpCloud and with API examples

Integration into a cloud IAM-aaS  from OneLogin and JumpCloud is easy and fun here's some more working  examples for JumpCloud.

In jumpcloud we need to create a api-key , this api key will be  call up the correct api-version.

A api key looks similar to the following this 2a8a2f959020db33d068b79d78b05463b0ddb755

You can create for each administrator by click his name and generating a key;



We can pass json formatted data to JumpCloud API



{
"username":"jdoe",
"email":"jdoe@example.com",
"firstname":"juan",
"lastname":"doe",
        "password":"text1234"
}






A system entry for creating user is structured like the following ;


curl -H "x-api-key: c3f8dd2695e3eecb5c486d438b5113c721683c3c"  --data-binary  "@/JumpcloudCreate" -H "Content-Type: application/json" -H "Accept: application/json"  "https://console.jumpcloud.com/api/systemusers"


or



 curl -X POST  -H "x-api-key: c3f8dd2695e3eecb5c486d438b5113c721683c3c"  -d '{  "email":"jode@null.com","firstname":"jode","lastname":"last","username":"user1" }'      
  -H "Content-Type: application/json"  "https://console.jumpcloud.com/api/systemusers"





if you try to recreate the same user you will get a friendly error




curl -X POST  -H "x-api-key: c3f8dd2695e3eecb5c486d438b5113c721683c3c"  -d '{  "email":"jode@null.com","firstname":"jode","lastname":"last","username":"user1" }'      
 -H "Content-Type: application/json"  "https://console.jumpcloud.com/api/systemusers"

user1 has already been registered. 


You can retrieve users details and pass query string values


ken$ curl -H "Accept: application/xml"  -H "x-api-key: c3f8dd2695e3eecb5c486d438b5113c721683c3c" "https://console.jumpcloud.com/api/systemusers?fields=username&fields=email"
{"totalCount":5,"results":[{"username":"ldap","email":"ldap@socpuppets.com","_id":"5af0e038bf0eb553c7fb03fa"},{"username":"NGFW","email":"ngfw@null.com","_id":"5b7c56122b08836127e3a492"},{"username":"user11","email":"user11@null.com","_id":"5b7c56599e583e1899296370"},{"username":"ssn","email":"ssn@null.com","_id":"5bbe8313457a9c62030e16cd"},{"username":"smcldap","email":"kfelix@socpuppets.com","_id":"5d67537a65a85751406a8698"}]}supports- 

You can lock a user accounts by passing a boolean value of 1  and calling up that user by it's id

curl -X PUT -d '{ "account_locked":"1" }' -H "Content-Type: application/json"  -H "Accept: application/json"   -H "x-api-key: c3f8dd2695e3eecb5c486d438b5113c721683c3c" "https://console.jumpcloud.com/api/systemusers/5b7c56122b08836127e3a492 








 You can get creative and set random password at the time of account creation using perl or python

ken$ cat pass.py

import string

 from random import *

      chars = string.ascii_letters + string.punctuation  + string.digits


      passwd =  "".join(choice(chars) for A in range(randint(10, 14)))


print passwd


example of above script a password structure;


sh-3.2$ python pypass
oQL?HXq4.$


In order to delete a user, again a very similar operation to OneLogin,  and where you use a http.request.method DELETE and the id;

 curl -X DELETE -H "Content-Type: application/json"  -H "x-api-key: c3f8dd2695e3eecb5c486d438b5113c721683c3c"   -H "Accept: application/json"  "https://console.jumpcloud.com/api/systemusers/5d815b250bc54b194afeb1e0"




Notice the custom X header  x-api-key always has the API key in all the above examples.











NSE ( network security expert) and Route/Switching Engineer
kfelix  -----a----t---- socpuppets ---dot---com
     ^      ^
=(  @  @ )=
         o
        /  \