Wednesday, July 15, 2020

ANSIBLE for fortigate devices setups

 Here's a simple play that sets our org wide settings for all new fortigates. 



(virt1) [opc@ansible-cloud ~]$ cat fgtsetup.yml

---

- hosts: fgt

  collections:

  - fortinet.fortios

  gather_facts: false

  connection: httpapi


  vars:

    vdom: "root"

    ansible_httpapi_use_ssl: yes

    ansible_httpapi_validate_certs: no

    ansible_httpapi_port: 443

    ansible_python_interpreter: virt1/bin/python

  tasks:

  - name: Setup_Console

    fortios_system_console:

      vdom: "{{ vdom  }}"

      system_console:

        output: "more"

        baudrate: 19200

  - name: Setup_Global

    fortios_system_global:

       vdom:  "{{ vdom }}"

       system_global:

         hostname: "BROOKLYNCNTAL"

         admin_login_max: "6"

         login_timestamp: "enable"

         cfg_save: "automatic"

         timezone: "08"

         admin_ssh_port: "2022"

         admin_scp: "enable"

         gui_certificates: "enable"

  - name: Setup_NTP

    fortios_system_ntp:

        vdom: "{{ vdom }}"

        system_ntp:

          interface:

            - interface_name: wan2

          syncinterval: "15"

          type: "fortiguard"

          ntpsync: "enable"

  - name: Setup_AlertEmail

    fortios_alertemail_setting:

        vdom: "{{ vdom }}"

        alertemail_setting:

          mailto1: "soc@socpuppets.com"

          username: "noc@socpuppets.com"

In our inventory file we define the fortigate address and these various variables


[fgt]

192.0.2.1 ansible_user=ansible ansible_password=test1234

192.0.2.2 ansible_user=ansible ansible_password=setup

192.0.2.3 ansible_user=ansible ansible_password=password123

192.0.2.4 ansible_user=ansible ansible_password=password0987654321


[fgt:vars]

 ansible_network_os=fortinet.fortios.fortios

# ansible_httpapi_password=hhhjh05tyx5h3r15d64Gm6Nh15tjpm


To call  our setup we just run the command and let the play execute the tasks.


example;



And lastly, we install our standard admin accounts;

(virt1) [opc@ansible-cloud ~]$ cat fgtaddadmin.yml

---

- hosts: fgt

  collections:

  - fortinet.fortios

  gather_facts: false

  connection: httpapi


  vars:

    vdom: "root"

    ansible_httpapi_use_ssl: yes

    ansible_httpapi_validate_certs: no

    ansible_httpapi_port: 443

    ansible_python_interpreter: virt1/bin/python

  tasks:

  - name: Configure primary admin

    fortios_system_admin:

      vdom:  "{{ vdom }}"

      state: "present"

      system_admin:

        accprofile: "super_admin"

        vdom:

         - name: "root"

        comments: "socpuppet admin account do not delete"

        name: "socadmin2"

        password: "testing1234"


  - name: Configure primary admin

    fortios_system_admin:

      vdom:  "{{ vdom }}"

      state: "present"

      system_admin:

        accprofile: "auditor"

        vdom:

         - name: "root"

        comments: "socpuppet PCI account do not delete"

        name: "auditor"

        password: "pciblahbl"


if you loose the admin account password and still have  the "ansible user account". You can always re-add the account. This makes for a great password recovery options.




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

        /  \


Tuesday, July 14, 2020

HOWTO user ansible with fortios

 To use ansible with the fortiosapi module you need to install the module and ensure that you have it installed;


pip install fortiosapi 

pip list | grep forti


Your install output should look like the following;


example



Now you can write your 1st playbook. Here's a simple playbook that was defined to check status





And the output when it ran;



Here's a simple group creation;



If you have problem executing use the ANSIBLE_DEBUG=1 while execution of the playbook


example;

    ANSIBLE_DEBUG=1 ansible-playbook fortios1.yml



you can also step thru the play using the switch --step when playing the playbook



Reference my earlier posts on fortios API and examples


https://socpuppet.blogspot.com/2018/07/howto-use-fortios-api-to-add-delete.html

https://socpuppet.blogspot.com/2019/09/howto-use-fortios-apiuser.html



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

        /  \

Monday, July 6, 2020

HOWTO: Audit unused fwpolicy on fortios via snmp

The firewall once configured for SNMP has a simple oid that will list the counters by packets for a given policy. You can snmpget the oid for the fwpolicyId or walk the whole tree.

.1.3.6.1.4.1.12356.101.5.1.2.1.1.2



So you can see that the firewall homefgt has 4 policyID 24/25/1/2 but only policy id #1 is taking traffic.


by querying the fwpolicy oid for statistics you can quickly ascertain what fwpolicyId by # is being used or not used.

If your only interesteding in un-used fwPolicyId # just do something like this and grep out the policy #

snmpwalk -v2c -c mycommunity 192.168.1.99 .1.3.6.1.4.1.12356.101.5.1.2.1.1.2 | egrep "Counter32: 0"


The output will clearly show you zero matched policies that you could dump to a sheet for later exploration and analysis.


For snmpv3. here's a working example;




Keep in mind, no matched for a policy that been installed for some considerable time is a good indicator of one of the following;


  • policyid seq and order is incorrect
  • service is wrong for that policy
  • policy is written wrong with regards to src/dst address and src/dst interface|zone


