CPRules.pl - Perl program to convert a Check Point FW-1 configuration to HTML
As the management of a FW is a security-sensitive subject, one can not allow others to access the management servers. With 'others' being non-administrators of the firewall, like internal or external customers. In many cases it is even prohibited by the security policy of your company and sometimes the mgmt LAN is even physically disconnected!
However in many cases it is very convenient to have a copy of the configuration available for viewing by a select group of 'others'. This can be for a helpdesk for trouble shooting purposes (not needing to call you every five minutes), a customer demanding to have an insight in their FW configuration or just for backup purposes.
On the other hand, it's not wise to leave this kind of configurations lying around for everybody to see (you're auditors would have a field day). So you might not want everything being published, but only a subset of the configuration (f.i. only the FW rulebase itself). Such a subset would enable the customer (being either internal or external) to request meaningfull changes without having to bother the administrators first.
To be able to do all this, we need a tool to convert the Check Point files to a readable format. This tool would need to be configurable to allow administrators to define what to publish and how. CPRULES is designed to accomodate in just that wish.
Searching the internet the only tool available to convert Check Point configurations is a perl script called FW1RULES, written and maintained by Volker Tanger <volker.tanger@wyae.de>. Admittedly this program did serve very well and is widely used. This program is originally written to cope with Check Point FW-1 version 4.1 code and has later been adapted to support NG configurations as well. It drastically needed a rewrite of the code due to additions and changes made in the past. That is basically where CPRULES has taken of.
There are two ways to configure the program. The first and easiest way is through the configuration file called CPRules.ini. The second option is to use the commandline parameters. The advantage of the .ini file is that many parameters can be set per rulebase. This is not possible through the commandline switches.
The software will read the CPRules.ini file first and adds the commandline switches later on. This enables you to use a default setup and overwrite it at will from the commandline. If you are handling more management stations, this would enable you to call the program for every management server in turn, only differing the location of the Check Point files.
Default behaviour is to process all rulebases found in the rulebases file. In some cases you just want to get the results for one rulebase or a subset of rulebases. Both is possible through the (include and exclude) commands in the CPRules.ini file. Through the commandline it is only possible to process one (-b switch) or all rulebases.
As discussed above, the CPRules.ini is the preferred way to configure the behaviour of the program. The CPRules.ini is searched for in the current directory and if not found in the working directory of CPRules, i.e. the folder where the script itself is located.
The configuration options are divided in three sections: CPRules file locations, Check Point file locations and Rulebase specific settings. The next three corresponding paragraphs will outline the commands.
The first section of the CPRules.ini file holds all the path and file names needed by the software itself:
TmplPath - The program uses templates to build the HTML pages. Templating allows you to make changes to the output without messing with the program. For more details about the syntax, see the documentation of the 'template.pm' file. This parameter defines the location of the template files. The program searches for the folder 'Templates' in both the current- and the working directory.
TmplPath=./tmpl
HTMLPath - The output of the program are HTML pages per rulebase. This will result in subfolders in the HTML folder per rulebase (f.i. ./html/MyRulebase). This parameter defines the location of the HTML files.
HTMLPath=./html
The second section of the CPRules.ini file holds all the path and file names needed to view the produced webpages correctly. Note that these paths are hardcoded in the HTML code produced! So you'd better check the files are there when viewing the results of the software.
IconPath - The objects all have different icons per type or class. These icons have been extracted from the Check Point files and stored in a separate folder. This folder is needed for correct displaying of the HTML pages, so the path is relative to the HTML directory. The default value assumes the 'icons'-folder is a subfolder of the HTML folder. This path will be hardcoded in the HTML pages, so be sure the icons are actual there!
IconPath=../icons
CSSPath - The location of the stylesheets used. There is currently only one stylesheet used, called cprules.css.
CSSPath=../css
ScriptPath - The HTML output uses three java scripts: menu.js, back2top.js and visible.js. This parameter defines the location of those scripts relative to the HTML files.
ScriptPath=../scripts
MainLogo - This defines the location of the main logo of the program. This could be the logo of the ISP providing the service, or a self-designed CPRules logo. Note that this will be hardcoded in the HTML files, so be sure it can be found during viewing.
The third section of the CPRules.ini file holds the location of the Check Point files needed. How the files get there is completely up to you, as long as they are accessible. Note: Check Point files are case-sensitive, so be careful not to misspell the filenames.
FW1Rules - Check Point stores all the rulebases in one file, called 'rulebases_5_0.fws'. This is the only rulebase file needed. This parameter defines the location and name of this file relative to the work folder.
FW1Rules=./rulebases_5_0.fws
FW1Objects - Check Point stores all the objects, services, etc in one database file called 'objects_5_0.C'. This parameter defines the location and name of this file relative to the work folder.
FW1Objects=./objects_5_0.C
FW1Users - The users of Check Point are currently not stored in a 'normal' database file. However in the GUI of R55 there are indications this might change. The file used is called 'users.C' and has the same structure as the 'objects_5_0.C' file. This parameter defines the location and name of this file relative to the work folder. If this file is not present yet, one has to rely on the exported users and groups. See below EXP_Users and EXP_Groups.
EXP_Users - Till now the users of Check Point are stored in the file 'fwauth.NDB', which is not readable. The users can be exported from this database by using the command:
fwm dbexport -f <filename>
This parameter defines the location and name of this exported users file relative to the work folder. The program will use CPUsers.pl to create the 'users.C' file from the export file(s).
EXP_Groups - As with the users, the groups of Check Point are stored in the file 'fwauth.NDB', which is not readable. The groups can be exported from this database by using the command:
fwm dbexport -g -f <filename>
This parameter defines the location and name of the exported groups file relative to the work folder. The program will use CPUsers.pl to create the 'users.C' file from the export file(s). If the groups file is not included, vital information will be missing, as comments, groups in groups information and administrator groups.
Default behaviour of the program is to process all rulebases found in the rulebases file. The Include and Exclude commands can be used to alter this behaviour. You should never have to combine both statements, but you are allowed to.
Exclude - Do NOT generate HTML for this rulebase. If the first (include/exclude) command found is an Exclude command, all other rulebases are INcluded automatically.
Include - Do generate HTML for this rulebase. If the first (include/exclude) command found is an Include command all other rulebases are EXcluded automatically.
Note: If a rulebase is both included and excluded (???), the first entry will prevail.
Example:
Include=MyCompany Exclude=Standard
The rulebase specific section holds additional commands to alter the output of the program. As the program creates HTML files per rulebase, these settings must be adaptable per rulebase. To accomplish this, section headers with the name of the rulebase are used to define the setting for this specific rulebases.
To make life easier, a [Default] section can (and will) be used to hold all 'default' settings. If a specific setting is not specified in a rulebase section, the corresponding setting in the [Default] section will be used. So in many practical situations, there will be no other rulebase sections at all!
Logo - The HTML pages always have a logo in the left top of the page (see MainLogo). The Logo parameter is used to define the image in the right top of the pages. This is designed to be the logo of the customer which rulebase is shown here. Note that this will be hardcoded in the HTML files, so be sure it can be found during viewing.
Logo=./html/MyCompany.jpg
AllObjects - By default (0) the HTML pages will only list those objects actually used in the rulebase. This parameter (if set to '1') will change this behaviour and will list all objects available. That might come in handy during testing or when documenting the configuration.
AllObjects=0
GlobalProps - By default (1) the Global Properties will be included in the output files. To suppress the Global Properties, set the value to '0'.
GlobalProps=1
Example:
[Default] Logo=./html/MyCompany.jpg AllObjects=0 GlobalProps=0
[CompanyB] Logo=./html/CompanyB/OtherLogo.gif AllObjects=1 GlobalProps=1
All the default values that can be set in the CPRules.ini can also be set using a commandline switch. For a more detailed description see that section. There is always a verbose version and a short version available and the switches are case-insensitive.
To set the path to the template folder (default: ./tmpl):
--TmplPath <path> -t <path>
To set the path to the HTML folder (default: ./html):
--HTMLPath <path> -h <path>
To set the path to the folder with icons relative to the HTML folder (default: ../icons):
--IconPath <path> -i <path>
To set the path to the folder which holds the css stylesheets (default: ../css):
--CSSPath <path> -c <path>
To set the path to the folder which holds the scripts used (default: ../scripts):
--ScriptPath <path> -s <path>
To define the logo in the upper left top of the HTML pages (default: (none)):
--MainLogo <path and filename> -m <path and filename> To define the location of the Check Point rulebase file (default: ./rulebases_5_0.fws):
--FW1Rules <path and filename> -r <path and filename>
To define the location of the Check Point object database (default: ./objects_5_0.C):
--FW1Objects <path and filename> -o <path and filename>
To define the location of the Check Point users database (if available):
--FW1Users <path and filename> -u <path and filename>
To define the location of the exported users file:
--EXP_Users <path and filename> -eu <path and filename>
To define the location of the exported groups file:
--EXP_Groups <path and filename> -eg <path and filename>
To specify one specific rulebase only (default: all rulebases):
--Rulebase <rulebase name> -b <rulebase name>
To define the logo in the upper right top of the HTML pages (default: (none)):
--Logo <path and filename> -l <path and filename>
To define if all objects should be listed by default, the following switch should be used. This switch turns the setting ON (it's OFF by default):
--AllObjects
To define if the Global Properties should be excluded from the output, the following switch should be used. This switch turns the setting OFF (it's ON by default):
--NoGlobalProps
Examples:
The typical installation of the CPRules will often be static. The icons, templates and html files are in a fixed location, so only the location of the Check Point files needs to be defined. All other parameters are defined in the .ini file. Such a setup would result in a commandline as shown below (displayed over more lines for readability):
cprules --FW1Objects /data/fwmgmt2/objects_5_0.C --FW1Rules /data/fwmgmt2/rulebases_5_0.C --FW1Users /data/fwmgmt2/users.C --AllObjects
To run the program for one rulebase only with the corresponding logo:
cprules --Rulebase MyCompany --Logo ./MyCompany.gif
This chapter describes how the output of CPRules is setup and how it can be altered. The default setup creates all HTML pages with all (used) object types converted to HTML. This might well be not what you want. The page, table and section definitions enables you to change the layout to your taste.
Tip: Run a report and check it out before you start modifying the layout definitions.
Which tables are presented on which HTML pages and which section is presented in which table, is defined in the file called: CPPages.def. This configuration file enables you to determine what to present to your customers. Although it is possible to NOT show an entire table or section, it is not possible to alter the content of the specific section or table through this file.
In CPPages.def the page the entire setup can be defined per rulebase by creating a separate section per rulebase. However there is also a section called [Default] which will be used if there is no section defined for a rulebase. This enables you to specify a different layout for every rulebase!
The layout of a rulebase consists of pages, tables and sections. Of these three only the page names are free to choose! The tables are defined in the Constants.pm file (described in the next paragraph), but the sectionnames are even hardcoded in the source files. Trying to change them might have interesting results :-).
Every page definition starts with a Page= command. Every table on this page is listed beneath the page definitione and denoted by one or more Table= commands. Every table holds one or more [Section name] definitions. For the pages and tables this is straightforward. To show the structure an example without sections is shown below.
Example:
[MyRulebase] Page = Rulebase Table = Rules Table = NATRules
Page=MyPage Table=Hosts Table=Services
Page=My2ndPage Table=Resources Table=OPSEC
Now many tables consists of several sections. Every section can be SKIPped (not displayed), OPEN or CLOSED. The latter two means that the section is folded open or closed. Clicking on the section name will revert this. By default all sections are CLOSED, but this can be altered. First impressions show that larger databases display much better with all sections CLOSED, but smaller databases might well turn out better with OPENed sections.
The below (partial) example shows one page with three tables in which the Topology section is OPENed, but the other sections are CLOSED.
Example:
[MyRulebase] Page = Gateways Table = CheckPoint Check Point Products = CLOSED Cluster Members = CLOSED Sofaware Settings = CLOSED Topology = OPEN ... Table = Interoperable Topology = OPEN VPN = CLOSED FireWall-1 GX = CLOSED Table = OSEDevices Topology = OPEN SNMP = CLOSED Setup = CLOSED
Warning: Changing table definitions is not straight-forward. You need to have thorough understanding of the Check Point database structure! However it provides an manageable way (for the author) to cope with future changes/additions Check Point comes up with.
The table definitions are in a package called Constants.pm. This Perl package holds all Check Point related constants used in CPRules.
The hash used for the table definitions is %Table and it is a bit complex. The purpose is to define which objects are to be displayed in which table AND to define the order in which they are presented within the table. All objects within one HTML table must be member of the same Check Point table. This table is reflected in the value of TABLE. At this time it is not possible to combine objects from different Check Point tables into one HTML table.
All Check Point objects do have a 'type'. Objects of the same type are normally grouped together in one table (not strictly necessary), but several types can be used in one table. The best table to show this grouping is the Services table:
SERVICES => { TABLE => 'services', TYPE => { 'tcp' => '1:TCP', 'tcp_subservice' => '2:Compound TCP', 'tcp_citrix' => '3:Citrix TCP', 'udp' => '4:UDP', 'rpc' => '5:RPC', 'icmp' => '6:ICMP', 'other' => '7:Other', 'dcerpc' => '8:DCE-RPC', 'gtp' => '9:GTP' } },
The SERVICES table above is getting the objects from the Check Point table 'services'. The numbers followed by a colon (':')in the text define the order in which they will be presented in the HTML page. For instance the services with type 'tcp' are presented before the services with type 'udp'. The remainder of the text is passed to the routine that creates the HTML pages and is currently used as header text for the service subsections (see the examples).
If the TYPE of an object is not sufficient to determine the different members, it is possible to define other keys to select on. An example to explain this is seen in the gateway table definition:
GATEWAYS => { TABLE => 'network_objects', TYPE => { 'gateway' => { 'AdminInfo:ClassName' => { 'gateway_ckp' => '1:Gateway', 'gateway_plain' => '6:Interoperable Device', 'gateway_profile' => '7:Gateway Profile' } }, 'gateway_cluster' => '2:Gateway Cluster', 'cluster_member' => '3:Cluster Member', 'sofaware_gateway_profile' => '4:Sofaware Profile', 'router' => '5:Router' } },
The type 'gateway' holds three different types of gateways. To distinguish between the three we need to look at the 'ClassName' of the objects. See above how that is defined in the hash %Table. Note the 'AdminInfo:ClassName' to denote the path to the key used.
There is one final possibility. The rules in a rulebase are no separate objects, but are part of a list of rules. This case is reflected in the %Table by not defining a TYPE, but by defining a LIST:
RULES => { TABLE => 'rule-base', LIST => 'rule' },
For more specific details check the code, to see what is passed exactly to the corresponding routines and how that can be handled.
Templating is used to differentiate between the codewriter and the layout people and have the best of both worlds. Implementing this is easier said than done. In this case we needed to have enough options for the codewriter to determine the layout of the tables and sections in the tables, but without needing to write actual HTML code. To fix this dilemma, we have included a template file called section.tmpl which defines the different formats information can be displayed (see below). This file is used in several other files as INCLUDE file. Now the codewriter has/can have a number of pre-defined layouts and the layout people can define the actual HTML code and influence the actual result.
This is not a codewriters guidebook. For examples of the described options one better examine the source code and the template files. The templating engine is discussed in a separate document (template.pm) and that is the place to learn about data structures used.
The section.tmpl file is used to add a section to a table. The include statement will normally be included in a loop, to allow for more than one section to be added (e.g. all nodes).
A section is always delimited by a BEGin and END statement. Not closing of a section might result in ``interesting'' layouts :-). The following section delimiters are currently defined:
SF_BEG ... SF_END SUBSECT_BEG ... SUBSECT_END COL_BEG ... COL_NXT ... COL_END
The section S0 generates a text with a horizontal line behind it. This can be used to indicate a new 'chapter' or to clearly distinguish between two sections. This feature is being superseded by the SF_BEG and SF_END structure, but is and will be supported for backwards compatibility (it is still begin used in the Global Properties, but this will be changed).
The SF stands for 'Section Folded'. It defines a section that can be folded closed or opened (see the Page Layout section). Clicking on the header of the section closes or opens the section.
This option generates a (sub)section in the table by using the html FIELDSET commands. This results in the browser to draw a box around the included text, indicating that this information is related.
Previously there was also a SECTION command that could be used if the content was all in one section. This still works, but is only supported for backwards compatibility. It is not used anymore in the source code of CPrules.
To place two or more sections next to each other, columns can be used. The COL_BEG starts the columns, the COL_NXT initiates a new column and the COL_END closes the columns off.
The layout of a section is based on a few input parameters supplied in the source code. The first option defines the general format and the suboptions define the specific field layouts.
In some case you just need to include a simple text message or note in a section. This option will just do that for you. The format of the text is determined by the CLASS suboption, which relates directly to classes defined in the cprules.css file. Therefore, this should be meaningfull names. Currently we have defined two classes:
This section is probably the most important section. Every line in this section consists of a maximum of five (5) fields or columns. As this section is actually a table, the fields are nicely lined up beneath each other.
The standard options in the S1 section:
Advanced option in the S1 section:
The T1 section generates an actual table with lines and a header line.
This is a special section, as it uses the same syntax as the routine HTMLMemberList. This routine is used to get the HTML code for all the members of an object (f.i. the Participating Gateways in a VPN community). Nothing more nothing less.
This special section is used to include a ' ' in a tablecell. In case a tablecell is empty, the browser will not display the borders either. This section just add a space to the cell, so the browser won't see it as an empty cell.
The version history is supplied in a different history file. This file can be viewed on the webpage ``http://www.wormnet.nl/cprules/history/History of CPrules.doc''
Bug reports and requests for modifications can be send to Peter-Paul.Worm@wormnet.nl
Peter-Paul Worm (Peter-Paul.Worm@wormnet.nl)