Monday, December 2, 2019

Forcepoint elements creator script

In forcepoint you have the means to import elements into the SMC. You can import csv host objects from a text file. If you want to create elements and deliver these to use I have a script that does groups , hosts and network elements and creates the finally formatted  xml files.



[SOF]


#!/bin/bash
#
#  kfelix socpuppets.com
#  rev1.0
#  date oct15-2019
#
#  Script for CSV supplied customer data { e.g field1,field2,field3 }



#  Purpose of this script is to assist with building  a bulk list of  "hosts"  or "Networks" objects based on a customer provided "space" separated details in a text file

#
#  It should expedite any "Host or Network" elements, which can be easily imported into the SMC after zip compressing the xml datafile

# The hostfile must contains single line entries space separate hostname  and ipv4 address
# The networkfile must contains single-line entries csv separate network-name and network_number and netmask in dot.dot.dot.dot format or CIDR

# e.g    wwww1,1.1.1.1
#        wwww2,1.1.1.2
#        wwww3,1.1.1.3

# e.g    net10,10.0.0.0  8
#        net192.168.1.0,192.168.1.0,255.255.255.0
         ntwrk 10,10.0.0.0,8
# e.g    groupname


######### ensure names do not have any spaces  , try to use _ - enlew of spaces  in the names #############
#########  script does not check the validation of the network number and netmask ; nor the host ipv4 address format    ###########


#
#  start of menu selections
#
#

PS3='Please enter your choice: '
opt=("GenerateHosts" "GenerateNetworks" "GenerateGroups"  "Quit")
select opt in "${opt[@]}"
do
    case $opt in
        "GenerateHosts")
            echo "Building Host Entries using filename $1"
                  D=`date +'%s'`

                  TMP=GeneratedHostImport.$D.xml

                read -p "Press [Enter] key to start"


                echo "<?xml version='1.0' encoding='UTF-8'?>" >> $TMP


                awk 'BEGIN { print "<!DOCTYPE generic_import_export SYSTEM \x22generic_import_export_v5.10.dtd\x22>"}'  >> $TMP


                awk 'BEGIN { print  "<generic_import_export build=\x22"10714"\x22 update_package_version=\x22"1175"\x22>" }' >> $TMP

                #  add host entrys to  temp file
                #

                cat $1  | awk -F "\"*,\"*"  ' {  print "\<host name=\x22"$1"\x22> <mvia_address address=\x22"$2"\x22/>  \n</host>"}'  >> $TMP

                echo "</generic_import_export>" >> $TMP
                
                #
                 echo "job Completed, please see the resulted in xml filename  $TMP"

            exit
            ;;
        "GenerateNetworks")
            echo "Building Network Entries using filename $1"
                 D=`date +'%s'`

                  TMP=GeneratedNetworkImport.$D.xml

                read -p "Press [Enter] key to start"


                echo "<?xml version='1.0' encoding='UTF-8'?>" >> $TMP


                awk 'BEGIN { print "<!DOCTYPE generic_import_export SYSTEM \x22generic_import_export_v5.10.dtd\x22>"}'  >> $TMP


                awk 'BEGIN { print  "<generic_import_export build=\x22"10714"\x22 update_package_version=\x22"1175"\x22>" }' >> $TMP

                #  add host entrys to  temp file
                #

                cat $1  | awk -F "\"*,\"*"  ' {  print "\<network db_key=\x22"7900"\x22 ipv4_network=\x22"$2"/"$3"\x22 name=\x22"$1"\x22/>" }' >> $TMP

                echo "</generic_import_export>" >> $TMP

                #
                 echo "job Completed, please see the resulted in xml filename  $TMP"
                exit
            ;;
         "GenerateGroups")

              echo "Building Group Entries using filename $1"
                 D=`date +'%s'`

                  TMP=GeneratedGroupImport.$D.xml

                read -p "Press [Enter] key to start"


                echo "<?xml version='1.0' encoding='UTF-8'?>" >> $TMP


                awk 'BEGIN { print "<!DOCTYPE generic_import_export SYSTEM \x22generic_import_export_v5.10.dtd\x22>"}'  >> $TMP


                awk 'BEGIN { print  "<generic_import_export build=\x22"10714"\x22 update_package_version=\x22"1175"\x22>" }' >> $TMP

                #  add host entrys to  temp file
                #

                cat $1  | awk -F "\"*,\"*"  ' {  print "\<group  name=\x22"$1"\x22/>"}' >> $TMP

                echo "</generic_import_export>" >> $TMP

                #
                 echo "job Completed, please see the resulted in xml filename  $TMP"
                exit

            ;;
        "Quit")
            break
            ;;
        *) echo "invalid option $REPLY";;
    esac
done


[EOF]


A very simple means to build a export.xml file










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

        /  \

No comments:

Post a Comment