The manual method for counting policy match is by the execution of the diag firewall iprope  show 001000004 <policyid>  command.

example;

diagnose firewall iprope show 00100004 2
idx=2 pkts/bytes=420878/339340862 asic_pkts/asic_bytes=405523/337996081 nturbo_pkts/nturbo_bytes=0/0 flag=0x0 hit count:3895
    first:2020-07-07 20:58:07 last:2020-07-07 21:41:01
 established session count:236

    first est:2020-07-07 20:58:07 last est:2020-07-07 21:41:01

The above could be tiring some if you had hundreds or thousands of fwPolicy and only need to see the ones not being matched.






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

        /  \





Friday, June 26, 2020

Checkpoint HA probe show HA down Cores did not match on nodes

I ran into a Checkpoint Security gateway HA issues where the XLcore did not match on the two security-gateways


Here's what happens, this is a VM and it has multiple vCPU. The primary and secondary node matches from a vmWare perspective but the configuration details did not.

the cpconfig also provided a clue based on the line option did not exist on the primary sec-gw, if you do not have the correct Cores listed the option 10 will not be presented





So the file /etc/fw.boot/boot.conf has to match on members




As you can clearly see, they did not. I had to unix-vi that file and reboot node cpsg101 and re-execute a "cphaprob state" command to  verify after the reboot


ID         Unique Address  Assigned Load   State          Name

1 (local)  10.1.20.5    100%            ACTIVE          cpsg101
2              10.1.20.6    0%              STANDBY            cpsg102


I hope this can help some one if you  do not have a healthy HA state.





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

        /  \

Friday, June 19, 2020

HOWTO: build discard routes to drop traffic by country for junos


In this thread, we will use a very simple python script to write discard routes for junos. You can create a "set config" and load that into your junos device.

The geoip source used in this example comes from denyip which keeps a up to date list. You can also use other geodata such as { https://www.ip2location.com/free/visitor-blocker } and call up the country and cidr format in your request.

I like  ipdeny since the data is clear and simple formatted. Just make sure to change the 2-letter country.code to the country that you want.

      https://www.ipdeny.com/ipblocks/data/countries/ch.zone


they are working on a firewall configuration-tool that I hope would be ready soon.








Just set the two-letter country code in your request when pulling down the CIDR blocks.

Next, just call the python script and read the text file back and in to generate the junos set commands.


#  file.txt would be the name prefix list in CIDR format

#!/usr/bin/python
#
#  junos discard route creator version1.0
#   socpuppets
#
#  set the two letter country code to whatever country of interest
#  
#        ch=china in this example
#
# https://www.ipdeny.com/ipblocks/data/countries/ch.zone

with open("file.text") as f:
         next(f)

         for prefix in f:
             print "set routing-options static route" , prefix.rstrip(), "discard"


This will format the discard routes in a similar fashion;

set routing-options static route 1.0.8.0/21 discard
set routing-options static route 1.0.32.0/19 discard
set routing-options static route 1.1.0.0/24 discard
set routing-options static route 1.1.2.0/23 discard
set routing-options static route 1.1.4.0/22 discard
set routing-options static route 1.1.8.0/24 discard
set routing-options static route 1.1.9.0/24 discard
set routing-options static route 1.1.10.0/23 discard
set routing-options static route 1.1.12.0/22 discard
set routing-options static route 1.1.16.0/20 discard
set routing-options static route 1.1.32.0/19 discard
set routing-options static route 1.2.0.0/23 discard
set routing-options static route 1.2.2.0/24 discard
set routing-options static route 1.2.4.0/24 discard
set routing-options static route 1.2.5.0/24 discard

Just save the above text into a file and then load that into the juniper device and commit the changes.


./china_blocks.py  > junos_china_netblocks.set-format

scp ./junos_china_netblocks.set-format    kfelix@juniper.example.com:

and then login and commit the changes on the juniper device


ssh  kfelix@juniper.example.com

 config 
   commit check
      load set china_netblocks.set
 commit and-quit 


I hope this demo will show you a quick means for blocking address from a particular country. Great if you need to quickly block a country due to unwarranted activities.





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

        /  \


Monday, June 8, 2020

decrypted fortios password with fpr fortios password recovery

Here's a simple example on how to decode passwords on fortios. This does NOT work with the latest fortios version 6.4.1

fpr "fortios password recovery"

The utility is called "fpr" https://github.com/inm7ripe/Fortigate-password-recovery

grab the enc password field

here's guest user



Now echo  and pipe the string into fpr




And boom shaka laka, "guest" is the password for guest . This utility works for user local accounts, vpn-psk,  but system admin seems to core dump. YMMV


 






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

        /  \

Tuesday, June 2, 2020

HOWTO" verify geo-protection blocks on Checkpoint Security Gateway

If you ever deploy geo-protection policies and block specific countries, you can easily witness blocks by logging into the checkpoint appliance and by running the follow command

   fw ctl zdebug drop | grep -i geo 


geo.database file is located in the IpToCountry.csv and you can verify that it's been updated by looking at it's timestamp



The above will display traffic that is blocked by the geo-protection. Keep in mind geo-protection rules are analyze before the access.rule

You can use maxmind to verify src of origination




So if you block let's say "russia" via geo-protection and then write an access-rule to allow a specific russian host in, that would not work unless you had a geo-protection exception for that ipv4 source.


 






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

        /  \