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 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, which is normally is a subfolder of the work 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 two java scripts: menu.js and back2top.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
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
Example:
[Default] Logo=./html/MyCompany.jpg AllObjects=0
[CompanyB] Logo=./html/CompanyB/OtherLogo.gif AllObjects=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 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
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 --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 object types converted to HTML. This might well be not what you want. The page and table definitions enables you to change the output to your taste.
Run a report and check it out before you start modifying the page definitions. Changing the table definitions is however not advised, because it requires extended knowledge of the Check Point database structure.
Which tables are presented on which HTML pages, is defined in a file called: CPPages.def. It also defines which tables are presented at all! So this file allows you to show just what you want your customers to see.
In CPPages.def the page 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!
A (rulebase)section consists of pages and tables. The page names are free to choose, but the tables have to be defined in the Constants.pm file. In the next paragraph more about that. Every page definition starts with a Page= command, followed by one or more Table= commands.
Example:
[MyRulebase] Page=MyPage Table=Hosts Table=Services
Page=My2ndPage Table=Resources Table=OPSEC
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. The objects within a HTML table have to be member of the same Check Point table, which 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.
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.
CPRules version 1.0 d.d. 01/02/2004
Bug reports and requests for modifications can be send to Peter-Paul.Worm@wormnet.nl
Peter-Paul Worm (Peter-Paul.Worm@wormnet.nl)