├── .gitignore ├── .gitmodules ├── LICENSE ├── README.md ├── c2c.py ├── config.py ├── data ├── default_r7730_network_objects.xml └── default_r7730_service_objects.xml ├── lib ├── cisco2checkpoint.py └── ciscoconfparse_patch.py ├── releases.txt ├── tests ├── network_script.txt ├── network_script_debug.txt ├── network_script_verify.txt └── test_policy.CONFIG └── tools ├── dbedit_export_objects.sh └── mass_object_update.xlsx /.gitignore: -------------------------------------------------------------------------------- 1 | # Project related 2 | logs/ 3 | out/ 4 | *.pyc 5 | lib/*.pyc 6 | # Byte-compiled / optimized / DLL files 7 | __pycache__/ 8 | *.py[cod] 9 | 10 | # C extensions 11 | *.so 12 | 13 | # Distribution / packaging 14 | .Python 15 | env/ 16 | build/ 17 | develop-eggs/ 18 | dist/ 19 | downloads/ 20 | eggs/ 21 | .eggs/ 22 | lib64/ 23 | parts/ 24 | sdist/ 25 | var/ 26 | *.egg-info/ 27 | .installed.cfg 28 | *.egg 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *,cover 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | 57 | # Sphinx documentation 58 | docs/_build/ 59 | 60 | # PyBuilder 61 | target/ 62 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "lib/ciscoconfparse"] 2 | path = lib/ciscoconfparse 3 | url = https://github.com/GoSecure/ciscoconfparse 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cisco2checkpoint Migration Tool 2 | 3 | Cisco to Checkpoint is a conversion tool developed by GoSecure to help during migration projects. The tool has the ability to convert objects such as networks, services, groups and even firewall rules. 4 | 5 | The tool requires python 2.7 and a forked version of [ciscoconfparse](https://pypi.python.org/pypi/ciscoconfparse) (included). 6 | 7 | Supported input syntax is currently IOS and ASA. The script output a file in dbedit syntax. 8 | 9 | The script was run on nearly 10 different configurations and leads to many success stories but the tool is still experimental. Use it at your own risk. 10 | 11 | 12 | ## Install 13 | 14 | ``` 15 | git clone --recursive https://github.com/gosecure/cisco2checkpoint c2c 16 | cd c2c 17 | ``` 18 | 19 | ## Simple use case: Fresh Install 20 | 21 | The easiest and most basic way to convert a cisco configuration file, exported with `show run`, as follows. 22 | 23 | ``` 24 | python2.7 c2c.py --export \ 25 | --ciscoFile 'some_cisco_conf.txt' \ 26 | --syntax asa \ 27 | --policy My_Policy \ 28 | --installOn My_Firewall \ 29 | --output 'network_script.txt' \ 30 | ``` 31 | 32 | As a result, the file `network_script.txt` is created and contains the converted policy. Upload the file on the SmartCenter server. Note that you will need a user with a bash shell to upload using SSH. To do so, run `chsh -s /bin/bash` and then logout to apply the change. 33 | 34 | Before import, make sure that no "write mode" session is open with SmartDashboard. Also make sure that there is **no empty lines** and that the return characters are **\n** (not \r\n). Don't forget to **take a backup or a DRC (Database Revision Control)**. 35 | 36 | To perform the import, run: 37 | 38 | ``` 39 | dbedit -local -f network_script.txt -ignore_script_failure -continue_updating 40 | ``` 41 | 42 | ## Advanced use case: Adding FW to existing policy 43 | 44 | If a Checkpoint policy already exists on the SmartCenter server, the script must be aware of the existing objects. It is possible to export those objects in xml format and specify them using a new argument. 45 | 46 | First run the following on the SmartCenter. 47 | 48 | ``` 49 | echo "printxml network_objects" > printxml_netobj.txt 50 | echo "printxml services" > printxml_services.txt 51 | echo '' > customer_network_objects.xml 52 | dbedit -local -f printxml_netobj.txt >> customer_network_objects.xml 53 | echo '' >> customer_network_objects.xml 54 | echo '' > customer_service_objects.xml 55 | dbedit -local -f printxml_services.txt >> customer_service_objects.xml 56 | echo '' >> customer_service_objects.xml 57 | ``` 58 | 59 | Then copy both xml files in the root of the repository and run as follows. 60 | 61 | ``` 62 | python2.7 c2c.py --export \ 63 | --ciscoFile 'some_cisco_conf.txt' \ 64 | --cpPortsFile 'customer_service_objects.xml' \ 65 | --cpNetObjFile 'customer_network_objects.xml' \ 66 | --syntax asa \ 67 | --policy My_Policy \ 68 | --installOn My_Firewall \ 69 | --output 'network_script.txt' 70 | ``` 71 | 72 | As a result, the file `network_script.txt` is created and contains the converted policy. Upload the file on the SmartCenter server. Note that you will need a user with a bash shell to upload using SSH. To do so, run `chsh -s /bin/bash` and then logout to apply the change. 73 | 74 | Before import, make sure that no "write mode" session is open with SmartDashboard. Also make sure that there is **no empty lines** and that the return characters are **\n** (not \r\n). Don't forget to **take a backup or a DRC (Database Revision Control)**. 75 | 76 | To perform the import, run: 77 | 78 | ``` 79 | dbedit -local -f network_script.txt -ignore_script_failure -continue_updating 80 | ``` 81 | 82 | ## Verify the conversion 83 | 84 | Simply replace the `--export` argument by `--verify` and add `--format text` to generate the configuration into a human-readable format. For example: 85 | 86 | ``` 87 | python2.7 c2c.py --verify \ 88 | --format text \ 89 | --ciscoFile 'some_cisco_conf.txt' \ 90 | --syntax asa \ 91 | --policy My_Policy \ 92 | --installOn My_Firewall \ 93 | --output 'network_script_verify.txt' \ 94 | ``` 95 | 96 | In the example below, the last three lines show three `access-list` that were used to generate a single checkpoint rule: 97 | 98 | ``` 99 | ACLRule(name=acl_inside,src=N-Prod-Wks-10.12.160.0_19;N-LAN-Wks-10.16.160.0_24;N-Prod-Wks-10.21.60.0_22,dst=G-xmpp-Internet,port=any,action=permit,pol=FW-Temp,inst=,disabled=False,desc=Access to X) 100 | Desc:Access to X 101 | Src: CiscoNet(name=N-Prod-Wks-10.12.160.0_19,ipAddr=10.12.160.0/255.255.224.0,desc=,alias=) 102 | Src: CiscoNet(name=N-LAN-Wks-10.16.160.0_24,ipAddr=10.16.160.0/255.255.255.0,desc=,alias=) 103 | Src: CiscoNet(name=N-Prod-Wks-10.21.60.0_22,ipAddr=10.21.60.0/255.255.252.0,desc=,alias=N-Prod-Wkstn-10.21.60.0_22) 104 | Dst: CiscoNetGroup(name=G-xmpp-Internet,desc= description Routes de xmpp via Internet,nbMembers=6,alias=) 105 | CiscoNet(name=N-xmpp-Int-160.43.250.0_24,ipAddr=160.43.250.0/255.255.255.0,desc=,alias=) 106 | CiscoNet(name=N-xmpp-Int-206.156.53.0_24,ipAddr=206.156.53.0/255.255.255.0,desc=,alias=) 107 | Port: CiscoAnyPort(name=any,port=0,desc=,alias=) 108 | Verify: 109 | Verify: 110 | Verify: 111 | ``` 112 | 113 | 114 | ## Implicit Behaviors 115 | 116 | **Firewall rationalization** 117 | 118 | By default, firewall rules are merged together if it doesn't affect the security of the policy. For two rules to be merged, all fields except one must be identical. Fewer firewall rules result in better performance and ease of management, which often increase security. 119 | 120 | **Objects Reuse** 121 | 122 | When two objects with the same properties are found, they are merged. For example, if two hosts are defined with the same IP address, the first name is taken. 123 | 124 | **Dynamic Object Generation** 125 | 126 | When a host is defined in a group or an access-list without a name, it is automatically created. The reason is that in Checkpoint everything needs to be a defined object. 127 | 128 | 129 | ## Modifiers 130 | 131 | Those modifiers can be used for specific needs, such as specifying color on objects and enable logging on every rule. 132 | 133 | 134 | --color COLOR The color to use for new objects. 135 | --force-log Force track=Log on all firewall rules 136 | --startIndex INDEX Index to start importing firewall rules. Default: 0 137 | --disableRules Disable all firewall rules. 138 | --flattenInlineNetGroups 139 | Flatten groups with prefix DM_INLINE_NETWORK_ so 140 | members are added to firewall rules instead of the 141 | group. 142 | --flattenInlineSvcGroups 143 | Flatten groups with prefix DM_INLINE_SERVICE_ so 144 | members are added to firewall rules instead of the 145 | group. 146 | 147 | 148 | ## Customization 149 | 150 | A config file is located in `./config.py`. Most users shouldn't need to modify it. However, it is worth knowing the existence of this file. Users will find object prefixes for dynamically created objects, excluded checkpoint services, illegal expression replacements and association tables for ports and protocols. 151 | 152 | 153 | ## Warning 154 | 155 | **Layer 2 vs Layer 3 :** As some of you may know, Checkpoint policy is layer-3 based, meaning that firewall interfaces are completely abstracted from the policy. In fact, it is not possible to assign a rule to an interface like on Cisco. For this reason, you will find many *Drop All* rules within the policy and other rules that make no sense in the context of a layer-3 stateful firewall. Thus, a review must **always** be performed after the import. 156 | 157 | **Cisco syntax :** Cisco tends to be very flexible when it's time to write a line. Some keywords are optional and it is not required to define everything as an object. It also allows one to define an object in multiple ways. Unfortunately, this lead to little hacks in the code. 158 | 159 | 160 | ## License 161 | 162 | cisco2checkpoint is licensed GPLv3; Copyright [GoSecure](https://gosecure.net), 2015-2017. 163 | 164 | 165 | ## Author and Thanks 166 | 167 | cisco2checkpoint was developed by Martin Dubé (mdube at gosecure.ca) 168 | 169 | Special thanks: 170 | - David Michael Pennington for his awesome work on [ciscoconfparse](https://github.com/mpenning/ciscoconfparse) 171 | - Olivier Bilodeau for helping me rebase the project and follow good practices 172 | -------------------------------------------------------------------------------- /c2c.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2 2 | # -*- coding: utf-8 -*- 3 | 4 | ''' 5 | @author: Martin Dubé 6 | @organization: GoSecure 7 | @contact: mdube@gosecure.ca 8 | @license: GPLv3 9 | Copyright (c) 2016, GoSecure 10 | 11 | This program is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation version 3. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program. If not, see . 22 | ''' 23 | 24 | # Python version validation 25 | import sys 26 | if sys.version_info > (2,7,14): 27 | print('Python version 2.7 is needed for this script') 28 | exit(1); 29 | 30 | sys.path.insert(0, 'lib') 31 | del sys 32 | 33 | # Project imports 34 | from cisco2checkpoint import Cisco2Checkpoint,Cisco2CheckpointManager 35 | from config import * 36 | 37 | # System imports 38 | import argparse 39 | import os 40 | 41 | # Get args 42 | description = '''GoSecure cisco2checkpoint migration tool. 43 | 44 | Known limitations 45 | - The script convert "permit" to "allow" and "deny" to "deny". 46 | - The script support only None and Log tracking. 47 | - The script does not feed the "VPN" field. 48 | - The NAT rule translation is buggy (for now). 49 | - The script does not support IPv6 (so any4 or any6 become any) 50 | - Redundant groups are not merged yet. 51 | ''' 52 | epilog = ''' 53 | Examples: 54 | Print a summary of what is parsed 55 | ./cisco2checkpoint.py --ciscoFile 'cisco-run-conf.txt' --summary 56 | 57 | Search some objects 58 | ./cisco2checkpoint.py --ciscoFile 'cisco-run-conf.txt' 59 | --search 'obj-172.16.66.0' --format text 60 | ./cisco2checkpoint.py --ciscoFile 'cisco-run-conf.txt' 61 | --search 'obj-172.16.66.0' --format text --filter CiscoHost 62 | 63 | Export in a human readable form 64 | ./cisco2checkpoint.py --ciscoFile 'cisco-run-conf.txt' --export --format text 65 | 66 | Export for dbedit 67 | ./cisco2checkpoint.py --ciscoFile 'cisco-run-conf.txt' --export 68 | --format dbedit --policy Standard --installOn fw01 --installOn fw02 69 | 70 | ''' 71 | parser = argparse.ArgumentParser( 72 | formatter_class=argparse.RawDescriptionHelpFormatter, \ 73 | description=description, epilog=epilog) 74 | parser.add_argument('-v','--version', action='version', \ 75 | version='%(prog)s '+C2C_VERSION) 76 | parser.add_argument('--debug', action='store_true', dest='debug', \ 77 | default=False, help='Run the tool in debug mode') 78 | 79 | actGrp = parser.add_argument_group("Action", "Select one of these action") 80 | actGrp.add_argument('--summary', '-u', action='store_true', dest='summary', 81 | default=False, \ 82 | help='Print a summary of what is parsed and what would be migrated.') 83 | actGrp.add_argument('--export', '-e', action='store_true', dest='export', default=False, \ 84 | help='Export configuration. Use --format to determine format.') 85 | actGrp.add_argument('--verify', action='store_true', dest='verify', default=False, \ 86 | help='Export configuration like --export but in text format and in a verifyable format.') 87 | actGrp.add_argument('--search', '-s', action='store', dest='search', default='',\ 88 | type=str, metavar='TEXT', help='Search for a specific object.') 89 | 90 | cnfGrp = parser.add_argument_group("Import config") 91 | cnfGrp.add_argument('--ciscoFile', '-c', action='store', dest='ciscoFile', default='', \ 92 | type=str, metavar='FILE', help='Cisco config file to parse.') 93 | cnfGrp.add_argument('--ciscoDir', '-d', action='store', dest='ciscoDir', default='', \ 94 | type=str, metavar='DIR', help='config directory to parse. Will read only *.Config files') 95 | cnfGrp.add_argument('--cpPortsFile', action='store', dest='cpPortsFile', default=DEFAULT_CP_PORT_FILE, \ 96 | type=str, metavar='FILE', help='Checkpoint xml port file to parse. Default: %s' % DEFAULT_CP_PORT_FILE) 97 | cnfGrp.add_argument('--cpNetObjFile', action='store', dest='cpNetObjFile', default=DEFAULT_CP_NETOBJ_FILE, \ 98 | type=str, metavar='FILE', help='Checkpoint xml network objects file to parse. Default: %s' % DEFAULT_CP_NETOBJ_FILE) 99 | cnfGrp.add_argument('--syntax', action='store', dest='syntax', default=DEFAULT_SYNTAX, \ 100 | type=str, help='Specify the cisco syntax. Valid values: ios, asa. '\ 101 | 'Default: %s' % DEFAULT_SYNTAX) 102 | 103 | optGrp = parser.add_argument_group("Options") 104 | optGrp.add_argument('--format', '-f', action='store', dest='format', default=DEFAULT_FORMAT, \ 105 | type=str, help='Specify the format. Valid values: dbedit, text. Default: %s' % DEFAULT_FORMAT) 106 | optGrp.add_argument('--output', '-o', action='store', dest='output', default=DEFAULT_OUTPUT_FILE, \ 107 | type=str, metavar='FILE', help='Output file. Default: %s' % DEFAULT_OUTPUT_FILE) 108 | optGrp.add_argument('--filter', action='append', dest='filter', default=None, \ 109 | type=str, metavar='CLASS', help='Filter a class name, e.g. CiscoHost, CiscoPort, CiscoFwRule. Can use option several times.') 110 | optGrp.add_argument('--stdout', action='store_true', dest='stdout', default=False, \ 111 | help='Print output to stdout.') 112 | 113 | expGrp = parser.add_argument_group("Export Modifiers") 114 | expGrp.add_argument('--policy', action='store', dest='policy', default=DEFAULT_POLICY, \ 115 | type=str, help='The policy name. Relevant with --export only. Default: %s' % DEFAULT_POLICY) 116 | expGrp.add_argument('--installOn', action='store', dest='installOn', default=DEFAULT_INSTALLON, \ 117 | type=str, metavar='FWs', help='Specify the checkpoint object to install rules on. ') 118 | expGrp.add_argument('--natInstallOn', action='store', dest='natInstallOn', default=DEFAULT_NAT_INSTALLON, \ 119 | type=str, metavar='FW', help='The firewall to use for all hide and static NAT rules.') 120 | expGrp.add_argument('--color', action='store', dest='color', default=DEFAULT_NEW_OBJ_COLOR, \ 121 | type=str, metavar='COLOR', help='The color to use for new objects.') 122 | expGrp.add_argument('--force-log', action='store_true', dest='forceLog', default=False, \ 123 | help='Force track=Log on all firewall rules') 124 | expGrp.add_argument('--startIndex', action='store', dest='startIndex', default=DEFAULT_ACL_RULE_INDEX, \ 125 | type=int, metavar='INDEX', help='Index to start importing firewall rules. Default: %i' % DEFAULT_ACL_RULE_INDEX) 126 | expGrp.add_argument('--disableRules', action='store_true', dest='disableRules', default=False, \ 127 | help='Disable all firewall rules.') 128 | expGrp.add_argument('--flattenInlineNetGroups', action='store_true', dest='flattenInlineNetGroups', default=False, \ 129 | help='Flatten groups with prefix DM_INLINE_NETWORK_ so members are added to firewall rules instead of the group.') 130 | expGrp.add_argument('--flattenInlineSvcGroups', action='store_true', dest='flattenInlineSvcGroups', default=False, \ 131 | help='Flatten groups with prefix DM_INLINE_SERVICE_ so members are added to firewall rules instead of the group.') 132 | expGrp.add_argument('--export-cp-obj', action='store_true', dest='exportCPObj', default=False, \ 133 | help='Also export imported Checkpoint Objects.') 134 | 135 | args = parser.parse_args() 136 | 137 | if args.debug: 138 | print(args) 139 | 140 | # Step 1: Validate user input 141 | if not os.path.isfile(str(args.cpPortsFile)): 142 | print('Cannot find checkpoint port file: "%s"' % args.cpPortsFile) 143 | exit(1) 144 | elif not ((args.ciscoFile and os.path.isfile(str(args.ciscoFile))) \ 145 | or (args.ciscoDir and os.path.isdir(args.ciscoDir))): # if dir was specified 146 | print('You must specify either a file or a dir (see --ciscoFile and --ciscoDir)') 147 | exit(1) 148 | if not (args.syntax in ['ios','asa']): 149 | print('Invalid --syntax value. RTFM.') 150 | exit(1) 151 | 152 | if args.ciscoFile != '': 153 | c2c = Cisco2Checkpoint() 154 | elif args.ciscoDir != '': 155 | c2c = Cisco2CheckpointManager() 156 | 157 | c2c.setDebug(args.debug) 158 | c2c.setSyntax(args.syntax) 159 | c2c.setPolicy(args.policy) 160 | c2c.setInstallOn(args.installOn) 161 | c2c.setNatInstallOn(args.natInstallOn) 162 | c2c.setColor(args.color) 163 | c2c.setForceLog(args.forceLog) 164 | c2c.setDisableRules(args.disableRules) 165 | c2c.setACLRuleIndex(args.startIndex) 166 | c2c.setFlattenInlineNetGroups(args.flattenInlineNetGroups) 167 | c2c.setFlattenInlineSvcGroups(args.flattenInlineSvcGroups) 168 | c2c.setExportCPObj(args.exportCPObj) 169 | 170 | if args.ciscoFile != '': 171 | c2c.importConfig(args.cpPortsFile,args.cpNetObjFile,args.ciscoFile) 172 | elif args.ciscoDir != '': 173 | c2c.importConfig(args.cpPortsFile,args.cpNetObjFile,args.ciscoDir) 174 | 175 | # Step 2: Process user request 176 | #try: 177 | if args.summary: 178 | print(MSG_PREFIX+'Generate Summary') 179 | print(c2c.getSummary()) 180 | elif args.search != '': 181 | if args.filter == None: 182 | print(MSG_PREFIX+"Searching for an object. No filter") 183 | obj_list = c2c.findObjByName(args.search) 184 | if len(obj_list) > 0: 185 | print(''.join([obj.toString() for obj in obj_list])) 186 | else: 187 | print(MSG_PREFIX+'No object found') 188 | else: 189 | print(MSG_PREFIX+"Searching for an object with filter(s): %s" % ','.join(args.filter)) 190 | obj_list = c2c.findObjByNameType(args.search,args.filter) 191 | if len(obj_list) > 0: 192 | print(''.join([obj.toString() for obj in obj_list])) 193 | else: 194 | print(MSG_PREFIX+'No object found') 195 | elif args.export: 196 | result = '' 197 | if args.filter == None: 198 | if args.format == 'text': 199 | print(MSG_PREFIX+'Exporting to text format') 200 | result = c2c.getAllObjs() 201 | elif args.format == 'dbedit': 202 | print(MSG_PREFIX+'Exporting to dbedit format') 203 | result = c2c.toDBEdit() 204 | else: 205 | print(WARN_PREFIX+'Invalid format') 206 | else: 207 | if args.format == 'text': 208 | print(MSG_PREFIX+'Exporting to text format') 209 | obj_list = c2c.findObjByType(args.filter) 210 | if len(obj_list) > 0: 211 | result += ''.join([obj.toString() for obj in obj_list]) 212 | else: 213 | print(MSG_PREFIX+'No object found') 214 | elif args.format == 'dbedit': 215 | print(MSG_PREFIX+'Operation not supported yet') 216 | else: 217 | print(WARN_PREFIX+'Invalid format') 218 | 219 | # Print summary 220 | print(c2c.getSummary()) 221 | 222 | # Output 223 | if args.stdout: 224 | print(result) 225 | else: 226 | fd = os.open(args.output, os.O_RDWR|os.O_CREAT|os.O_TRUNC) 227 | os.write(fd,result) 228 | os.close(fd) 229 | elif args.verify: 230 | result = '' 231 | args.format = 'text' 232 | 233 | if args.filter == None: 234 | print(MSG_PREFIX+'Exporting to verify format') 235 | result = c2c.getAllObjs(True) 236 | else: 237 | print(MSG_PREFIX+'Exporting to verify format') 238 | obj_list = c2c.findObjByType(args.filter) 239 | if len(obj_list) > 0: 240 | result += ''.join([obj.toString('', True) for obj in obj_list]) 241 | else: 242 | print(MSG_PREFIX+'No object found') 243 | 244 | # Print summary 245 | print(c2c.getSummary()) 246 | 247 | # Output 248 | if args.stdout: 249 | print(result) 250 | else: 251 | fd = os.open(args.output, os.O_RDWR|os.O_CREAT|os.O_TRUNC) 252 | os.write(fd,result) 253 | os.close(fd) 254 | else: 255 | parser.print_help() 256 | -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2 2 | # -*- coding: utf-8 -*- 3 | 4 | ''' 5 | @author: Martin Dubé 6 | @organization: GoSecure 7 | @contact: mdube@gosecure.ca 8 | @license: GPLv3 9 | Copyright (c) 2016, GoSecure 10 | 11 | This file is part of cisco2checkpoint project. 12 | 13 | This program is free software: you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation version 3. 16 | 17 | This program is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | GNU General Public License for more details. 21 | 22 | You should have received a copy of the GNU General Public License 23 | along with this program. If not, see . 24 | ''' 25 | 26 | C2C_VERSION = '1.1 - 2016-09-07' 27 | C2C_DEBUG = False 28 | 29 | # 30 | # Some default variables mostly used by c2c.py but also by the lib. 31 | # 32 | DEFAULT_FORMAT = 'dbedit' 33 | DEFAULT_CP_NETOBJ_FILE = 'data/default_r7730_network_objects.xml' 34 | DEFAULT_CP_PORT_FILE = 'data/default_r7730_service_objects.xml' 35 | DEFAULT_OUTPUT_FILE = 'network_script.txt' 36 | DEFAULT_POLICY = 'Standard' 37 | DEFAULT_INSTALLON = 'vs01' 38 | DEFAULT_NAT_INSTALLON = 'vs01' 39 | DEFAULT_NEW_OBJ_COLOR = 'black' 40 | DEFAULT_SYNTAX = 'ios' # Valid values: ios|asa 41 | DEFAULT_ACL_RULE_INDEX = 0 42 | 43 | # Product limitation: An ACL name cannot have more than 30 caracters. 44 | # NOT IMPLEMENTED YET. 45 | # Might change in R80 ? 46 | MAX_ACLRU_NAME_LEN = 30 47 | 48 | # 49 | # Some prefix used when creating object dynamically. 50 | # For example, when an object is created without a name, the default name will 51 | # be composed of a prefix and some attributes. Host example: H_10.0.0.1 52 | # 53 | WARN_PREFIX = '#[-] ' 54 | MSG_PREFIX = '#[+] ' 55 | NEW_NET_PREFIX = 'N_' 56 | NEW_HOST_PREFIX = 'H_' 57 | NEW_RANGE_PREFIX = 'R_' 58 | NEW_GROUP_PREFIX = 'G_' 59 | TCPUDP_PREFIX = 'TU_' 60 | TCP_PREFIX = 'TCP_' 61 | UDP_PREFIX = 'UDP_' 62 | 63 | # 64 | # DM INLINE groups are generated by the cisco webui and are rarely desired 65 | # in checkpoint firewall policies. These prefix are used to distinguish them. 66 | # 67 | DM_INLINE_NET_PREFIX = 'DM_INLINE_NETWORK' 68 | DM_INLINE_SVC_PREFIX = 'DM_INLINE_SERVICE' 69 | DM_INLINE_TCP_PREFIX = 'DM_INLINE_TCP' 70 | DM_INLINE_UDP_PREFIX = 'DM_INLINE_UDP' 71 | 72 | # 73 | # "Any" objects usually represent a protocol. For example "any tcp" means all 74 | # tcp ports. The list below represent the default name to use when matching 75 | # a layer 2 or 3 protocol. 76 | # 77 | ANY_ICMP = 'icmp-proto' 78 | ANY_ESP = 'ESP' 79 | ANY_AH = 'AH' 80 | ANY_OSPF = 'ospf' 81 | ANY_VRRP = 'vrrp' 82 | ANY_SKIP = 'SKIP' 83 | ANY_GRE = 'gre' 84 | 85 | # 86 | # These are the protocols supported by the project. They are splitted in two 87 | # constants as IP protocols have ports (or any ports). No IP protocols exist 88 | # but are very basically converted. ICMP is supported with several control 89 | # messages. 90 | # 91 | SUPPORTED_IP_PROTO = ['ip', 'tcp', 'udp', 'tcp-udp'] 92 | SUPPORTED_NO_IP_PROTO = ['icmp', 'esp', 'ah', 'ospf', 'esp', 'ahp', 'vrrp', \ 93 | 'skip', 'gre'] 94 | SUPPORTED_PROTO = SUPPORTED_IP_PROTO + SUPPORTED_NO_IP_PROTO 95 | 96 | # 97 | # Some categories of classes to simplify searches 98 | # 99 | HOST_CLASSES = ['CiscoHost','CiscoAnyHost'] 100 | #NETOBJ_CLASSES = ['CiscoHost','CiscoAnyHost','CiscoNet','CiscoRange'] 101 | #SVCOBJ_CLASSES = ['CiscoServicePort','CiscoServiceRange','CiscoServiceGroup','CiscoAnyPort','CiscoIcmp','CiscoAnyIcmp','CiscoEspProto','CiscoAHProto'] 102 | ANY_CLASSES = ['CiscoAnyHost', 'CiscoAnyIcmp', 'CiscoAnyPort'] 103 | GROUP_CLASSES = ['CiscoNetGroup', 'CiscoServiceGroup', 'CiscoProtoGroup'] 104 | 105 | # Classes that have a name (searchable by name) 106 | NETOBJ_NAMED_CLASSES = ('CiscoHost','CiscoAnyHost','CiscoNet','CiscoRange','CiscoNetGroup') 107 | SVCOBJ_NAMED_CLASSES = ['CiscoServicePort','CiscoServiceRange','CiscoServiceGroup','CiscoAnyPort','CiscoProtoGroup', 'CiscoIcmp','CiscoAnyIcmp','CiscoEspProto','CiscoAHProto'] 108 | 109 | # 110 | # Excluded ports: Ports here are proprietary to checkpoint. The reason why 111 | # they are excluded is that they are redundant with other ones. For examples, 112 | # https and ssl_v3 are both on port 443. By excluding ssl_v3, https is always 113 | # taken when performing a lookup from the port number. 114 | # 115 | EXCLUDE_PORTS = ['ssl_v3', 'ssh_version_2', 'ftp-bidir', 'ftp-pasv', 'ftp-port', \ 116 | 'sip_tls_not_inspected', 'H323_any', 'H323_ras_only', 'snmp-read', \ 117 | 'dhcp-relay', 'dhcp-req-localmodule', 'MSSQL_resolver'] 118 | 119 | # Translate cisco value => checkpoint value 120 | ICMP_DIC = { 'unreachable' : 'dest-unreach', \ 121 | 'echo' : 'echo-request', \ 122 | 'information-request' : 'info-req', \ 123 | 'information-reply' : 'info-reply', \ 124 | 'mask-reply' : 'mask-reply', \ 125 | 'mask-reply' : 'mask-reply', \ 126 | 'parameter-problem' : 'param-prblm', \ 127 | 'mobile-redirect' : 'redirect'} 128 | 129 | # TODO: Update this with the defined reserved word list. 130 | # https://supportcenter.checkpoint.com/supportcenter/portal?eventSubmit_doGoviewsolutiondetails=&solutionid=sk40179 131 | ILLEGAL_DIC = { 'All-Perimeter' : 'All_Perimeter', \ 132 | 'In-Domain' : 'In_Domain', \ 133 | 'GigabitEthernet' : 'Gi', \ 134 | 'HOST' : 'HST', \ 135 | '(' : '-', \ 136 | ')' : '', \ 137 | '-Nets' : '-N', \ 138 | } 139 | 140 | # 141 | # This list is incomplete. In case a port string is not converted, add the 142 | # corresponding port number here. 143 | # 144 | PORT_DIC = { 'echo' : '7', \ 145 | 'daytime' : '13', \ 146 | 'ftp-data' : '20', \ 147 | 'ftp' : '21', \ 148 | 'ssh' : '22', \ 149 | 'telnet' : '23', \ 150 | 'smtp' : '25', \ 151 | 'whois' : '43', \ 152 | 'tacacs' : '49', \ 153 | 'domain' : '53', \ 154 | 'domain-tcp' : '53', \ 155 | 'domain-udp' : '53', \ 156 | 'bootps' : '67', \ 157 | 'bootpc' : '68', \ 158 | 'tftp' : '69', \ 159 | 'http' : '80', \ 160 | 'www' : '80', \ 161 | 'pop2' : '109', \ 162 | 'pop3' : '110', \ 163 | 'sunrpc' : '111', \ 164 | 'ntp' : '123', \ 165 | 'netbios-ns' : '137', \ 166 | 'netbios-dgm' : '138', \ 167 | 'netbios-ssn' : '139', \ 168 | 'netbios-ss' : '139', \ 169 | 'imap4' : '143', \ 170 | 'snmp' : '161', \ 171 | 'snmptrap' : '162', \ 172 | 'ldap': '389', \ 173 | 'ldaps' : '636', \ 174 | 'https' : '443', \ 175 | 'smtps' : '465', \ 176 | 'isakmp' : '500', \ 177 | 'cmd' : '514', \ 178 | 'rsh' : '514', \ 179 | 'syslog' : '514', \ 180 | 'lpd' : '515', \ 181 | 'rtsp' : '554', \ 182 | 'citrix-ica' : '1494', \ 183 | 'sqlnet' : '1521', \ 184 | 'h323' : '1720', \ 185 | 'pptp' : '1723', \ 186 | 'radius' : '1812', \ 187 | 'sip' : '5060 5061', \ 188 | 'aol' : '5190', \ 189 | 'pcanywhere-data' : '5631', \ 190 | 'pcanywhere-status' : '5632' \ 191 | } 192 | 193 | # 194 | # This list should be complete. It refers to the protocol IDs. 195 | # 196 | PROTO_DIC= { \ 197 | '0':'HOPOPT',\ 198 | '1':'ICMP',\ 199 | '2':'IGMP',\ 200 | '3':'GGP',\ 201 | '4':'IPv4',\ 202 | '5':'ST',\ 203 | '6':'TCP',\ 204 | '7':'CBT',\ 205 | '8':'EGP',\ 206 | '9':'IGP',\ 207 | '10':'BBN-RCC-MON',\ 208 | '11':'NVP-II',\ 209 | '12':'PUP',\ 210 | '13':'ARGUS',\ 211 | '14':'EMCON',\ 212 | '15':'XNET',\ 213 | '16':'CHAOS',\ 214 | '17':'UDP',\ 215 | '18':'MUX',\ 216 | '19':'DCN-MEAS',\ 217 | '20':'HMP',\ 218 | '21':'PRM',\ 219 | '22':'XNS-IDP',\ 220 | '23':'TRUNK-1',\ 221 | '24':'TRUNK-2',\ 222 | '25':'LEAF-1',\ 223 | '26':'LEAF-2',\ 224 | '27':'RDP',\ 225 | '28':'IRTP',\ 226 | '29':'ISO-TP4',\ 227 | '30':'NETBLT',\ 228 | '31':'MFE-NSP',\ 229 | '32':'MERIT-INP',\ 230 | '33':'DCCP',\ 231 | '34':'3PC',\ 232 | '35':'IDPR',\ 233 | '36':'XTP',\ 234 | '37':'DDP',\ 235 | '38':'IDPR-CMTP',\ 236 | '39':'TP++',\ 237 | '40':'IL',\ 238 | '41':'IPv6',\ 239 | '42':'SDRP',\ 240 | '43':'IPv6-Route',\ 241 | '44':'IPv6-Frag',\ 242 | '45':'IDRP',\ 243 | '46':'RSVP',\ 244 | '47':'GRE',\ 245 | '48':'DSR',\ 246 | '49':'BNA',\ 247 | '50':'ESP',\ 248 | '51':'AH',\ 249 | '52':'I-NLSP',\ 250 | '53':'SWIPE',\ 251 | '54':'NARP',\ 252 | '55':'MOBILE',\ 253 | '56':'TLSP',\ 254 | '57':'SKIP',\ 255 | '58':'IPv6-ICMP',\ 256 | '59':'IPv6-NoNxt',\ 257 | '60':'IPv6-Opts',\ 258 | '62':'CFTP',\ 259 | '64':'SAT-EXPAK',\ 260 | '65':'KRYPTOLAN',\ 261 | '66':'RVD',\ 262 | '67':'IPPC',\ 263 | '69':'SAT-MON',\ 264 | '70':'VISA',\ 265 | '71':'IPCV',\ 266 | '72':'CPNX',\ 267 | '73':'CPHB',\ 268 | '74':'WSN',\ 269 | '75':'PVP',\ 270 | '76':'BR-SAT-MON',\ 271 | '77':'SUN-ND',\ 272 | '78':'WB-MON',\ 273 | '79':'WB-EXPAK',\ 274 | '80':'ISO-IP',\ 275 | '81':'VMTP',\ 276 | '82':'SECURE-VMTP',\ 277 | '83':'VINES',\ 278 | '84':'TTP',\ 279 | '84':'IPTM',\ 280 | '85':'NSFNET-IGP',\ 281 | '86':'DGP',\ 282 | '87':'TCF',\ 283 | '88':'EIGRP',\ 284 | '89':'OSPFIGP',\ 285 | '90':'Sprite-RPC',\ 286 | '91':'LARP',\ 287 | '92':'MTP',\ 288 | '93':'AX.25',\ 289 | '94':'IPIP',\ 290 | '95':'MICP',\ 291 | '96':'SCC-SP',\ 292 | '97':'ETHERIP',\ 293 | '98':'ENCAP',\ 294 | '100':'GMTP',\ 295 | '101':'IFMP',\ 296 | '102':'PNNI',\ 297 | '103':'PIM',\ 298 | '104':'ARIS',\ 299 | '105':'SCPS',\ 300 | '106':'QNX',\ 301 | '107':'A/N',\ 302 | '108':'IPComp',\ 303 | '109':'SNP',\ 304 | '110':'Compaq-Peer',\ 305 | '111':'IPX-in-IP',\ 306 | '112':'VRRP',\ 307 | '113':'PGM',\ 308 | '115':'L2TP',\ 309 | '116':'DDX',\ 310 | '117':'IATP',\ 311 | '118':'STP',\ 312 | '119':'SRP',\ 313 | '120':'UTI',\ 314 | '121':'SMP',\ 315 | '122':'SM',\ 316 | '123':'PTP',\ 317 | '124':'ISIS over IPv4',\ 318 | '125':'FIRE',\ 319 | '126':'CRTP',\ 320 | '127':'CRUDP',\ 321 | '128':'SSCOPMCE',\ 322 | '129':'IPLT',\ 323 | '130':'SPS',\ 324 | '131':'PIPE',\ 325 | '132':'SCTP',\ 326 | '133':'FC',\ 327 | '134':'RSVP-E2E-IGNORE',\ 328 | '135':'Mobility Header',\ 329 | '136':'UDPLite',\ 330 | '137':'MPLS-in-IP',\ 331 | '138':'manet',\ 332 | '139':'HIP',\ 333 | '140':'Shim6',\ 334 | '141':'WESP',\ 335 | '142':'ROHC',\ 336 | '255':'Reserved'\ 337 | } 338 | 339 | CONFIG_FILE_SUFFIX = '.CONFG' 340 | -------------------------------------------------------------------------------- /data/default_r7730_network_objects.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | CP_default_Office_Mode_addresses_pool 4 | 5 | CP_default_Office_Mode_addresses_pool 6 | 7 | 8 | ReferenceObject 9 | All 10 | globals
11 | {97AEB368-9AEA-11D5-BD16-0090272CCB30} 12 |
13 | 14 | 15 | 16 |
true 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | false 31 | 32 |
33 | 34 | LocalMachine 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | LocalMachine_All_Interfaces 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | InternalNet 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | DMZNet 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | AuxiliaryNet 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | CPDShield 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | WirelessZone 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | DMZZone 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | ExternalZone 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | InternalZone 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | LocalMachine_Loopbackfalse 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | All_Internetfalse 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | Trusted_Zone 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | Internet_Zone 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | my-mgmtfalsefalsefalsefalsefalsefalsefalsefalse 165 | 166 | 167 | truetruefalsefalse 168 | 169 | ReferenceObject 170 | No_protection 171 | profiles
172 | {A744D79A-414B-4C00-8798-9570FDB8719C} 173 |
174 | 175 | my-mgmt 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | falsefalsefalsefalsefalsefalsetrue 184 | 120falsefalse 185 | 186 | falsefalsefalse 187 | 188 | 189 | false 190 | 2 191 | 2 192 | 80truetruefalse 193 | 194 | 195 | falsefalse 196 | 1true 197 | 198 | 1 199 | 200 200 | 5 201 | 15false 202 | false 203 | 204 | falsefalse 205 | 206 | false 207 | falsetrue 208 | 209 | 210 | 211 | 212 | false 213 | false 214 | 215 | 216 | falsefalsefalsefalsefalsetruefalsefalsetruefalsefalse 217 | falsefalse 218 | 219 | 220 | 221 | my-mgmt 222 | 223 | 224 | 225 | 226 | false 227 | 60 228 | 10 229 | 20 230 | 5000 231 | 232 | 10 233 | 1 234 | 300 235 | 90 236 | 600 237 | 65536 238 | 25000 239 | 40 240 | 2048false 241 | 65536 242 | 50000 243 | 90000 244 | 245 | 90 246 | 90 247 | 248 | 249 | 250 | 251 | 252 | false 253 | 254 | 0 255 | 256 | 257 | 258 | falsefalsetruefalsefalsefalse 259 | 260 | 261 | 262 | 263 | 264 | 265 | falsefalse 266 | 267 | 268 | 0 269 | 270 | false 271 | 0 272 | 273 | 274 | 275 | 276 | 277 | true 278 | 279 | 280 | 281 | falsefalsetrue 282 | false 283 | false 284 | 285 | 286 | false 287 | 288 | truefalse 289 | 290 | 291 | 292 | 293 | truefalsefalsefalsefalse 294 | falsefalse 295 | 296 | 297 | false 298 | 3600 299 | 3000 300 | true 301 | 302 | 20falsefalse 303 | 200 304 | 5 305 | 180truefalsefalsefalsefalse 306 | 307 | 100000true 308 | 14 309 | 310 | 5000truefalse 311 | 312 | 0falsefalsefalse 313 | 1000 314 | 100 315 | 316 | 500 317 | 15falsefalse 318 | false 319 | true 320 | 70 321 | 70 322 | true 323 | 324 | 325 | 326 | truefalsefalse 327 | 328 | 329 | 330 | 331 | 10 332 | 1024 333 | 70 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | false 342 | 343 | 344 | 25 345 | 346 | 347 | true 348 | 349 | 1 350 | 351 | 352 | 353 | 10238976 354 | 355 | 10238976 356 | 10238976 357 | 0 358 | 2 359 | 6 360 | 361 | falsefalse 362 | 363 | 364 | 365 | true 366 | 367 | 368 | truefalsefalse 369 | 370 | 371 | true 372 | 373 | 374 | true 375 | 376 | falsefalse 377 | false 378 | 379 | ReferenceObject 380 | None 381 | globals
382 | {97AEB36A-9AEA-11D5-BD16-0090272CCB30} 383 |
false 384 | 385 | truetruefalse 386 | 20000 387 | 388 | 100truefalse 389 | 390 | 10800 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | falsefalse 400 | 401 | 402 | 403 | 404 | 405 | 406 | 0 407 | 0 408 | falsetrue 409 | 410 | 990180000 411 | false 412 | 413 | 414 | falsetruefalsefalsefalse 415 | 416 | 417 |
418 |
419 | -------------------------------------------------------------------------------- /lib/ciscoconfparse_patch.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2 2 | # -*- coding: utf-8 -*- 3 | 4 | ''' 5 | @author: Martin Dubé 6 | @organization: GoSecure 7 | @contact: mdube@gosecure.ca 8 | @license: GPLv3 9 | Copyright (c) 2016, GoSecure 10 | 11 | This file is part of cisco2checkpoint project. 12 | 13 | This program is free software: you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation version 3. 16 | 17 | This program is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | GNU General Public License for more details. 21 | 22 | You should have received a copy of the GNU General Public License 23 | along with this program. If not, see . 24 | ''' 25 | 26 | import re 27 | from collections import Iterator 28 | 29 | from ciscoconfparse import models_cisco 30 | from ciscoconfparse import models_asa 31 | 32 | import ciscoconfparse.ciscoconfparse as ccp 33 | 34 | ## 35 | ##------------- ASA and IOS supported protocols, operators and port names 36 | ## 37 | _PORT_SIMPLE_OP = 'eq|neq|lt|gt' 38 | _PORT_NAMES = r'aol|bgp|chargen|cifs|citrix-ica|cmd|ctiqbe|daytime'\ 39 | '|discard|domain|echo|exec|finger|tftp|ftp-data|ftp|gopher'\ 40 | '|h323|hostname|https|http|ident|imap4|irc|kerberos|klogin'\ 41 | '|kshell|ldaps|ldap|login|lotusnotes|lpd|netbios-ssn|nfs'\ 42 | '|nntp|ntp|pcanywhere-data|pim-auto-rp|pop2|pop3|pptp|rsh'\ 43 | '|rtsp|sip|smtps|smtp|sqlnet|ssh|sunrpc|tacacs|talk|telnet|uucp'\ 44 | '|whois|www|netbios-ns|netbios-dgm|netbios-ss|snmptrap|snmp'\ 45 | '|syslog|isakmp|bootps|bootpc|radius|\d+' 46 | 47 | _ACL_PROTOCOLS = 'ip|tcp|udp|icmp|ahp|ah|eigrp|esp|gre|igmp|igrp|ipinip|ipsec'\ 48 | '|ospf|pcp|pim|pptp|snp|\d+' 49 | _ACL_ICMP_PROTOCOLS = 'alternate-address|conversion-error|echo-reply|echo'\ 50 | '|information-reply|information-request|mask-reply'\ 51 | '|mask-request|mobile-redirect|parameter-problem|redirect'\ 52 | '|router-advertisement|router-solicitation|source-quench'\ 53 | '|time-exceeded|timestamp-reply|timestamp-request|traceroute'\ 54 | '|unreachable' 55 | _ACL_LOGLEVELS = r'alerts|critical|debugging|emergencies|errors'\ 56 | '|informational|notifications|warnings|[0-7]' 57 | _IP_PROTO = 'tcp|udp|tcp-udp' 58 | 59 | ## 60 | ##------------- Extension of an ASA object network 61 | ## 62 | 63 | ## 64 | ##------------- ASA name 65 | ## 66 | 67 | _RE_NAMEOBJECT_STR = r'''(?: # Non-capturing parentesis 68 | # Valid values 69 | # name 1.2.3.4 70 | # name 1.2.3.4 host1 71 | # name 1.2.3.4 host1 description bla bla bla 72 | # 73 | (^name 74 | \s+(?P\d+\.\d+\.\d+\.\d+) 75 | (?:\s+(?P\S+)) 76 | (?:\s+description\s+(?P.+)$)? 77 | ) 78 | ) 79 | ''' 80 | _RE_NAMEOBJECT = re.compile(_RE_NAMEOBJECT_STR, re.VERBOSE) 81 | class ASAName(models_asa.ASACfgLine): 82 | 83 | def __init__(self, *args, **kwargs): 84 | """Accept an ASA line number and initialize family relationship 85 | attributes""" 86 | super(ASAName, self).__init__(*args, **kwargs) 87 | mm = _RE_NAMEOBJECT.search(self.text) 88 | if not (mm is None): 89 | self._mm_results = mm.groupdict() # All regex match results 90 | else: 91 | print self.text 92 | raise ValueError 93 | 94 | self.name = self._mm_results['name'] 95 | self.addr = self._mm_results['addr'] 96 | self.desc = self._mm_results['desc'] 97 | 98 | @classmethod 99 | def is_object_for(cls, line="", re=re): 100 | if 'name ' in line[0:5].lower(): 101 | return True 102 | return False 103 | 104 | @property 105 | def result_dict(self): 106 | mm_r = self._mm_results 107 | retval = dict() 108 | 109 | retval['name'] = self._mm_results['name'] 110 | retval['addr'] = self._mm_results['addr'] 111 | retval['desc'] = self._mm_results['desc'] 112 | 113 | return retval 114 | 115 | 116 | _RE_ASA_NETOBJ_CHILD_STR = r"""(?: 117 | (^\s+description(?P.+)$) 118 | |(^\s+host\s+(?P\S+)$) 119 | |(^\s+subnet\s+(?P\d+\.\d+\.\d+\.\d+)\s+(?P\d+\.\d+\.\d+\.\d+)$) 120 | |(^\s+range\s+(?P\d+\.\d+\.\d+\.\d+)\s+(?P\d+\.\d+\.\d+\.\d+)$) 121 | ) 122 | """ 123 | _RE_ASA_NETOBJ_CHILD = re.compile(_RE_ASA_NETOBJ_CHILD_STR, re.VERBOSE) 124 | class ASAObjNetwork(models_asa.ASAObjNetwork): 125 | 126 | @property 127 | def name(self): 128 | retval = self.re_match_typed(r'^\s*object\snetwork\s+(\S.+)$', 129 | result_type=str, default='') 130 | return retval 131 | 132 | @property 133 | def description(self): 134 | regex = r"(^\s+description(?P.+)$)" 135 | retval = self.re_match_iter_typed(regex, 136 | result_type=str, default='') 137 | return retval 138 | 139 | @property 140 | def result_dict(self): 141 | retval = dict() 142 | 143 | for obj in self.children: 144 | ## Parse out 'service' and 'description' lines 145 | mm = _RE_ASA_NETOBJ_CHILD.search(obj.text) 146 | if not (mm is None): 147 | mm_r = mm.groupdict() 148 | else: 149 | mm_r = dict() 150 | 151 | # host... 152 | if mm_r.get('host1',None): 153 | retval['net_method'] = 'host' 154 | retval['ipaddr'] = mm_r['host1'] 155 | retval['mask'] = '255.255.255.255' 156 | elif mm_r.get('subnet2',None): 157 | retval['net_method'] = 'subnet' 158 | retval['ipaddr'] = mm_r['subnet2'] 159 | retval['mask'] = mm_r['mask2'] 160 | elif mm_r.get('range_low3',None): 161 | retval['net_method'] = 'range' 162 | retval['ipaddr_low'] = mm_r['range_low3'] 163 | retval['ipaddr_high'] = mm_r['range_high3'] 164 | # description 165 | elif mm_r.get('description0',None): 166 | retval['description'] = mm_r['description0'] 167 | else: 168 | raise NotImplementedError("Cannot parse '{0}'".format(obj.text)) 169 | return retval 170 | 171 | ## 172 | ##------------- Extension of an ASA object service 173 | ## 174 | _RE_ASA_SVCOBJ_CHILD_STR = r"""(?: # Non-capturing parentesis 175 | # example: 176 | # service tcp source range 1 65535 destination range 49152 65535 177 | # service tcp source eq bgp destination eq 53 178 | (^\s+description(?P.+)) 179 | |(^\s+service 180 | \s+(?P{0}) 181 | (?:\s+source 182 | (?: # source port 183 | (?:\s+ 184 | (?P{1}) 185 | \s+(?P(?:(?:{2})\s?)+) 186 | ) 187 | |(?:\s+range\s+(?P\d+)\s+(?P\d+)) 188 | |(?:\s+object-group\s+(?P\S+)) 189 | ) 190 | )? 191 | (?:\s+destination 192 | (?: # destination port 193 | (?:\s+ 194 | (?P{1}) 195 | \s+(?P(?:(?:{2})\s?)+) 196 | ) 197 | |(?:\s+range\s+(?P\d+)\s+(?P\d+)) 198 | |(?:\s+object-group\s+(?P\S+)) 199 | ) 200 | ) 201 | ) 202 | ) # Close non-capture parentesis 203 | """.format(_IP_PROTO,_PORT_SIMPLE_OP,_PORT_NAMES) 204 | _RE_ASA_SVCOBJ_CHILD = re.compile(_RE_ASA_SVCOBJ_CHILD_STR, re.VERBOSE) 205 | class ASAObjService(models_asa.ASAObjService): 206 | 207 | # TODO: Parent's class is defined differently. Determine why. 208 | # 209 | # @classmethod 210 | # def is_object_for(cls, line="", re=re): 211 | # if 'object service ' in line[0:15].lower(): 212 | # return True 213 | # return False 214 | @classmethod 215 | def is_object_for(cls, line="", re=re): 216 | if re.search(r'^(object\sservice)', line): 217 | return True 218 | return False 219 | 220 | @property 221 | def name(self): 222 | retval = self.re_match_typed(r'^\s*object\sservice\s+(\S.+)$', 223 | result_type=str, default='') 224 | return retval 225 | 226 | @property 227 | def description(self): 228 | regex = r"(^\s+description(?P.+)$)" 229 | retval = self.re_match_iter_typed(regex, result_type=str, default='') 230 | return retval 231 | 232 | def m_src_port(self,mm_r): 233 | if mm_r['src_port_low1']: 234 | return mm_r['src_port_low1'] + ' ' + mm_r['src_port_high1'] 235 | return mm_r['src_port1'] or mm_r['src_service_group1'] \ 236 | 237 | def m_src_port_method(self,mm_r): 238 | if mm_r['src_port_op1']: 239 | return mm_r['src_port_op1'] 240 | elif mm_r['src_port_low1'] and mm_r['src_port_high1']: 241 | return 'range' 242 | elif mm_r['src_service_group1']: 243 | return 'object-group' 244 | 245 | def m_dst_port(self,mm_r): 246 | if mm_r['dst_port_low1']: 247 | return mm_r['dst_port_low1'] + ' ' + mm_r['dst_port_high1'] 248 | return mm_r['dst_port1'] or mm_r['dst_service_group1'] \ 249 | 250 | def m_dst_port_method(self,mm_r): 251 | if mm_r['dst_port_op1']: 252 | return mm_r['dst_port_op1'] 253 | elif mm_r['dst_port_low1'] and mm_r['dst_port_high1']: 254 | return 'range' 255 | elif mm_r['dst_service_group1']: 256 | return 'object-group' 257 | 258 | @property 259 | def result_dict(self): 260 | """Return a list of strings which represent the source and destination 261 | ports.""" 262 | retval = dict() 263 | 264 | for obj in self.children: 265 | ## Parse out 'service' and 'description' lines 266 | mm = _RE_ASA_SVCOBJ_CHILD.search(obj.text) 267 | if not (mm is None): 268 | mm_r = mm.groupdict() 269 | else: 270 | mm_r = dict() 271 | 272 | # service ... 273 | if mm_r.get('protocol1',None): 274 | retval['proto'] = mm_r['protocol1'] 275 | retval['proto_method'] = 'proto' 276 | retval['src_port'] = self.m_src_port(mm_r) 277 | retval['src_port_method'] = self.m_src_port_method(mm_r) 278 | retval['src_port_op'] = mm_r['src_port_op1'] 279 | retval['src_port_low'] = mm_r['src_port_low1'] 280 | retval['src_port_high'] = mm_r['src_port_high1'] 281 | retval['dst_port'] = self.m_dst_port(mm_r) 282 | retval['dst_port_method'] = self.m_dst_port_method(mm_r) 283 | retval['dst_port_op'] = mm_r['dst_port_op1'] 284 | retval['dst_port_low'] = mm_r['dst_port_low1'] 285 | retval['dst_port_high'] = mm_r['dst_port_high1'] 286 | # description 287 | elif mm_r.get('description0',None): 288 | retval['description'] = mm_r['description0'] 289 | else: 290 | raise NotImplementedError("Cannot parse '{0}'".format(obj.text)) 291 | return retval 292 | 293 | ## 294 | ##------------- ASA object group protocol 295 | ## 296 | _RE_ASA_PROTO_GROUP_CHILD_STR = r"""(?: 297 | (^\s+description(?P.+)$) 298 | |(^\s+protocol-object\s+(?P\S+)$) 299 | ) 300 | """ 301 | _RE_ASA_PROTO_GROUP_CHILD = re.compile(_RE_ASA_PROTO_GROUP_CHILD_STR, re.VERBOSE) 302 | class ASAObjGroupProtocol(models_asa.BaseCfgLine): 303 | def __init__(self, *args, **kwargs): 304 | """Provide attributes on Cisco ASA Service groups""" 305 | super(ASAObjGroupProtocol, self).__init__(*args, **kwargs) 306 | 307 | def __repr__(self): 308 | return "<%s # %s '%s'>" % (self.classname, self.linenum, self.name) 309 | 310 | @classmethod 311 | def is_object_for(cls, line="", re=re): 312 | if re.search(r'^(object-group\sprotocol)', line): 313 | return True 314 | return False 315 | 316 | @property 317 | def name(self): 318 | retval = self.re_match_typed(r'^\s*object-group\sprotocol\s+(\S.+)$', 319 | result_type=str, default='') 320 | return retval 321 | 322 | @property 323 | def description(self): 324 | regex = r"(^\s+description(?P.+)$)" 325 | retval = self.re_match_iter_typed(regex, 326 | result_type=str, default='') 327 | return retval 328 | 329 | @property 330 | def result_dict(self): 331 | """Return a list of strings which represent the source and destination 332 | ports.""" 333 | retval = list() 334 | 335 | for obj in self.children: 336 | ## Parse out 'service' and 'description' lines 337 | mm = _RE_ASA_PROTO_GROUP_CHILD.search(obj.text) 338 | if not (mm is None): 339 | mm_r = mm.groupdict() 340 | else: 341 | mm_r = dict() 342 | 343 | # description 344 | if mm_r.get('description0',None): 345 | pass 346 | # protocol... 347 | elif mm_r.get('protocol1',None): 348 | retval.append(mm_r['protocol1']) 349 | else: 350 | raise NotImplementedError("Cannot parse '{0}'".format(obj.text)) 351 | return retval 352 | 353 | ## 354 | ##------------- ASA object-group service 355 | ## 356 | ## This class already exist in ciscoconfparse but I have rewrite it for 357 | ## convenience and delivery delay. 358 | ## TODO: Extend the class instead of rewriting it. 359 | ## 360 | # Difference between service-object and port-object 361 | # 362 | # object-group service WEB-PORTS tcp <- proto is here 363 | # port-object eq www 364 | # port-object eq https 365 | # 366 | # object-group service WEB-PORTS 367 | # service-object tcp eq 80 <- proto is here 368 | # service-object tcp eq 443 <- proto is here 369 | # 370 | _RE_ASA_SVCGROUP_CHILD_STR = r"""(?: # Non-capturing parentesis 371 | # TODO: Add support for source ports in this regex 372 | # Examples group_suffix 373 | # service-object icmp|ip|tcp|udp|.. 1 374 | # service-object udp destination eq dns 2 375 | # service-object tcp eq 80 2 376 | # service-object tcp range 5000 5005 3 377 | # service-object object TCP_4443 4 378 | # port-object eq https 5 379 | # port-object range 1 1024 6 380 | # group-object RPC_High_ports_TCP 7 381 | # icmp-object echo-reply|time-exceeded|.. 8 382 | # service-object icmp echo-reply|time-exceeded|... 9 383 | # 384 | (^\s+description\s+(?P.*)$) 385 | |(^\s+service-object\s+(?P{3})$) 386 | |(^\s+service-object\s+(?P{0})(?:\s+destination)? 387 | \s+(?P{1})\s+(?P{2})) 388 | |(^\s+service-object\s+(?P{0})(?:\s+destination)? 389 | \s+(?Prange)\s+(?P\d+)\s+(?P\d+)) 390 | |(^\s+service-object\sobject\s+(?P\S+)) 391 | |(^\s+port-object\s+(?P{1})\s+(?P{2})) 392 | |(^\s+port-object\s+(?Prange) 393 | \s+(?P\d+)\s+(?P\d+)) 394 | |(^\s+group-object\s+(?P\S+)) 395 | |(^\s+icmp-object\s+(?P\S+)) 396 | |(^\s+service-object\sicmp\s+(?P\S+)) 397 | ) # Close non-capture parens 398 | """.format(_IP_PROTO,_PORT_SIMPLE_OP,_PORT_NAMES,_ACL_PROTOCOLS) 399 | _RE_ASA_SVCGROUP_CHILD = re.compile(_RE_ASA_SVCGROUP_CHILD_STR, re.VERBOSE) 400 | class ASAObjGroupService(models_asa.ASAObjGroupService): 401 | def __init__(self, *args, **kwargs): 402 | """Provide attributes on Cisco ASA Service groups""" 403 | super(ASAObjGroupService, self).__init__(*args, **kwargs) 404 | 405 | # Update to catch specific cases 406 | self.name = self.re_match_typed(r'object-group\s+service\s+(\S+)\s*.*$', 407 | result_type=str, default='') 408 | 409 | def __repr__(self): 410 | return "<%s # %s '%s'>" % (self.classname, self.linenum, self.name) 411 | 412 | @classmethod 413 | def is_object_for(cls, line="", re=re): 414 | if re.search(r'^(?:object-group\sservice)', line): 415 | return True 416 | return False 417 | 418 | @property 419 | def description(self): 420 | retval = self.re_match_iter_typed(r'\s+description\s+(\S+)$', 421 | result_type=str, default='') 422 | return retval 423 | 424 | @property 425 | def proto(self): 426 | retval = self.re_match(r'object-group\s+service\s+(?:\S+)\s+(\S+)?$', 427 | group=1, default=None) 428 | return retval 429 | 430 | def m_proto(self,mm_r): 431 | return mm_r['protocol1'] or mm_r['protocol2'] or mm_r['protocol3'] \ 432 | or self.proto 433 | 434 | def m_proto_method(self,mm_r): 435 | if mm_r['protocol1']: 436 | return 'protocol' 437 | elif mm_r['protocol2'] or mm_r['protocol3']: 438 | return 'service-object' 439 | elif mm_r['dst_group7']: 440 | return 'group' 441 | elif mm_r['dst_object4']: 442 | return 'object' 443 | elif mm_r['dst_icmp_msg8'] or mm_r['dst_icmp_msg9']: 444 | return 'icmp' 445 | elif self.proto: 446 | return 'port-object' 447 | 448 | def m_dst_port(self,mm_r): 449 | if mm_r['dst_port_op3']: 450 | return mm_r['dst_port_low3'] + ' ' + mm_r['dst_port_high3'] 451 | elif mm_r['dst_port_op6']: 452 | return mm_r['dst_port_low6'] + ' ' + mm_r['dst_port_high6'] 453 | return mm_r['dst_port2'] or mm_r['dst_port5'] \ 454 | or mm_r['dst_object4'] or mm_r['dst_group7'] or mm_r['dst_icmp_msg8'] \ 455 | or mm_r['dst_icmp_msg9'] 456 | 457 | def m_dst_port_method(self,mm_r): 458 | if mm_r['dst_port_op2']: 459 | return mm_r['dst_port_op2'] 460 | elif mm_r['dst_port_op5']: 461 | return mm_r['dst_port_op5'] 462 | elif (mm_r['dst_port_low3'] and mm_r['dst_port_high3'])\ 463 | or (mm_r['dst_port_low6'] and mm_r['dst_port_high6']): 464 | return 'range' 465 | elif mm_r['dst_object4']: 466 | return 'object' 467 | elif mm_r['dst_group7']: 468 | return 'group' 469 | elif mm_r['dst_icmp_msg8'] or mm_r['dst_icmp_msg9']: 470 | return 'icmp' 471 | 472 | def m_dst_port_op(self,mm_r): 473 | return mm_r['dst_port_op2'] or mm_r['dst_port_op3'] \ 474 | or mm_r['dst_port_op5'] or mm_r['dst_port_op6'] 475 | 476 | def m_service_name_exist(self,name): 477 | group_ports = self.confobj.object_group_service.get(name, None) \ 478 | or self.confobj.object_service.get(name, None) \ 479 | or self.confobj.object_group_protocol.get(name, None) 480 | 481 | if name==self.name: 482 | ## Throw an error when importing self 483 | raise ValueError("FATAL: Cannot recurse through group-object {0} in object-group service {1}".format(name, self.name)) 484 | if (group_ports is None): 485 | return False 486 | return True 487 | 488 | @property 489 | def result_dict(self): 490 | """ 491 | Return a list of objects which represent the protocol and ports 492 | allowed by this object-group 493 | """ 494 | retval = list() 495 | for obj in self.children: 496 | mm = _RE_ASA_SVCGROUP_CHILD.search(obj.text) 497 | if not (mm is None): 498 | mm_r = mm.groupdict() 499 | else: 500 | raise ValueError("[FATAL] models_asa cannot parse '{0}'"\ 501 | .format(obj.text)) 502 | 503 | if mm_r.get('description0',None): 504 | pass 505 | else: 506 | svc = dict() 507 | svc['proto'] = self.m_proto(mm_r) 508 | svc['proto_method'] = self.m_proto_method(mm_r) 509 | svc['dst_port'] = self.m_dst_port(mm_r) 510 | svc['dst_port_method'] = self.m_dst_port_method(mm_r) 511 | svc['dst_port_op'] = self.m_dst_port_op(mm_r) 512 | svc['dst_port_low'] = mm_r['dst_port_low3'] or mm_r['dst_port_low6'] 513 | svc['dst_port_high'] = mm_r['dst_port_high3'] or mm_r['dst_port_low6'] 514 | 515 | # Make sure the service group was defined before 516 | if self.m_dst_port_method(mm_r) in ['object','group']: 517 | name = self.m_dst_port(mm_r) 518 | if not self.m_service_name_exist(name): 519 | raise ValueError("FATAL: Cannot find service object named {0}"\ 520 | .format(name)) 521 | 522 | retval.append(svc) 523 | 524 | return retval 525 | 526 | ## 527 | ##------------- ASA object-group network 528 | ## 529 | _RE_ASA_NETOBJECT_STR = r"""(?: # Non-capturing parenthesis 530 | (^\s+description(?P.+)$) 531 | |(^\s+network-object\s+host\s+(?P\S+)) 532 | |(^\s+network-object 533 | (?:\s+network)? 534 | \s+(?P\d+\.\d+\.\d+\.\d+) 535 | \s+(?P\d+\.\d+\.\d+\.\d+)) 536 | |(^\s+network-object 537 | \s+(?P\S+) 538 | \s+(?P\d+\.\d+\.\d+\.\d+)) 539 | |(^\s+network-object\s+object\s+(?P\S+)) 540 | |(^\s+group-object\s+(?P\S+)) 541 | ) # Close non-capture parens 542 | """ 543 | _RE_ASA_NETOBJECT = re.compile(_RE_ASA_NETOBJECT_STR, re.VERBOSE) 544 | class ASAObjGroupNetwork(models_asa.ASAObjGroupNetwork): 545 | 546 | def __init__(self, *args, **kwargs): 547 | """Accept an ASA line number and initialize family relationship 548 | attributes""" 549 | super(ASAObjGroupNetwork, self).__init__(*args, **kwargs) 550 | 551 | # Main diff with current code: Additional .+ to catch specific cases. 552 | self.name = self.re_match_typed(r'^object-group\snetwork\s+(\S.+)$', 553 | result_type=str, default='') 554 | 555 | @classmethod 556 | def is_object_for(cls, line="", re=re): 557 | if re.search(r'^(?:object-group\snetwork)', line): 558 | return True 559 | return False 560 | 561 | @property 562 | def description(self): 563 | regex = r"(^\s+description(?P.+)$)" 564 | retval = self.re_match_iter_typed(regex, 565 | result_type=str, default='') 566 | return retval 567 | 568 | def m_network_name_exist(self, name): 569 | group_ports = self.confobj.object_group_network.get(name, None) \ 570 | or self.confobj.object_network.get(name, None) 571 | 572 | if name==self.name: 573 | ## Throw an error when importing self 574 | raise ValueError('FATAL: Cannot recurse through group-object {0}'\ 575 | ' in object-group or object network {1}'\ 576 | .format(name, self.name)) 577 | if (group_ports is None): 578 | return False 579 | return True 580 | 581 | @property 582 | def result_dict(self): 583 | """Return a list of objects which represent 584 | the network group members""" 585 | retval = list() 586 | for obj in self.children: 587 | mm = _RE_ASA_NETOBJECT.search(obj.text) 588 | if not (mm is None): 589 | mm_r = mm.groupdict() 590 | else: 591 | raise ValueError("[FATAL] models_asa cannot parse '{0}'"\ 592 | .format(obj.text)) 593 | 594 | net_obj = dict() 595 | if mm_r.get('description0',None): 596 | net_obj['member_method'] = 'description' 597 | elif mm_r.get('host', None): 598 | net_obj['ipaddr'] = mm_r['host'] 599 | net_obj['mask'] = '255.255.255.255' 600 | net_obj['member_method'] = 'host' 601 | elif mm_r.get('network', None): 602 | net_obj['subnet'] = mm_r['network'] 603 | net_obj['mask'] = mm_r['netmask1'] 604 | net_obj['member_method'] = 'subnet' 605 | elif mm_r.get('name', None): 606 | # Make sure the name was defined before 607 | if not mm_r['name'] in self.confobj.names: 608 | raise ValueError("FATAL: Cannot find network object named {0}"\ 609 | .format(net_obj['object_name'])) 610 | 611 | if mm_r['netmask2'] == '255.255.255.255': 612 | net_obj['ipaddr'] = self.confobj.names[mm_r['name']] 613 | net_obj['mask'] = mm_r['netmask2'] 614 | net_obj['member_method'] = 'host' 615 | else: 616 | net_obj['subnet'] = self.confobj.names[mm_r['name']] 617 | net_obj['mask'] = mm_r['netmask2'] 618 | net_obj['member_method'] = 'subnet' 619 | elif mm_r.get('groupobject', None): 620 | net_obj['object_name'] = mm_r['groupobject'] 621 | net_obj['member_method'] = 'group-object' 622 | # Make sure the network group was defined before 623 | if not self.m_network_name_exist(mm_r['groupobject']): 624 | raise ValueError("FATAL: Cannot find network object named {0}"\ 625 | .format(name)) 626 | elif mm_r.get('object', None): 627 | net_obj['object_name'] = mm_r['object'] 628 | net_obj['member_method'] = 'object' 629 | # Make sure the network object was defined before 630 | if not self.m_network_name_exist(mm_r['object']): 631 | raise ValueError("FATAL: Cannot find network object named {0}"\ 632 | .format(name)) 633 | retval.append(net_obj) 634 | 635 | return retval 636 | 637 | ## 638 | ##------------- ASA ACL object 639 | ## 640 | ## This class already exist in ciscoconfparse but I have rewrite it for 641 | ## convenience and delivery delay. 642 | ## TODO: Extend the class instead of rewriting it. 643 | ## 644 | _RE_ASA_ACL_STR = r"""(?: # Non-capturing parenthesis 645 | # remark 646 | (^access-list\s+(?P\S+)\s+(?Premark)\s+(?P.*)$) 647 | 648 | # extended service object with source network object, destination network object 649 | |(?:^access-list\s+(?P\S+) 650 | \s+(?Pextended) 651 | \s+(?Ppermit|deny) 652 | \s+(?: # proto 653 | (?:object-group\s+(?P\S+)) 654 | |(?:object\s+(?P\S+)) 655 | |(?P{0}) 656 | ) 657 | \s+(?: # source addr 658 | (?Pany|any4|any6) 659 | |(?:object-group\s+(?P\S+)) 660 | |(?:object\s+(?P\S+)) 661 | |(?:host\s+(?P\S+)) 662 | |(?:(?P\S+)\s+0\.0\.0\.0) 663 | |(?:(?P\S+)\s+(?P\d+\.\d+\.\d+\.\d+)) 664 | ) 665 | \s+(?: # destination addr 666 | (?Pany|any4|any6) 667 | |(?:object-group\s+(?P\S+)) 668 | |(?:object\s+(?P\S+)) 669 | |(?:host\s+(?P\S+)) 670 | |(?:(?P\S+)\s+0\.0\.0\.0) 671 | |(?:(?P\S+)\s+(?P\d+\.\d+\.\d+\.\d+)) 672 | ) 673 | (?:\s+ 674 | (?: # destination port 675 | (?: 676 | (?Peq|neq|lt|gt) 677 | \s(?P(?:(?:{3})\s?)+) 678 | ) 679 | |(?:range\s+(?P\S+)\s+(?P\S+)) 680 | |(?:object-group\s+(?P\S+)) 681 | ) 682 | )? 683 | (?:\s+ 684 | (?Plog) 685 | (?:\s+(?P{1}))? 686 | (?:\s+interval\s+(?P\d+))? 687 | )? 688 | (?:\s+(?Pdisable))? 689 | (?: 690 | (?:\s+(?Pinactive)) 691 | |(?:\s+time-range\s+(?P\S+)) 692 | )? 693 | \s*$) # END access-list 1 parse 694 | 695 | #access-list TESTME extended permit icmp any4 0.0.0.0 0.0.0.0 unreachable log interval 1 696 | |(?:^access-list\s+(?P\S+) 697 | \s+(?Pextended) 698 | \s+(?Ppermit|deny) 699 | \s+(?Picmp) 700 | \s+(?: # source addr 701 | (?Pany|any4|any6) 702 | |(?:object-group\s+(?P\S+)) 703 | |(?:object\s+(?P\S+)) 704 | |(?:host\s+(?P\S+)) 705 | |(?:(?P\S+)\s+0\.0\.0\.0) 706 | |(?:(?P\S+)\s+(?P\d+\.\d+\.\d+\.\d+)) 707 | ) 708 | \s+(?: # destination addr 709 | (?Pany|any4|any6) 710 | |(?:object-group\s+(?P\S+)) 711 | |(?:object\s+(?P\S+)) 712 | |(?:host\s+(?P\S+)) 713 | |(?:(?P\S+)\s+0\.0\.0\.0) 714 | |(?:(?P\S+)\s+(?P\d+\.\d+\.\d+\.\d+)) 715 | ) 716 | (?:\s+(?P{3}|\d+))? 717 | (?:\s+ 718 | (?Plog) 719 | (?:\s+(?P{1}))? 720 | (?:\s+interval\s+(?P\d+))? 721 | )? 722 | (?:\s+(?Pdisable))? 723 | (?: 724 | (?:\s+(?Pinactive)) 725 | |(?:\s+time-range\s+(?P\S+)) 726 | )? 727 | ) 728 | 729 | # access-list SPLIT_TUNNEL_NETS standard permit 192.0.2.0 255.255.255.0 730 | |(?:^access-list\s+(?P\S+) 731 | \s+(?Pstandard) 732 | \s+(?Ppermit|deny) 733 | \s+(?: # destination addr 734 | (?Pany|any4|any6) 735 | |(?:object-group\s+(?P\S+)) 736 | |(?:object\s+(?P\S+)) 737 | |(?:host\s+(?P\S+)) 738 | |(?:(?P\S+)\s+0\.0\.0\.0) 739 | |(?:(?P\S+)) 740 | |(?:(?P\S+)\s+(?P\d+\.\d+\.\d+\.\d+)) 741 | ) 742 | (?:\s+ 743 | (?Plog) 744 | (?:\s+(?P{2}))? 745 | (?:\s+interval\s+(?P\d+))? 746 | )? 747 | (?:\s+(?Pdisable))? 748 | (?: 749 | (?:\s+(?Pinactive)) 750 | |(?:\s+time-range\s+(?P\S+)) 751 | )? 752 | ) 753 | ) # Close non-capture parens 754 | """.format(_ACL_PROTOCOLS, _ACL_LOGLEVELS, _ACL_ICMP_PROTOCOLS, _PORT_NAMES) 755 | _RE_ASA_ACL = re.compile(_RE_ASA_ACL_STR, re.VERBOSE) 756 | 757 | class ASAAclLine(models_asa.ASACfgLine): 758 | 759 | def __init__(self, *args, **kwargs): 760 | """Provide attributes on Cisco ASA Access-Lists""" 761 | super(ASAAclLine, self).__init__(*args, **kwargs) 762 | mm = _RE_ASA_ACL.search(self.text) 763 | if not (mm is None): 764 | self._mm_results = mm.groupdict() # All regex match results 765 | else: 766 | raise ValueError("[FATAL] models_asa cannot parse '{0}'".format(self.text)) 767 | 768 | @classmethod 769 | def is_object_for(cls, line="", re=re): 770 | if re.search('^access-list', line): 771 | return True 772 | return False 773 | 774 | @property 775 | def name(self): 776 | mm_r = self._mm_results 777 | return mm_r['name0'] or mm_r['name1'] or mm_r['name2'] \ 778 | or mm_r['name3'] 779 | 780 | @property 781 | def type(self): 782 | mm_r = self._mm_results 783 | return mm_r['type0'] or mm_r['type1'] or mm_r['type2'] or mm_r['type3'] 784 | 785 | @property 786 | def action(self): 787 | mm_r = self._mm_results 788 | return mm_r['action1'] or mm_r['action2'] or mm_r['action3'] 789 | 790 | @property 791 | def remark(self): 792 | mm_r = self._mm_results 793 | return mm_r['remark'] 794 | 795 | @property 796 | def proto(self): 797 | mm_r = self._mm_results 798 | return mm_r['service_objectgroup1'] or mm_r['service_object1'] \ 799 | or mm_r['protocol1'] or mm_r['protocol2'] 800 | 801 | @property 802 | def proto_method(self): 803 | mm_r = self._mm_results 804 | if mm_r['protocol1'] or mm_r['protocol2']: 805 | return 'proto' 806 | elif mm_r['service_objectgroup1'] or mm_r['service_object1']: 807 | return 'object-group' 808 | elif self.action == 'remark': 809 | return 'remark' 810 | 811 | @property 812 | def src_addr(self): 813 | mm_r = self._mm_results 814 | return mm_r['src_any1'] or mm_r['src_objectgroup1'] \ 815 | or mm_r['src_object1'] or mm_r['src_host1a'] \ 816 | or mm_r['src_host1b'] \ 817 | or mm_r['src_network1'] \ 818 | \ 819 | or mm_r['src_any2'] or mm_r['src_objectgroup2'] \ 820 | or mm_r['src_object2'] or mm_r['src_host2a'] \ 821 | or mm_r['src_host2b'] \ 822 | or mm_r['src_network2'] 823 | 824 | @property 825 | def src_hostmask(self): 826 | mm_r = self._mm_results 827 | method = self.src_addr_method 828 | if method == 'any': 829 | return '255.255.255.255' 830 | elif method == 'host': 831 | return '0.0.0.0' 832 | elif method == 'network': 833 | return mm_r['src_hostmask1'] or mm_r['src_hostmask2'] 834 | elif method == 'object-group' or method == 'object' \ 835 | or method == 'remark' \ 836 | or self.parent.type == 'standard': # standard acl = no src ip 837 | return None 838 | 839 | @property 840 | def src_addr_method(self): 841 | mm_r = self._mm_results 842 | if mm_r['src_any1'] or mm_r['src_any2']: 843 | return 'any' 844 | elif mm_r['src_objectgroup1'] or mm_r['src_objectgroup2']: 845 | return 'object-group' 846 | elif mm_r['src_object1'] or mm_r['src_object2']: 847 | return 'object' 848 | elif mm_r['src_host1a'] or mm_r['src_host1b'] \ 849 | or mm_r['src_host2a'] or mm_r['src_host2b']: 850 | return 'host' 851 | elif (mm_r['src_network1'] or mm_r['src_hostmask1']) \ 852 | or (mm_r['src_network2'] or mm_r['src_hostmask2']): 853 | return 'network' 854 | elif self.action == 'remark': 855 | return 'remark' 856 | elif self.parent.type == 'standard': # standard acl = no src ip 857 | return None 858 | 859 | @property 860 | def src_port(self): 861 | return None 862 | 863 | @property 864 | def src_port_method(self): 865 | return None 866 | 867 | @property 868 | def dst_addr(self): 869 | mm_r = self._mm_results 870 | return mm_r['dst_any1'] or mm_r['dst_objectgroup1'] \ 871 | or mm_r['dst_object1'] or mm_r['dst_host1a'] \ 872 | or mm_r['dst_host1b'] \ 873 | or mm_r['dst_network1'] \ 874 | \ 875 | or mm_r['dst_any2'] or mm_r['dst_objectgroup2'] \ 876 | or mm_r['dst_object2'] or mm_r['dst_host2a'] \ 877 | or mm_r['dst_host2b'] \ 878 | or mm_r['dst_network2'] \ 879 | \ 880 | or mm_r['dst_any3'] or mm_r['dst_objectgroup3'] \ 881 | or mm_r['dst_object3'] or mm_r['dst_host3a'] \ 882 | or mm_r['dst_host3b'] or mm_r['dst_host3c']\ 883 | or mm_r['dst_network3'] 884 | 885 | @property 886 | def dst_hostmask(self): 887 | mm_r = self._mm_results 888 | method = self.dst_addr_method 889 | if method == 'any': 890 | return '255.255.255.255' 891 | elif method == 'host': 892 | return '0.0.0.0' 893 | elif method == 'network': 894 | return mm_r['dst_hostmask1'] or mm_r['dst_hostmask2'] \ 895 | or mm_r['dst_hostmask3'] 896 | elif method == 'object-group' or method == 'object' \ 897 | or method == 'remark': 898 | return None 899 | else: 900 | return None 901 | 902 | @property 903 | def dst_addr_method(self): 904 | mm_r = self._mm_results 905 | if mm_r['dst_any1'] or mm_r['dst_any2'] or mm_r['dst_any3']: 906 | return 'any' 907 | elif mm_r['dst_objectgroup1'] or mm_r['dst_objectgroup2'] \ 908 | or mm_r['dst_objectgroup3']: 909 | return 'object-group' 910 | elif mm_r['dst_object1'] or mm_r['dst_object2'] or mm_r['dst_object3']: 911 | return 'object' 912 | elif mm_r['dst_host1a'] or mm_r['dst_host1b'] \ 913 | or mm_r['dst_host2a'] or mm_r['dst_host2b'] \ 914 | or mm_r['dst_host3a'] or mm_r['dst_host3b'] \ 915 | or mm_r['dst_host3c']: 916 | return 'host' 917 | elif (mm_r['dst_network1'] and mm_r['dst_hostmask1']) \ 918 | or (mm_r['dst_network2'] and mm_r['dst_hostmask2']) \ 919 | or (mm_r['dst_network3'] and mm_r['dst_hostmask3']): 920 | return 'network' 921 | elif self.action == 'remark': 922 | return 'remark' 923 | else: 924 | return None 925 | 926 | @property 927 | def dst_port(self): 928 | mm_r = self._mm_results 929 | if self.dst_port_method == 'range': 930 | return mm_r['dst_port_low1'] + ' ' + mm_r['dst_port_high1'] 931 | return mm_r['dst_port1'] or mm_r['dst_service_group1'] 932 | 933 | @property 934 | def dst_port_method(self): 935 | mm_r = self._mm_results 936 | if mm_r['dst_port_op1']: 937 | return mm_r['dst_port_op1'] 938 | elif mm_r['dst_port_low1'] and mm_r['dst_port_high1']: 939 | return 'range' 940 | elif mm_r['dst_service_group1']: 941 | return 'object-group' 942 | 943 | @property 944 | def log(self): 945 | mm_r = self._mm_results 946 | return mm_r['log1'] or mm_r['log2'] 947 | 948 | @property 949 | def log_level(self): 950 | mm_r = self._mm_results 951 | return mm_r['log_level1'] or mm_r['log_level2'] 952 | 953 | @property 954 | def log_interval(self): 955 | mm_r = self._mm_results 956 | return mm_r['log_interval1'] or mm_r['log_interval2'] 957 | 958 | @property 959 | def disable(self): 960 | mm_r = self._mm_results 961 | return mm_r['disable1'] or mm_r['disable2'] 962 | 963 | @property 964 | def inactive(self): 965 | mm_r = self._mm_results 966 | return mm_r['inactive1'] or mm_r['inactive2'] 967 | 968 | @property 969 | def time_range(self): 970 | mm_r = self._mm_results 971 | return mm_r['time_range1'] or mm_r['time_range2'] 972 | 973 | # TODO: This should not be needed 974 | # Otherwise: fix code to support this attribute. 975 | @property 976 | def established(self): 977 | mm_r = self._mm_results 978 | return mm_r['established'] 979 | 980 | class ASAConfigList(ccp.ASAConfigList): 981 | def __init__(self, data=None, comment_delimiter='!', debug=False, 982 | factory=False, ignore_blank_lines=True, syntax='asa', CiscoConfParse=None): 983 | super(ASAConfigList, self).__init__(data, comment_delimiter, debug, factory, \ 984 | ignore_blank_lines, syntax, CiscoConfParse) 985 | 986 | ### New Internal structures 987 | self._RE_NETS = re.compile(r'^\s*object\s+network\s+(\S+)') 988 | self._RE_SVCS = re.compile(r'^\s*object\s+service\s+(\S+)') 989 | self._RE_OBJPRO = re.compile(r'^\s*object-group\s+protocol\s+(\S+)') 990 | 991 | @property 992 | def object_network(self): 993 | """Return a dictionary of name to object network mappings""" 994 | retval = dict() 995 | obj_rgx = self._RE_NETS 996 | for obj in self.CiscoConfParse.find_objects(obj_rgx): 997 | name = obj.re_match_typed(obj_rgx, group=1, result_type=str) 998 | retval[name] = obj 999 | return retval 1000 | 1001 | @property 1002 | def object_service(self): 1003 | """Return a dictionary of name to object network mappings""" 1004 | retval = dict() 1005 | obj_rgx = self._RE_SVCS 1006 | for obj in self.CiscoConfParse.find_objects(obj_rgx): 1007 | name = obj.re_match_typed(obj_rgx, group=1, result_type=str) 1008 | retval[name] = obj 1009 | return retval 1010 | 1011 | @property 1012 | def object_group_service(self): 1013 | """Return a dictionary of name to object-group service mappings""" 1014 | retval = dict() 1015 | obj_rgx = self._RE_OBJSVC 1016 | for obj in self.CiscoConfParse.find_objects(obj_rgx): 1017 | name = obj.re_match_typed(obj_rgx, group=1, result_type=str) 1018 | retval[name] = obj 1019 | return retval 1020 | 1021 | @property 1022 | def object_group_protocol(self): 1023 | """Return a dictionary of name to object-group protocol mappings""" 1024 | retval = dict() 1025 | obj_rgx = self._RE_OBJPRO 1026 | for obj in self.CiscoConfParse.find_objects(obj_rgx): 1027 | name = obj.re_match_typed(obj_rgx, group=1, result_type=str) 1028 | retval[name] = obj 1029 | return retval 1030 | 1031 | 1032 | ## 1033 | ##------------- IOS ACL object 1034 | ## 1035 | _RE_IOS_ACL_STR = r"""(?: # Non-capturing parenthesis 1036 | # basic access-list 1037 | # access-list 10 permet 1.2.3.4 0.0.15.255 1038 | (?:^access-list\s+(?P\S+) 1039 | \s+(?Ppermit|deny) 1040 | \s+(?: # 10.0.0.0 255.255.255.0 1041 | (?Pany|any4|any6) 1042 | |(?:object-group\s+(?P\S+)) 1043 | |(?:object\s+(?P\S+)) 1044 | |(?:host\s+(?P\S+)) 1045 | |(?:(?P\S+)\s+0\.0\.0\.0) 1046 | |(?:(?P\S+)) 1047 | |(?:(?P\S+)\s+(?P\d+\.\d+\.\d+\.\d+)) 1048 | ) 1049 | (?:\s+ 1050 | (?Plog) 1051 | (?:\s+(?P{1}))? 1052 | (?:\s+interval\s+(?P\d+))? 1053 | )? 1054 | (?:\s+(?Pdisable))? 1055 | (?: 1056 | (?:\s+(?Pinactive)) 1057 | |(?:\s+time-range\s+(?P\S+)) 1058 | )? 1059 | \s*$) # END access-list 0 parse 1060 | 1061 | # extended access-list 1062 | # access-list 100 permit ip any host 10.1.2.3 1063 | |(?:^access-list\s+(?P\S+) 1064 | \s+(?Ppermit|deny) 1065 | \s+(?: 1066 | (?:object-group\s+(?P\S+)) 1067 | |(?P{0}) 1068 | ) 1069 | \s+(?: # 10.0.0.0 255.255.255.0 1070 | (?Pany|any4|any6) 1071 | |(?:object-group\s+(?P\S+)) 1072 | |(?:object\s+(?P\S+)) 1073 | |(?:host\s+(?P\S+)) 1074 | |(?:(?P\S+)\s+0\.0\.0\.0) 1075 | |(?:(?P\S+)\s+(?P\d+\.\d+\.\d+\.\d+)) 1076 | ) 1077 | \s+(?: # 10.0.0.0 255.255.255.0 1078 | (?Pany|any4|any6) 1079 | |(?:object-group\s+(?P\S+)) 1080 | |(?:object\s+(?P\S+)) 1081 | |(?:host\s+(?P\S+)) 1082 | |(?:(?P\S+)\s+0\.0\.0\.0) 1083 | |(?:(?P\S+)\s+(?P\d+\.\d+\.\d+\.\d+)) 1084 | ) 1085 | (?:\s+ 1086 | (?Plog) 1087 | (?:\s+(?P{1}))? 1088 | (?:\s+interval\s+(?P\d+))? 1089 | )? 1090 | (?:\s+(?Pdisable))? 1091 | (?: 1092 | (?:\s+(?Pinactive)) 1093 | |(?:\s+time-range\s+(?P\S+)) 1094 | )? 1095 | \s*$) # END access-list 1 parse 1096 | ) 1097 | """.format(_ACL_PROTOCOLS, _ACL_LOGLEVELS, _ACL_ICMP_PROTOCOLS) 1098 | _RE_IOS_ACL = re.compile(_RE_IOS_ACL_STR, re.VERBOSE) 1099 | 1100 | class IOSAclLine(models_cisco.BaseCfgLine): 1101 | def __init__(self, *args, **kwargs): 1102 | """Provide attributes on Cisco IOS Access-Lists""" 1103 | super(IOSAclLine, self).__init__(*args, **kwargs) 1104 | mm = _RE_IOS_ACL.search(self.text) 1105 | if not (mm is None): 1106 | self._mm_results = mm.groupdict() # All regex match results 1107 | else: 1108 | raise ValueError("[FATAL] models_cisco cannot parse '{0}'".format(self.text)) 1109 | 1110 | def __repr__(self): 1111 | return "<%s # %s '%s'>" % (self.classname, self.linenum, self.name) 1112 | 1113 | @classmethod 1114 | def is_object_for(cls, line="", re=re): 1115 | if 'access-list ' in line[0:13].lower(): 1116 | return True 1117 | return False 1118 | 1119 | @property 1120 | def name(self): 1121 | mm_r = self._mm_results 1122 | return mm_r['acl_num0'] or mm_r['acl_num1'] 1123 | 1124 | @property 1125 | def action(self): 1126 | mm_r = self._mm_results 1127 | return mm_r['action0'] or mm_r['action1'] 1128 | 1129 | @property 1130 | def type(self): 1131 | mm_r = self._mm_results 1132 | if mm_r['action0']: 1133 | return 'standard' 1134 | elif mm_r['action1']: 1135 | return 'extended' 1136 | 1137 | @property 1138 | def proto(self): 1139 | mm_r = self._mm_results 1140 | return mm_r['service_object1'] or mm_r['protocol1'] 1141 | 1142 | @property 1143 | def proto_method(self): 1144 | mm_r = self._mm_results 1145 | if mm_r['service_object1']: 1146 | return 'object-group' 1147 | elif mm_r['protocol1']: 1148 | return 'proto' 1149 | 1150 | @property 1151 | def src_addr(self): 1152 | mm_r = self._mm_results 1153 | return mm_r['src_any1'] or mm_r['src_objectgroup1'] \ 1154 | or mm_r['src_object1'] or mm_r['src_host1a'] \ 1155 | or mm_r['src_host1b'] \ 1156 | or mm_r['src_network1'] 1157 | 1158 | @property 1159 | def src_hostmask(self): 1160 | mm_r = self._mm_results 1161 | method = self.src_addr_method 1162 | if method == 'any': 1163 | return '255.255.255.255' 1164 | elif method == 'host': 1165 | return '0.0.0.0' 1166 | elif method == 'network': 1167 | return mm_r['src_hostmask1'] 1168 | elif method == 'object-group' or method == 'object': 1169 | return None 1170 | else: 1171 | return None 1172 | #raise ValueError("Cannot parse ACL source hostmask for '{0}'".format(self.text)) 1173 | 1174 | @property 1175 | def src_addr_method(self): 1176 | mm_r = self._mm_results 1177 | if mm_r['src_any1']: 1178 | return 'any' 1179 | elif mm_r['src_objectgroup1']: 1180 | return 'object-group' 1181 | elif mm_r['src_object1']: 1182 | return 'object' 1183 | elif mm_r['src_host1a'] or mm_r['src_host1b']: 1184 | return 'host' 1185 | elif (mm_r['src_network1'] or mm_r['src_hostmask1']): 1186 | return 'network' 1187 | else: 1188 | return None 1189 | #raise ValueError("Cannot parse ACL source address method for '{0}'".format(self.text)) 1190 | 1191 | @property 1192 | def dst_addr(self): 1193 | mm_r = self._mm_results 1194 | return mm_r['dst_any0'] or mm_r['dst_objectgroup0'] \ 1195 | or mm_r['dst_object0'] or mm_r['dst_host0a'] \ 1196 | or mm_r['dst_host0b'] \ 1197 | or mm_r['dst_network0'] \ 1198 | \ 1199 | or mm_r['dst_any1'] or mm_r['dst_objectgroup1'] \ 1200 | or mm_r['dst_object1'] or mm_r['dst_host1a'] \ 1201 | or mm_r['dst_host1b'] \ 1202 | or mm_r['dst_network1'] 1203 | 1204 | @property 1205 | def dst_hostmask(self): 1206 | mm_r = self._mm_results 1207 | method = self.dst_addr_method 1208 | if method == 'any': 1209 | return '255.255.255.255' 1210 | elif method == 'host': 1211 | return '0.0.0.0' 1212 | elif method == 'network': 1213 | return mm_r['dst_hostmask0'] or mm_r['dst_hostmask1'] 1214 | elif method == 'object-group' or method == 'object': 1215 | return None 1216 | else: 1217 | return None 1218 | 1219 | @property 1220 | def dst_addr_method(self): 1221 | mm_r = self._mm_results 1222 | if mm_r['dst_any0'] or mm_r['dst_any1']: 1223 | return 'any' 1224 | elif mm_r['dst_objectgroup0'] or mm_r['dst_objectgroup1']: 1225 | return 'object-group' 1226 | elif mm_r['dst_object0'] or mm_r['dst_object1']: 1227 | return 'object' 1228 | elif mm_r['dst_host0a'] or mm_r['dst_host0b']\ 1229 | or mm_r['dst_host1a'] or mm_r['dst_host1b']: 1230 | return 'host' 1231 | elif (mm_r['dst_network0'] and mm_r['dst_hostmask0'])\ 1232 | or (mm_r['dst_network1'] and mm_r['dst_hostmask1']): 1233 | return 'network' 1234 | else: 1235 | return None 1236 | 1237 | @property 1238 | def log(self): 1239 | mm_r = self._mm_results 1240 | return mm_r['log0'] or mm_r['log1'] 1241 | 1242 | @property 1243 | def log_level(self): 1244 | mm_r = self._mm_results 1245 | return mm_r['log_level0'] or mm_r['log_level1'] 1246 | 1247 | @property 1248 | def log_interval(self): 1249 | mm_r = self._mm_results 1250 | return mm_r['log_interval0'] or mm_r['log_interval1'] 1251 | 1252 | @property 1253 | def disable(self): 1254 | mm_r = self._mm_results 1255 | return mm_r['disable0'] or mm_r['disable1'] 1256 | 1257 | @property 1258 | def inactive(self): 1259 | mm_r = self._mm_results 1260 | return mm_r['inactive0'] or mm_r['inactive1'] 1261 | 1262 | @property 1263 | def time_range(self): 1264 | mm_r = self._mm_results 1265 | return mm_r['time_range0'] or mm_r['time_range1'] 1266 | 1267 | @property 1268 | def result_dict(self): 1269 | mm_r = self._mm_results 1270 | retval = dict() 1271 | 1272 | proto_dict = self.acl_protocol_dict 1273 | retval['ip_protocol'] = proto_dict['protocol'] 1274 | retval['ip_protocol_object'] = proto_dict['protocol_object'] 1275 | retval['acl_name'] = mm_r['acl_name0'] or mm_r['acl_name1'] \ 1276 | or mm_r['acl_name2'] or mm_r['acl_name3'] or mm_r['acl_name4'] 1277 | retval['action'] = mm_r['action0'] or mm_r['action1'] \ 1278 | or mm_r['action2'] or mm_r['action3'] or mm_r['action4'] 1279 | retval['remark'] = mm_r['remark'] 1280 | retval['src_addr_method'] = self.src_addr_method 1281 | retval['dst_addr_method'] = self.dst_addr_method 1282 | retval['disable'] = bool(mm_r['disable1'] or mm_r['disable2'] or mm_r['disable4']) 1283 | retval['time_range'] = mm_r['time_range1'] or mm_r['time_range2'] or mm_r['time_range4'] 1284 | retval['log'] = bool(mm_r['log1'] or mm_r['log2'] or mm_r['log4']) 1285 | if not retval['log']: 1286 | retval['log_interval'] = -1 1287 | retval['log_level'] = '' 1288 | else: 1289 | retval['log_level'] = mm_r['log_level1'] or mm_r['log_level2'] or mm_r['log_level4'] or 'informational' 1290 | retval['log_interval'] = int(mm_r['log_interval1'] \ 1291 | or mm_r['log_interval2'] or mm_r['log_interval4'] or 300) 1292 | 1293 | return retval 1294 | 1295 | _RE_IOS_IPACL_STR = r"""(?: # Non-capturing parenthesis 1296 | (^ip\s+access-list\s+(?Pstandard|extended)\s+(?P\S+)$) 1297 | ) # Close non-capture parens 1298 | """ 1299 | _RE_IOS_IPACL = re.compile(_RE_IOS_IPACL_STR, re.VERBOSE) 1300 | 1301 | ## 1302 | ## ------------- IOS "ip access-list" objects 1303 | ## 1304 | class IOSIPAclLine(models_cisco.BaseCfgLine): 1305 | def __init__(self, *args, **kwargs): 1306 | """ 1307 | """ 1308 | """Provide attributes on Cisco IOS Access-Lists""" 1309 | super(IOSIPAclLine, self).__init__(*args, **kwargs) 1310 | mm = _RE_IOS_IPACL.search(self.text) 1311 | if not (mm is None): 1312 | self._mm_results = mm.groupdict() # All regex match results 1313 | else: 1314 | raise ValueError("[FATAL] models_cisco cannot parse '{0}'".format(self.text)) 1315 | 1316 | def __repr__(self): 1317 | return "<%s # %s '%s'>" % (self.classname, self.linenum, self.name) 1318 | 1319 | @classmethod 1320 | def is_object_for(cls, line="", re=re): 1321 | if 'ip access-list ' in line[0:16].lower(): 1322 | return True 1323 | return False 1324 | 1325 | @property 1326 | def name(self): 1327 | mm_r = self._mm_results 1328 | return mm_r['name'] 1329 | 1330 | @property 1331 | def type(self): 1332 | mm_r = self._mm_results 1333 | return mm_r['type'] 1334 | 1335 | ## 1336 | ## ------------- IOS child of "ip access-list" objects 1337 | ## 1338 | _RE_IOS_IPACL_CHILD_STR = r"""(?: # Non-capturing parenthesis 1339 | # remark 1340 | (^\s+(?Premark)\s+(?P\S.+?)$) 1341 | 1342 | # extended service object with protocol, source network object, 1343 | # destination network object 1344 | # permit ip host 10.112.143.212 any 1345 | # permit ip host 10.111.143.201 host 10.112.191.101 log 1346 | # permit udp 172.18.0.0 0.0.255.255 host 10.112.191.251 eq domain ntp 389 1347 | # permit tcp 192.168.1.240 0.0.0.15 host 172.19.33.11 range 20000 20010 1348 | |(^\s+(?Ppermit|deny) 1349 | \s+(?: 1350 | (?:object-group\s+(?P\S+)) 1351 | |(?P{0}) 1352 | ) 1353 | \s+(?: # source addr 1354 | (?Pany|any4|any6) 1355 | |(?:object-group\s+(?P\S+)) 1356 | |(?:object\s+(?P\S+)) 1357 | |(?:host\s+(?P\S+)) 1358 | |(?:(?P\S+)\s+0\.0\.0\.0) 1359 | |(?:(?P\S+)\s+(?P\d+\.\d+\.\d+\.\d+)) 1360 | ) 1361 | (?:\s+ 1362 | (?: # source port 1363 | (?: 1364 | (?Peq|neq|lt|gt) 1365 | \s(?P(?:(?:{3})\s?)+) 1366 | ) 1367 | |(?:range\s+(?P\S+)\s+(?P\S+)) 1368 | |(?:object-group\s+(?P\S+)) 1369 | ) 1370 | )? 1371 | \s+(?: # destination addr 1372 | (?Pany|any4|any6) 1373 | |(?:object-group\s+(?P\S+)) 1374 | |(?:object\s+(?P\S+)) 1375 | |(?:host\s+(?P\S+)) 1376 | |(?:(?P\S+)\s+0\.0\.0\.0) 1377 | |(?:(?P\S+)\s+(?P\d+\.\d+\.\d+\.\d+)) 1378 | ) 1379 | (?:\s+ 1380 | (?: # destination port 1381 | (?: 1382 | (?Peq|neq|lt|gt) 1383 | \s(?P(?:(?:{3})\s?)+) 1384 | ) 1385 | |(?:range\s+(?P\S+)\s+(?P\S+)) 1386 | |(?:object-group\s+(?P\S+)) 1387 | ) 1388 | )? 1389 | (?:\s+ 1390 | (?Plog) 1391 | (?:\s+(?P{1}))? 1392 | (?:\s+interval\s+(?P\d+))? 1393 | )? 1394 | (?:\s+(?Pdisable))? 1395 | (?: 1396 | (?:\s+(?Pinactive)) 1397 | |(?:\s+time-range\s+(?P\S+)) 1398 | )? 1399 | (?:\s+(?Pestablished))? # established = temporary hack. 1400 | \s*$) # END access-list 1 parse 1401 | 1402 | # ICMP 1403 | # permit icmp any4 0.0.0.0 0.0.0.0 unreachable log interval 1 1404 | # permit icmp object-group ISO_NET host 172.19.33.11 1405 | |(^\s+(?Ppermit|deny) 1406 | \s+(?Picmp) 1407 | (?:\s+ # source addr 1408 | (?: 1409 | (?Pany|any4|any6) 1410 | |(?:object-group\s+(?P\S+)) 1411 | |(?:object\s+(?P\S+)) 1412 | |(?:host\s+(?P\S+)) 1413 | |(?:(?P\S+)\s+0\.0\.0\.0) 1414 | |(?:(?P\S+)\s+(?P\d+\.\d+\.\d+\.\d+)) 1415 | ) 1416 | ) 1417 | (?:\s+ # destination addr 1418 | (?: 1419 | (?Pany|any4|any6) 1420 | |(?:object-group\s+(?P\S+)) 1421 | |(?:object\s+(?P\S+)) 1422 | |(?:host\s+(?P\S+)) 1423 | |(?:(?P\S+)\s+0\.0\.0\.0) 1424 | |(?:(?P\S+)\s+(?P\d+\.\d+\.\d+\.\d+)) 1425 | ) 1426 | ) 1427 | (?:\s+(?P{2}|\d+))? 1428 | (?:\s+ 1429 | (?Plog) 1430 | (?:\s+(?P{1}))? 1431 | (?:\s+interval\s+(?P\d+))? 1432 | )? 1433 | (?:\s+(?Pdisable))? 1434 | (?: 1435 | (?:\s+(?Pinactive)) 1436 | |(?:\s+time-range\s+(?P\S+)) 1437 | )? 1438 | \s*$) 1439 | 1440 | # For standard ACLs 1441 | #ip access-list standard ALLOW_MOD_OSPF_AD 1442 | # permit 10.0.0.0 0.255.255.255 1443 | |(^\s+(?Ppermit|deny) 1444 | (?:\s+ # destination addr 1445 | (?: 1446 | (?Pany|any4|any6|0\.0\.0\.0) 1447 | |(?:object-group\s+(?P\S+)) 1448 | |(?:object\s+(?P\S+)) 1449 | |(?:host\s+(?P\S+)) 1450 | |(?:(?P\S+)\s+0\.0\.0\.0) 1451 | |(?:(?P\S+)) 1452 | |(?:(?P\S+)\s+(?P\d+\.\d+\.\d+\.\d+)) 1453 | ) 1454 | ) 1455 | \s*$) 1456 | ) # Close non-capture parens 1457 | """.format(_ACL_PROTOCOLS, _ACL_LOGLEVELS, _ACL_ICMP_PROTOCOLS, _PORT_NAMES) 1458 | _RE_IOS_IPACL_CHILD = re.compile(_RE_IOS_IPACL_CHILD_STR, re.VERBOSE) 1459 | 1460 | class IOSIPAclChildLine(models_cisco.BaseCfgLine): 1461 | def __init__(self, *args, **kwargs): 1462 | """Provide attributes on Cisco IOS Access-Lists""" 1463 | super(IOSIPAclChildLine, self).__init__(*args, **kwargs) 1464 | mm = _RE_IOS_IPACL_CHILD.search(self.text) 1465 | if not (mm is None): 1466 | self._mm_results = mm.groupdict() # All regex match results 1467 | else: 1468 | raise ValueError("[FATAL] models_cisco cannot parse '{0}'".format(self.text)) 1469 | 1470 | def __repr__(self): 1471 | return "<%s # %s '%s'>" % (self.classname, self.linenum, self.text) 1472 | 1473 | @classmethod 1474 | def is_object_for(cls, line="", re=re): 1475 | aclChild_regex = r'^\s+remark|permit|deny\s+(\S+.+)$' 1476 | if re.search(aclChild_regex, line): 1477 | return True 1478 | return False 1479 | 1480 | @property 1481 | def name(self): 1482 | return self.parent.name 1483 | 1484 | @property 1485 | def action(self): 1486 | mm_r = self._mm_results 1487 | return mm_r['action0'] or mm_r['action1'] or mm_r['action2'] \ 1488 | or mm_r['action3'] 1489 | 1490 | @property 1491 | def remark(self): 1492 | mm_r = self._mm_results 1493 | return mm_r['remark'] 1494 | 1495 | @property 1496 | def proto(self): 1497 | mm_r = self._mm_results 1498 | return mm_r['service_object1'] \ 1499 | or mm_r['protocol1'] or mm_r['protocol2'] 1500 | 1501 | @property 1502 | def proto_method(self): 1503 | mm_r = self._mm_results 1504 | if mm_r['protocol1'] or mm_r['protocol2']: 1505 | return 'proto' 1506 | elif mm_r['service_object1']: 1507 | return 'object-group' 1508 | elif self.action == 'remark': 1509 | return 'remark' 1510 | 1511 | @property 1512 | def src_addr(self): 1513 | mm_r = self._mm_results 1514 | return mm_r['src_any1'] or mm_r['src_objectgroup1'] \ 1515 | or mm_r['src_object1'] or mm_r['src_host1a'] \ 1516 | or mm_r['src_host1b'] \ 1517 | or mm_r['src_network1'] \ 1518 | \ 1519 | or mm_r['src_any2'] or mm_r['src_objectgroup2'] \ 1520 | or mm_r['src_object2'] or mm_r['src_host2a'] \ 1521 | or mm_r['src_host2b'] \ 1522 | or mm_r['src_network2'] 1523 | 1524 | @property 1525 | def src_hostmask(self): 1526 | mm_r = self._mm_results 1527 | method = self.src_addr_method 1528 | if method == 'any': 1529 | return '255.255.255.255' 1530 | elif method == 'host': 1531 | return '0.0.0.0' 1532 | elif method == 'network': 1533 | return mm_r['src_hostmask1'] or mm_r['src_hostmask2'] 1534 | elif method == 'object-group' or method == 'object' \ 1535 | or method == 'remark' \ 1536 | or self.parent.type == 'standard': # standard acl = no src ip 1537 | return None 1538 | 1539 | @property 1540 | def src_addr_method(self): 1541 | mm_r = self._mm_results 1542 | if mm_r['src_any1'] or mm_r['src_any2']: 1543 | return 'any' 1544 | elif mm_r['src_objectgroup1'] or mm_r['src_objectgroup2']: 1545 | return 'object-group' 1546 | elif mm_r['src_object1'] or mm_r['src_object2']: 1547 | return 'object' 1548 | elif mm_r['src_host1a'] or mm_r['src_host1b'] \ 1549 | or mm_r['src_host2a'] or mm_r['src_host2b']: 1550 | return 'host' 1551 | elif (mm_r['src_network1'] or mm_r['src_hostmask1']) \ 1552 | or (mm_r['src_network2'] or mm_r['src_hostmask2']): 1553 | return 'network' 1554 | elif self.action == 'remark': 1555 | return 'remark' 1556 | elif self.parent.type == 'standard': # standard acl = no src ip 1557 | return None 1558 | 1559 | @property 1560 | def src_port(self): 1561 | mm_r = self._mm_results 1562 | if self.src_port_method == 'range': 1563 | return mm_r['src_port_low1'] + ' ' + mm_r['src_port_high1'] 1564 | return mm_r['src_port1'] or mm_r['src_service_object1'] 1565 | 1566 | @property 1567 | def src_port_method(self): 1568 | mm_r = self._mm_results 1569 | if mm_r['src_port_op1']: 1570 | return mm_r['src_port_op1'] 1571 | elif mm_r['src_port_low1'] and mm_r['src_port_high1']: 1572 | return 'range' 1573 | elif mm_r['src_service_object1']: 1574 | return 'object-group' 1575 | 1576 | @property 1577 | def dst_addr(self): 1578 | mm_r = self._mm_results 1579 | return mm_r['dst_any1'] or mm_r['dst_objectgroup1'] \ 1580 | or mm_r['dst_object1'] or mm_r['dst_host1a'] \ 1581 | or mm_r['dst_host1b'] \ 1582 | or mm_r['dst_network1'] \ 1583 | \ 1584 | or mm_r['dst_any2'] or mm_r['dst_objectgroup2'] \ 1585 | or mm_r['dst_object2'] or mm_r['dst_host2a'] \ 1586 | or mm_r['dst_host2b'] \ 1587 | or mm_r['dst_network2'] \ 1588 | \ 1589 | or mm_r['dst_any3'] or mm_r['dst_objectgroup3'] \ 1590 | or mm_r['dst_object3'] or mm_r['dst_host3a'] \ 1591 | or mm_r['dst_host3b'] or mm_r['dst_host3c']\ 1592 | or mm_r['dst_network3'] 1593 | 1594 | @property 1595 | def dst_hostmask(self): 1596 | mm_r = self._mm_results 1597 | method = self.dst_addr_method 1598 | if method == 'any': 1599 | return '255.255.255.255' 1600 | elif method == 'host': 1601 | return '0.0.0.0' 1602 | elif method == 'network': 1603 | return mm_r['dst_hostmask1'] or mm_r['dst_hostmask2'] \ 1604 | or mm_r['dst_hostmask3'] 1605 | elif method == 'object-group' or method == 'object' \ 1606 | or method == 'remark': 1607 | return None 1608 | else: 1609 | return None 1610 | 1611 | @property 1612 | def dst_addr_method(self): 1613 | mm_r = self._mm_results 1614 | if mm_r['dst_any1'] or mm_r['dst_any2'] or mm_r['dst_any3']: 1615 | return 'any' 1616 | elif mm_r['dst_objectgroup1'] or mm_r['dst_objectgroup2'] \ 1617 | or mm_r['dst_objectgroup3']: 1618 | return 'object-group' 1619 | elif mm_r['dst_object1'] or mm_r['dst_object2'] or mm_r['dst_object3']: 1620 | return 'object' 1621 | elif mm_r['dst_host1a'] or mm_r['dst_host1b'] \ 1622 | or mm_r['dst_host2a'] or mm_r['dst_host2b'] \ 1623 | or mm_r['dst_host3a'] or mm_r['dst_host3b'] \ 1624 | or mm_r['dst_host3c']: 1625 | return 'host' 1626 | elif (mm_r['dst_network1'] and mm_r['dst_hostmask1']) \ 1627 | or (mm_r['dst_network2'] and mm_r['dst_hostmask2']) \ 1628 | or (mm_r['dst_network3'] and mm_r['dst_hostmask3']): 1629 | return 'network' 1630 | elif self.action == 'remark': 1631 | return 'remark' 1632 | else: 1633 | return None 1634 | 1635 | @property 1636 | def dst_port(self): 1637 | mm_r = self._mm_results 1638 | if self.dst_port_method == 'range': 1639 | return mm_r['dst_port_low1'] + ' ' + mm_r['dst_port_high1'] 1640 | return mm_r['dst_port1'] or mm_r['dst_service_object1'] 1641 | 1642 | @property 1643 | def dst_port_method(self): 1644 | mm_r = self._mm_results 1645 | if mm_r['dst_port_op1']: 1646 | return mm_r['dst_port_op1'] 1647 | elif mm_r['dst_port_low1'] and mm_r['dst_port_high1']: 1648 | return 'range' 1649 | elif mm_r['dst_service_object1']: 1650 | return 'object-group' 1651 | 1652 | @property 1653 | def log(self): 1654 | mm_r = self._mm_results 1655 | return mm_r['log1'] or mm_r['log2'] 1656 | 1657 | @property 1658 | def log_level(self): 1659 | mm_r = self._mm_results 1660 | return mm_r['log_level1'] or mm_r['log_level2'] 1661 | 1662 | @property 1663 | def log_interval(self): 1664 | mm_r = self._mm_results 1665 | return mm_r['log_interval1'] or mm_r['log_interval2'] 1666 | 1667 | @property 1668 | def disable(self): 1669 | mm_r = self._mm_results 1670 | return mm_r['disable1'] or mm_r['disable2'] 1671 | 1672 | @property 1673 | def inactive(self): 1674 | mm_r = self._mm_results 1675 | return mm_r['inactive1'] or mm_r['inactive2'] 1676 | 1677 | @property 1678 | def time_range(self): 1679 | mm_r = self._mm_results 1680 | return mm_r['time_range1'] or mm_r['time_range2'] 1681 | 1682 | # TODO: This should not be needed 1683 | # Otherwise: fix code to support this attribute. 1684 | @property 1685 | def established(self): 1686 | mm_r = self._mm_results 1687 | return mm_r['established'] 1688 | 1689 | ## 1690 | ## ----------------- New L4Object. 1691 | ## Features: New attributes: operator, port_spec, src_port_list 1692 | ## 1693 | class L4Object(object): 1694 | """Object for Transport-layer protocols; the object ensures that logical operators (such as le, gt, eq, and ne) are parsed correctly, as well as mapping service names to port numbers""" 1695 | def __init__(self, protocol='', port_spec='', syntax=''): 1696 | self.protocol = protocol 1697 | self.operator = '' 1698 | self.port_spec = port_spec 1699 | self.port_list = list() 1700 | self.src_port_list = list() 1701 | self.syntax = syntax 1702 | 1703 | try: 1704 | port_spec = port_spec.strip() 1705 | except: 1706 | port_spec = port_spec 1707 | 1708 | if syntax=='asa': 1709 | if protocol=='tcp': 1710 | ports = ASA_TCP_PORTS 1711 | elif protocol=='udp': 1712 | ports = ASA_UDP_PORTS 1713 | else: 1714 | raise NotImplementedError("'{0}' is not supported: '{0}'".format(protocol)) 1715 | else: 1716 | raise NotImplementedError("This syntax is unknown: '{0}'".format(syntax)) 1717 | 1718 | if 'eq ' in port_spec: 1719 | port_str = re.split('\s+', port_spec)[-1] 1720 | self.operator = 'eq' 1721 | self.port_list = [int(ports.get(port_str, port_str))] 1722 | elif re.search(r'^\S+$', port_spec): 1723 | # Technically, 'eq ' is optional... 1724 | self.operator = 'eq' 1725 | self.port_list = [int(ports.get(port_spec, port_spec))] 1726 | elif 'range ' in port_spec: 1727 | port_tmp = re.split('\s+', port_spec)[1:] 1728 | self.operator = 'range' 1729 | self.port_list = range(int(ports.get(port_tmp[0], port_tmp[0])), 1730 | int(ports.get(port_tmp[1], port_tmp[1])) + 1) 1731 | elif 'lt ' in port_spec: 1732 | port_str = re.split('\s+', port_spec)[-1] 1733 | self.operator = 'lt' 1734 | self.port_list = range(1, int(ports.get(port_str, port_str))) 1735 | elif 'gt ' in port_spec: 1736 | port_str = re.split('\s+', port_spec)[-1] 1737 | self.operator = 'gt' 1738 | self.port_list = range(int(ports.get(port_str, port_str)) + 1, 65535) 1739 | elif 'neq ' in port_spec: 1740 | port_str = re.split('\s+', port_spec)[-1] 1741 | tmp = set(range(1, 65535)) 1742 | tmp.remove(int(port_str)) 1743 | self.operator = 'neq' 1744 | self.port_list = sorted(tmp) 1745 | 1746 | def __eq__(self, val): 1747 | if (self.protocol==val.protocol) and (self.port_list==val.port_list): 1748 | return True 1749 | return False 1750 | 1751 | def __repr__(self): 1752 | return "".format(self.protocol, self.port_list) 1753 | 1754 | ## 1755 | ##------------- New ConfigLineFactory 1756 | ## 1757 | def ConfigLineFactory(text="", comment_delimiter="!", syntax='ios'): 1758 | if syntax=='ios': 1759 | classes = [models_cisco.IOSIntfLine, \ 1760 | models_cisco.IOSRouteLine, \ 1761 | models_cisco.IOSAccessLine, \ 1762 | models_cisco.IOSAaaLoginAuthenticationLine, \ 1763 | models_cisco.IOSAaaEnableAuthenticationLine, \ 1764 | models_cisco.IOSAaaCommandsAuthorizationLine, \ 1765 | models_cisco.IOSAaaCommandsAccountingLine, \ 1766 | models_cisco.IOSAaaExecAccountingLine, \ 1767 | models_cisco.IOSAaaGroupServerLine, \ 1768 | models_cisco.IOSHostnameLine, \ 1769 | models_cisco.IOSIntfGlobal, \ 1770 | IOSAclLine, \ 1771 | IOSIPAclLine, \ 1772 | IOSIPAclChildLine, \ 1773 | models_cisco.IOSCfgLine] 1774 | elif syntax=='asa': 1775 | classes = [ASAName, \ 1776 | ASAObjNetwork, \ 1777 | ASAObjService, \ 1778 | ASAObjGroupNetwork, \ 1779 | ASAObjGroupService, \ 1780 | ASAObjGroupProtocol, \ 1781 | models_asa.ASAIntfLine, \ 1782 | models_asa.ASAIntfGlobal, \ 1783 | models_asa.ASAHostnameLine, \ 1784 | ASAAclLine, \ 1785 | models_asa.ASACfgLine] 1786 | for cls in classes: 1787 | if cls.is_object_for(text): 1788 | inst = cls(text=text, 1789 | comment_delimiter=comment_delimiter) # instance of the proper subclass 1790 | return inst 1791 | raise ValueError("Could not find an object for '%s'" % line) 1792 | 1793 | ## 1794 | ##------------- Monkey Patching 1795 | ## Temporary patch. Goal is to send a pull request to the project. 1796 | ## 1797 | ccp.ConfigLineFactory = ConfigLineFactory 1798 | models_asa.ASAConfigList = ASAConfigList 1799 | 1800 | ## 1801 | ##------------- New CiscoConfParse definition 1802 | ## Reason: Have a good reference to ASAConfigList 1803 | ## 1804 | class CiscoConfParse(ccp.CiscoConfParse): 1805 | """Parses Cisco IOS configurations and answers queries about the configs""" 1806 | 1807 | def __init__(self, config="", comment="!", debug=False, factory=False, 1808 | linesplit_rgx=r"\r*\n+", ignore_blank_lines=True, syntax='ios'): 1809 | """ 1810 | You will find a great class description in ccp.CiscoConfParse 1811 | """ 1812 | 1813 | # all IOSCfgLine object instances... 1814 | self.comment_delimiter = comment 1815 | self.factory = factory 1816 | self.ConfigObjs = None 1817 | self.syntax = syntax 1818 | self.debug = debug 1819 | 1820 | if isinstance(config, list) or isinstance(config, Iterator): 1821 | if syntax=='ios': 1822 | # we already have a list object, simply call the parser 1823 | if self.debug: 1824 | _log.debug("parsing from a python list with ios syntax") 1825 | self.ConfigObjs = ccp.IOSConfigList(data=config, 1826 | comment_delimiter=comment, 1827 | debug=debug, 1828 | factory=factory, 1829 | ignore_blank_lines=ignore_blank_lines, 1830 | syntax='ios', 1831 | CiscoConfParse=self) 1832 | elif syntax=='asa': 1833 | # we already have a list object, simply call the parser 1834 | if self.debug: 1835 | _log.debug("parsing from a python list with asa syntax") 1836 | self.ConfigObjs = ASAConfigList(data=config, 1837 | comment_delimiter=comment, 1838 | debug=debug, 1839 | factory=factory, 1840 | ignore_blank_lines=ignore_blank_lines, 1841 | syntax='asa', 1842 | CiscoConfParse=self) 1843 | elif syntax=='junos': 1844 | ## FIXME I am shamelessly abusing the IOSConfigList for now... 1845 | # we already have a list object, simply call the parser 1846 | config = self.convert_braces_to_ios(config) 1847 | if self.debug: 1848 | _log.debug("parsing from a python list with junos syntax") 1849 | self.ConfigObjs = ccp.IOSConfigList(data=config, 1850 | comment_delimiter=comment, 1851 | debug=debug, 1852 | factory=factory, 1853 | ignore_blank_lines=ignore_blank_lines, 1854 | syntax='junos', 1855 | CiscoConfParse=self) 1856 | else: 1857 | raise ValueError("FATAL: '{}' is an unknown syntax".format(syntax)) 1858 | 1859 | ## Accept either a string or unicode... 1860 | elif getattr(config, 'encode', False): 1861 | # Try opening as a file 1862 | try: 1863 | if syntax=='ios': 1864 | # string - assume a filename... open file, split and parse 1865 | if self.debug: 1866 | _log.debug("parsing from '{0}' with ios syntax".format(config)) 1867 | f = open(config, mode="rU") 1868 | text = f.read() 1869 | rgx = re.compile(linesplit_rgx) 1870 | self.ConfigObjs = ccp.IOSConfigList(rgx.split(text), 1871 | comment_delimiter=comment, 1872 | debug=debug, 1873 | factory=factory, 1874 | ignore_blank_lines=ignore_blank_lines, 1875 | syntax='ios', 1876 | CiscoConfParse=self) 1877 | elif syntax=='asa': 1878 | # string - assume a filename... open file, split and parse 1879 | if self.debug: 1880 | _log.debug("parsing from '{0}' with asa syntax".format(config)) 1881 | f = open(config, mode="rU") 1882 | text = f.read() 1883 | rgx = re.compile(linesplit_rgx) 1884 | self.ConfigObjs = ASAConfigList(rgx.split(text), 1885 | comment_delimiter=comment, 1886 | debug=debug, 1887 | factory=factory, 1888 | ignore_blank_lines=ignore_blank_lines, 1889 | syntax='asa', 1890 | CiscoConfParse=self) 1891 | 1892 | elif syntax=='junos': 1893 | # string - assume a filename... open file, split and parse 1894 | if self.debug: 1895 | _log.debug("parsing from '{0}' with junos syntax".format(config)) 1896 | f = open(config, mode="rU") 1897 | text = f.read() 1898 | rgx = re.compile(linesplit_rgx) 1899 | 1900 | config = self.convert_braces_to_ios(rgx.split(text)) 1901 | ## FIXME I am shamelessly abusing the IOSConfigList for now... 1902 | self.ConfigObjs = ccp.IOSConfigList(config, 1903 | comment_delimiter=comment, 1904 | debug=debug, 1905 | factory=factory, 1906 | ignore_blank_lines=ignore_blank_lines, 1907 | syntax='junos', 1908 | CiscoConfParse=self) 1909 | else: 1910 | raise ValueError("FATAL: '{}' is an unknown syntax".format(syntax)) 1911 | 1912 | except IOError: 1913 | print("[FATAL] CiscoConfParse could not open '%s'" % config) 1914 | raise RuntimeError 1915 | else: 1916 | raise RuntimeError("[FATAL] CiscoConfParse() received" + 1917 | " an invalid argument\n") 1918 | self.ConfigObjs.CiscoConfParse = self 1919 | -------------------------------------------------------------------------------- /releases.txt: -------------------------------------------------------------------------------- 1 | TODO 2 | - Add a "--no-any-any" feature to avoid import of any/any rules 3 | - Look for examples with client DATA 4 | - add counters to c2c.addObj() to automatically increase counters 5 | - check group merge with -01 6 | - run pep8 7 | - run pylint 8 | - run sphinx 9 | 10 | v1.1 - 2016-09-07 11 | Features: 12 | - Clean the code for publishing 13 | - Extracted changes made in ciscoconfparse to fit in a single file. 14 | - ciscoconfparse is not a submodule to https://github.com/gosecure/ciscoconfparse 15 | - License is now GPLv3 to match ciscoconfparse project. 16 | 17 | v1.0 - 2016-02-21 18 | Features: 19 | - Major refactoring of the parsing to reduce "hacks" and ugly codes 20 | - A distinction is made between ASA and IOS. The argument --syntax was added. 21 | - Unfortunatly, ciscoconfparse was forked but a pull request to the Project 22 | should be made in a near future. 23 | - Added support for source ports 24 | - Deleted an important number of line of codes 25 | 26 | v0.18 - 2016-01-13 27 | Features: 28 | - Added support to protocols: ospf,esp,ah,ahp,vrrp,skip,gre 29 | - Added support to "ip access-list" 30 | - Reduced ACL parsing code from cisco2checkpoint.py 31 | - Optimized parsing by updating ciscoconfparse library 32 | - Now using ciscoconfparse with factory=True 33 | 34 | v0.17 - 2015-10-13 35 | Features: 36 | - Added support to import only new objects or flag differences. 37 | - New parameter: --new-only 38 | - New parameter: --show-diff 39 | - Updated network_objects.xml and services_objects.xml using "printxml services" and "printxml network_objects" in dbedit. 40 | 41 | v0.16 - 2015-06-22 42 | Features: 43 | - Developped a feature to "flatten" "DM_INLINE" groups in a firewall rule. When enabled, all these groups are removed and only the member is added to a firewall rule attribute (either src, dst or port). 44 | 45 | v0.15 - 2015-06-16 46 | Features: 47 | - Several adjustement for another customer. 48 | - Uncommented "names" 49 | - Added rtsp port (554) 50 | - Added some ICMP messages 51 | - Added tftp and other cisco protocols 52 | - Added the port object (can parse SinglePort and PortRange) from cisco config 53 | - Added prefix to CiscoRange when created by script 54 | - Fixed NAT issues when importing hide nat rules 55 | 56 | v0.14 - 2015-05-08 57 | Features: 58 | - Made several tests 59 | - Fixed a bug where NAT rules were not imported properly in "directory mode" (--configDir) 60 | - Fixed a bug where groups were not renamed when starting with a number. 61 | - Fixed a bug where disabled rules were merged with enabled one 62 | 63 | v0.13 - 2015-05-07 64 | Features: 65 | - Fixed a bug where groups were not renamed properly 66 | - Fixed a bug where "any" objects were not appended to group members 67 | - Fixed a bug where fw rules did not contain the right objects 68 | - Fixed a bug where "tcp-udp" protocol was not created properly 69 | 70 | v0.12 - 2015-04-27 71 | Features: 72 | - updated formating 73 | - Removed labels 74 | - Fixed a bug where group renaming was not working properly 75 | 76 | v0.11 - 2015-04-24 77 | Features: 78 | - Do not merge rules from different ACLs 79 | - Fixed issues with group renaming 80 | 81 | v0.10 - 2015-04-21 82 | Features: 83 | - Fixed NAT issue where "interface" become a hide rule 84 | - Written Cisco2CheckpointManager class that can interact with multiple config files 85 | 86 | v0.09 - 2015-04-20 87 | Features: 88 | - Worked on a procedure 89 | - Fixed the "network" alias on CiscoHost 90 | - Updated text output 91 | 92 | v0.08 - 2015-04-17 93 | Features: 94 | - Fixed several redundancy bugs with "any" objects 95 | - Fixed a bug where "dest-unreach" and "echo" icmp messages were not imported properly 96 | - Moved some dictionaries to config.py 97 | - The script now support policy and installOn arguments 98 | - Fixed a bug where a mask was imported as subnet 99 | 100 | v0.07 - 2015-04-16 101 | Features: 102 | - Fixed multiple duplicate ports 103 | - Fixed multiple duplicate source 104 | - Fix a bug where "any4" is created as an object 105 | - Fixed a bug where "host" and "network" identifier were imported as objects 106 | 107 | v0.06 - 2015-04-15 108 | Features: 109 | - Fixed bug with comments 110 | - Fixed a bug where a CiscoRange was imported as a CiscoName 111 | - Fixed a bug where a CiscoHost was sometimes added as a CiscoNet 112 | - Removed some prefix/suffix characters in the comment fields 113 | - Added _fixDuplicateSubnet() to delete duplicate subnets 114 | - Added _fixDuplicateRange() to delete duplicate subnets 115 | - Changed order of _fixDuplicateName() because it was causing issues. 116 | - Added support for nat rules (static only) 117 | - Fixed a bug where "any" port was not flagged as "alreadyExist" 118 | - Fixed a bug where some character crash the import if a comments field contain bad chars (such as :) 119 | - Added a function to merge redundant rules 120 | 121 | v0.05 - 2015-04-14 122 | Features: 123 | - Fixed several issues 124 | - Added a function to sanitize illegal words and characters 125 | - Added the "any" host object and service object 126 | - Added a way to print all objects 127 | 128 | v0.04 - 2015-04-13 129 | Features: 130 | - Migrate a FW rule 131 | - Fixed several issues 132 | - Added a function to import all checkpoint ports in XML format. 133 | 134 | v0.03 - 2015-04-09 135 | Features: 136 | - Migrate a port, port-group 137 | 138 | v0.02 - 2015-04-09 139 | Features: 140 | - Migrate a host, subnet, range, network-group 141 | 142 | v0.01 - 2015-04-08 143 | Features: 144 | - Migrate a "name" 145 | 146 | -------------------------------------------------------------------------------- /tests/network_script.txt: -------------------------------------------------------------------------------- 1 | # Creating new host: myHost 2 | create host_plain myHost 3 | modify network_objects myHost ipaddr 10.0.1.201 4 | modify network_objects myHost comments " description mdube's VM in lab" 5 | modify network_objects myHost color "black" 6 | update network_objects myHost 7 | # Creating new host: H_10.0.1.101 8 | create host_plain H_10.0.1.101 9 | modify network_objects H_10.0.1.101 ipaddr 10.0.1.101 10 | modify network_objects H_10.0.1.101 comments "" 11 | modify network_objects H_10.0.1.101 color "black" 12 | update network_objects H_10.0.1.101 13 | # Creating new host: H_10.0.1.10 14 | create host_plain H_10.0.1.10 15 | modify network_objects H_10.0.1.10 ipaddr 10.0.1.10 16 | modify network_objects H_10.0.1.10 comments "" 17 | modify network_objects H_10.0.1.10 color "black" 18 | update network_objects H_10.0.1.10 19 | # Creating new host: myHost 20 | create host_plain myHost 21 | modify network_objects myHost ipaddr 10.0.1.201 22 | modify network_objects myHost comments " description mdube's VM in lab" 23 | modify network_objects myHost color "black" 24 | update network_objects myHost 25 | # Creating new host: H_10.0.1.101 26 | create host_plain H_10.0.1.101 27 | modify network_objects H_10.0.1.101 ipaddr 10.0.1.101 28 | modify network_objects H_10.0.1.101 comments "" 29 | modify network_objects H_10.0.1.101 color "black" 30 | update network_objects H_10.0.1.101 31 | # Creating new host: H_10.0.1.10 32 | create host_plain H_10.0.1.10 33 | modify network_objects H_10.0.1.10 ipaddr 10.0.1.10 34 | modify network_objects H_10.0.1.10 comments "" 35 | modify network_objects H_10.0.1.10 color "black" 36 | update network_objects H_10.0.1.10 37 | # Creating new subnet: myLAN 38 | create network myLAN 39 | modify network_objects myLAN ipaddr 10.0.1.0 40 | modify network_objects myLAN netmask 255.255.255.0 41 | modify network_objects myLAN comments " description LAN" 42 | modify network_objects myLAN color "black" 43 | update network_objects myLAN 44 | # Creating new subnet: myDMZ 45 | create network myDMZ 46 | modify network_objects myDMZ ipaddr 10.0.2.0 47 | modify network_objects myDMZ netmask 255.255.255.0 48 | modify network_objects myDMZ comments " description DMZ" 49 | modify network_objects myDMZ color "black" 50 | update network_objects myDMZ 51 | # Creating new network group: MyInternal 52 | create network_object_group MyInternal 53 | modify network_objects MyInternal comments "" 54 | modify network_objects MyInternal color "black" 55 | addelement network_objects MyInternal '' network_objects:myLAN 56 | addelement network_objects MyInternal '' network_objects:myDMZ 57 | update network_objects MyInternal 58 | # Creating new network group: MyAdmins 59 | create network_object_group MyAdmins 60 | modify network_objects MyAdmins comments "" 61 | modify network_objects MyAdmins color "black" 62 | addelement network_objects MyAdmins '' network_objects:myHost 63 | addelement network_objects MyAdmins '' network_objects:H_10.0.1.101 64 | update network_objects MyAdmins 65 | # Creating new port range: MyInternalPorts 66 | create tcp_service MyInternalPorts 67 | modify services MyInternalPorts port 49152-65535 68 | modify services MyInternalPorts src_port 1-65535 69 | modify services MyInternalPorts comments " description Client to DCs tcp Ports" 70 | update services MyInternalPorts 71 | # Creating new port range: TCP_8194-8198 72 | create tcp_service TCP_8194-8198 73 | modify services TCP_8194-8198 port 8194-8198 74 | modify services TCP_8194-8198 comments "" 75 | update services TCP_8194-8198 76 | # Creating new port range: TCP_4209-4220 77 | create tcp_service TCP_4209-4220 78 | modify services TCP_4209-4220 port 4209-4220 79 | modify services TCP_4209-4220 comments "" 80 | update services TCP_4209-4220 81 | # Creating new port group: MyCustomAppPorts 82 | create service_group MyCustomAppPorts 83 | modify services MyCustomAppPorts comments "" 84 | modify services MyCustomAppPorts color "black" 85 | addelement services MyCustomAppPorts '' services:TCP_8194-8198 86 | addelement services MyCustomAppPorts '' services:TCP_4209-4220 87 | addelement services MyCustomAppPorts '' services:ldap 88 | update services MyCustomAppPorts 89 | # Creating new rule: lan 90 | addelement fw_policies ##My_Policy rule security_rule 91 | modify fw_policies ##My_Policy rule:0:name "lan" 92 | modify fw_policies ##My_Policy rule:0:comments "LAN access to internet" 93 | modify fw_policies ##My_Policy rule:0:disabled false 94 | modify fw_policies ##My_Policy rule:0:src rule_source 95 | modify fw_policies ##My_Policy rule:0:dst rule_destination 96 | modify fw_policies ##My_Policy rule:0:services rule_services 97 | modify fw_policies ##My_Policy rule:0:install rule_install 98 | addelement fw_policies ##My_Policy rule:0:src:'' network_objects:myLAN 99 | modify fw_policies ##My_Policy rule:0:src:op '' 100 | addelement fw_policies ##My_Policy rule:0:dst:'' globals:Any 101 | modify fw_policies ##My_Policy rule:0:dst:op '' 102 | addelement fw_policies ##My_Policy rule:0:services:'' services:http 103 | addelement fw_policies ##My_Policy rule:0:services:'' services:https 104 | addelement fw_policies ##My_Policy rule:0:services:'' services:ftp 105 | modify fw_policies ##My_Policy rule:0:services:op '' 106 | addelement fw_policies ##My_Policy rule:0:action accept_action:accept 107 | addelement fw_policies ##My_Policy rule:0:install:'' network_objects:My_Firewall 108 | rmbyindex fw_policies ##My_Policy rule:0:track 0 109 | addelement fw_policies ##My_Policy rule:0:track tracks:None 110 | addelement fw_policies ##My_Policy rule:0:time globals:Any 111 | # Creating new rule: lan 112 | addelement fw_policies ##My_Policy rule security_rule 113 | modify fw_policies ##My_Policy rule:1:name "lan" 114 | modify fw_policies ##My_Policy rule:1:comments "LAN access to DMZ " 115 | modify fw_policies ##My_Policy rule:1:disabled false 116 | modify fw_policies ##My_Policy rule:1:src rule_source 117 | modify fw_policies ##My_Policy rule:1:dst rule_destination 118 | modify fw_policies ##My_Policy rule:1:services rule_services 119 | modify fw_policies ##My_Policy rule:1:install rule_install 120 | addelement fw_policies ##My_Policy rule:1:src:'' network_objects:myLAN 121 | modify fw_policies ##My_Policy rule:1:src:op '' 122 | addelement fw_policies ##My_Policy rule:1:dst:'' network_objects:myDMZ 123 | modify fw_policies ##My_Policy rule:1:dst:op '' 124 | addelement fw_policies ##My_Policy rule:1:services:'' services:MyCustomAppPorts 125 | modify fw_policies ##My_Policy rule:1:services:op '' 126 | addelement fw_policies ##My_Policy rule:1:action accept_action:accept 127 | addelement fw_policies ##My_Policy rule:1:install:'' network_objects:My_Firewall 128 | rmbyindex fw_policies ##My_Policy rule:1:track 0 129 | addelement fw_policies ##My_Policy rule:1:track tracks:None 130 | addelement fw_policies ##My_Policy rule:1:time globals:Any 131 | # Creating new rule: lan 132 | addelement fw_policies ##My_Policy rule security_rule 133 | modify fw_policies ##My_Policy rule:2:name "lan" 134 | modify fw_policies ##My_Policy rule:2:comments "Admin access" 135 | modify fw_policies ##My_Policy rule:2:disabled false 136 | modify fw_policies ##My_Policy rule:2:src rule_source 137 | modify fw_policies ##My_Policy rule:2:dst rule_destination 138 | modify fw_policies ##My_Policy rule:2:services rule_services 139 | modify fw_policies ##My_Policy rule:2:install rule_install 140 | addelement fw_policies ##My_Policy rule:2:src:'' network_objects:MyAdmins 141 | modify fw_policies ##My_Policy rule:2:src:op '' 142 | addelement fw_policies ##My_Policy rule:2:dst:'' globals:Any 143 | modify fw_policies ##My_Policy rule:2:dst:op '' 144 | addelement fw_policies ##My_Policy rule:2:services:'' globals:Any 145 | modify fw_policies ##My_Policy rule:2:services:op '' 146 | addelement fw_policies ##My_Policy rule:2:action accept_action:accept 147 | addelement fw_policies ##My_Policy rule:2:install:'' network_objects:My_Firewall 148 | rmbyindex fw_policies ##My_Policy rule:2:track 0 149 | addelement fw_policies ##My_Policy rule:2:track tracks:None 150 | addelement fw_policies ##My_Policy rule:2:time globals:Any 151 | # Creating new rule: dmz 152 | addelement fw_policies ##My_Policy rule security_rule 153 | modify fw_policies ##My_Policy rule:3:name "dmz" 154 | modify fw_policies ##My_Policy rule:3:comments "DMZ access to internet" 155 | modify fw_policies ##My_Policy rule:3:disabled false 156 | modify fw_policies ##My_Policy rule:3:src rule_source 157 | modify fw_policies ##My_Policy rule:3:dst rule_destination 158 | modify fw_policies ##My_Policy rule:3:services rule_services 159 | modify fw_policies ##My_Policy rule:3:install rule_install 160 | addelement fw_policies ##My_Policy rule:3:src:'' network_objects:myDMZ 161 | modify fw_policies ##My_Policy rule:3:src:op '' 162 | addelement fw_policies ##My_Policy rule:3:dst:'' network_objects:H_10.0.1.10 163 | modify fw_policies ##My_Policy rule:3:dst:op '' 164 | addelement fw_policies ##My_Policy rule:3:services:'' services:MyInternalPorts 165 | modify fw_policies ##My_Policy rule:3:services:op '' 166 | addelement fw_policies ##My_Policy rule:3:action accept_action:accept 167 | addelement fw_policies ##My_Policy rule:3:install:'' network_objects:My_Firewall 168 | rmbyindex fw_policies ##My_Policy rule:3:track 0 169 | addelement fw_policies ##My_Policy rule:3:track tracks:None 170 | addelement fw_policies ##My_Policy rule:3:time globals:Any 171 | # Creating new rule: outbound 172 | addelement fw_policies ##My_Policy rule security_rule 173 | modify fw_policies ##My_Policy rule:4:name "outbound" 174 | modify fw_policies ##My_Policy rule:4:comments "Internet access" 175 | modify fw_policies ##My_Policy rule:4:disabled false 176 | modify fw_policies ##My_Policy rule:4:src rule_source 177 | modify fw_policies ##My_Policy rule:4:dst rule_destination 178 | modify fw_policies ##My_Policy rule:4:services rule_services 179 | modify fw_policies ##My_Policy rule:4:install rule_install 180 | addelement fw_policies ##My_Policy rule:4:src:'' globals:Any 181 | modify fw_policies ##My_Policy rule:4:src:op '' 182 | addelement fw_policies ##My_Policy rule:4:dst:'' network_objects:MyInternal 183 | modify fw_policies ##My_Policy rule:4:dst:op '' 184 | addelement fw_policies ##My_Policy rule:4:services:'' services:icmp-proto 185 | modify fw_policies ##My_Policy rule:4:services:op '' 186 | addelement fw_policies ##My_Policy rule:4:action accept_action:accept 187 | addelement fw_policies ##My_Policy rule:4:install:'' network_objects:My_Firewall 188 | rmbyindex fw_policies ##My_Policy rule:4:track 0 189 | addelement fw_policies ##My_Policy rule:4:track tracks:None 190 | addelement fw_policies ##My_Policy rule:4:time globals:Any 191 | # Creating new rule: outbound 192 | addelement fw_policies ##My_Policy rule security_rule 193 | modify fw_policies ##My_Policy rule:5:name "outbound" 194 | modify fw_policies ##My_Policy rule:5:comments "" 195 | modify fw_policies ##My_Policy rule:5:disabled false 196 | modify fw_policies ##My_Policy rule:5:src rule_source 197 | modify fw_policies ##My_Policy rule:5:dst rule_destination 198 | modify fw_policies ##My_Policy rule:5:services rule_services 199 | modify fw_policies ##My_Policy rule:5:install rule_install 200 | addelement fw_policies ##My_Policy rule:5:src:'' network_objects:MyInternal 201 | modify fw_policies ##My_Policy rule:5:src:op '' 202 | addelement fw_policies ##My_Policy rule:5:dst:'' globals:Any 203 | modify fw_policies ##My_Policy rule:5:dst:op '' 204 | addelement fw_policies ##My_Policy rule:5:services:'' services:http 205 | addelement fw_policies ##My_Policy rule:5:services:'' services:https 206 | addelement fw_policies ##My_Policy rule:5:services:'' services:ftp 207 | modify fw_policies ##My_Policy rule:5:services:op '' 208 | addelement fw_policies ##My_Policy rule:5:action accept_action:accept 209 | addelement fw_policies ##My_Policy rule:5:install:'' network_objects:My_Firewall 210 | rmbyindex fw_policies ##My_Policy rule:5:track 0 211 | addelement fw_policies ##My_Policy rule:5:track tracks:None 212 | addelement fw_policies ##My_Policy rule:5:time globals:Any 213 | update_all -------------------------------------------------------------------------------- /tests/network_script_debug.txt: -------------------------------------------------------------------------------- 1 | Namespace(ciscoDir='', ciscoFile='tests/test_policy.CONFIG', color='black', cpNetObjFile='cp/default_r7730_network_objects.xml', cpPortsFile='cp/default_r7730_service_objects.xml', debug=True, disableRules=False, export=False, filter=None, flattenInlineNetGroups=False, flattenInlineSvcGroups=False, forceLog=False, format='dbedit', installOn='My_Firewall', natInstallOn='vs01', output='tests/network_script_verify.txt', policy='My_Policy', search='', startIndex=0, stdout=False, summary=False, syntax='asa', verify=True) 2 | #[+] Importing all objects except groups. 3 | #[+] Importing Checkpoint network objects 4 | #[+] Importing all hosts. 5 | #[-] Importing: 6 | #[+] Importing all networks. 7 | #[-] Importing: 8 | #[-] Importing: 9 | #[+] Importing all ranges. 10 | #[+] Fixing duplicate names 11 | #[+] Fixing duplicate IP addresses 12 | #[+] Fixing duplicate subnets 13 | #[+] Fixing duplicate ranges 14 | #[+] Importing Checkpoint ports objects 15 | #[+] Adding ICMP Aliases 16 | #[-] Adding Alias "unreachable" on object "dest-unreach" 17 | #[-] Adding Alias "mobile-redirect" on object "redirect" 18 | #[-] Adding Alias "echo" on object "echo-request" 19 | #[-] Adding Alias "parameter-problem" on object "param-prblm" 20 | #[-] Adding Alias "information-request" on object "info-req" 21 | #[-] Adding Alias "information-reply" on object "info-reply" 22 | #[+] Importing all single ports objects. 23 | #[+] Importing all port ranges objects. 24 | #[-] Importing: 25 | #[+] Importing all net/host/range groups. 26 | #[-] Importing: 27 | #[-] Adding member myLAN to group MyInternal 28 | #[-] Adding member myDMZ to group MyInternal 29 | #[-] Importing: 30 | #[-] Adding member myHost to group MyAdmins 31 | #[-] Warning: Could not find object "10.0.1.101" (host). The script will create it. 32 | #[-] Adding member H_10.0.1.101 to group MyAdmins 33 | #[+] Importing all port groups. 34 | #[-] Importing: 35 | #[-] Warning: Could not find object "tcp/8194-8198" (range). The script will create it. 36 | #[-] Adding member TCP_8194-8198 to group MyCustomAppPorts 37 | #[-] Warning: Could not find object "tcp/4209-4220" (range). The script will create it. 38 | #[-] Adding member TCP_4209-4220 to group MyCustomAppPorts 39 | #[-] Adding member ldap to group MyCustomAppPorts 40 | #[+] Importing all protocol groups. 41 | #[+] Importing all NAT rules. 42 | #[+] Importing all firewall rules. (access-list) 43 | #[-] Warning: Could not find object "any" (host). The script will create it. 44 | #[-] Warning: Could not find object "any" (ip). The script will create it. 45 | #[-] Warning: Could not find object "10.0.1.10" (host). The script will create it. 46 | #[-] Warning: Could not find object "any" (icmp). The script will create it. 47 | #[-] Adding Alias "any" on object "icmp-proto" 48 | #[+] Importing all firewall rules. (ip access-list) 49 | #[+] Merging redundant ACL rules 50 | #[-] Merging: ACLRule(name=lan,src=myLAN,dst=any,port=http;https,action=permit,pol=My_Policy,inst=My_Firewall,disabled=False,desc=LAN access to internet) 51 | #[-] With: ACLRule(name=lan,src=myLAN,dst=any,port=ftp,action=permit,pol=My_Policy,inst=My_Firewall,disabled=False,desc=) 52 | #[-] Adding CiscoLine "" on object "lan" 53 | #[-] Result: ACLRule(name=lan,src=myLAN,dst=any,port=http;https;ftp,action=permit,pol=My_Policy,inst=My_Firewall,disabled=False,desc=LAN access to internet) 54 | #[+] Exporting to verify format 55 | # Summary of the findings in "tests/test_policy.CONFIG" 56 | # 57 | # Number of names (before merge/cleanup): 0 58 | # Number of names (after merge/cleanup): 0 59 | # Number of hosts (imported from cisco file): 1 60 | # Number of hosts (imported from checkpoint xml): 1 61 | # Number of hosts (dynamically created): 2 62 | # Number of hosts (after merge/cleanup): 1 63 | # Number of subnet (imported from cisco file): 1 64 | # Number of subnet (imported from checkpoint xml): 2 65 | # Number of subnet (dynamically created): 0 66 | # Number of subnet (after merge/cleanup): 2 67 | # Number of range (imported from cisco file): 0 68 | # Number of range (imported from checkpoint xml): 0 69 | # Number of range (dynamically created): 0 70 | # Number of range (after merge/cleanup): 0 71 | # Number of subnet groups: 2 72 | # Number of service groups: 1 73 | # Number of nat rules: 0 74 | # Number of acl rules (not imported: established): 0 75 | # Number of acl rules (not imported: source port): 0 76 | # Number of acl rules (before merge/cleanup): 0 77 | # Number of acl rules (after merge/cleanup): 6 78 | # Number of single ports (imported from cisco file): 261 79 | # Number of single ports (imported from checkpoint xml): 0 80 | # Number of single ports (dynamically created): 0 81 | # Number of port range (imported from cisco file): 0 82 | # Number of port range (imported from checkpoint xml): 1 83 | # Number of port range (dynamically created): 2 84 | 85 | -------------------------------------------------------------------------------- /tests/network_script_verify.txt: -------------------------------------------------------------------------------- 1 | CiscoHost(name=myHost,ipAddr=10.0.1.201,desc= description mdube's VM in lab,alias=) 2 | CiscoNet(name=myLAN,ipAddr=10.0.1.0/255.255.255.0,desc= description LAN,alias=) 3 | CiscoNet(name=myDMZ,ipAddr=10.0.2.0/255.255.255.0,desc= description DMZ,alias=) 4 | CiscoIcmp(name=echo-reply,desc=ICMP, echo reply,alias=) 5 | CiscoIcmp(name=dest-unreach,desc=ICMP, destination unreach,alias=unreachable) 6 | CiscoIcmp(name=source-quench,desc=ICMP, source quench,alias=) 7 | CiscoIcmp(name=redirect,desc=ICMP, route redirect,alias=mobile-redirect) 8 | CiscoIcmp(name=echo-request,desc=ICMP, echo request,alias=echo) 9 | CiscoIcmp(name=time-exceeded,desc=ICMP, time to live exceeded,alias=) 10 | CiscoIcmp(name=param-prblm,desc=ICMP, parameters problem,alias=parameter-problem) 11 | CiscoIcmp(name=timestamp,desc=ICMP, timestamp request,alias=) 12 | CiscoIcmp(name=timestamp-reply,desc=ICMP, timestamp reply,alias=) 13 | CiscoIcmp(name=info-req,desc=ICMP, info request,alias=information-request) 14 | CiscoIcmp(name=info-reply,desc=ICMP, info reply,alias=information-reply) 15 | CiscoIcmp(name=mask-request,desc=ICMP, mask request,alias=) 16 | CiscoIcmp(name=mask-reply,desc=ICMP, mask reply,alias=) 17 | CiscoServiceRange(name=MyInternalPorts,port=49152-65535,src_port=1-65535,desc= description Client to DCs tcp Ports) 18 | CiscoNetGroup(name=MyInternal,desc=,nbMembers=2,alias=) 19 | CiscoNet(name=myLAN,ipAddr=10.0.1.0/255.255.255.0,desc= description LAN,alias=) 20 | CiscoNet(name=myDMZ,ipAddr=10.0.2.0/255.255.255.0,desc= description DMZ,alias=) 21 | Verify: 22 | CiscoHost(name=H_10.0.1.101,ipAddr=10.0.1.101,desc=,alias=) 23 | CiscoNetGroup(name=MyAdmins,desc=,nbMembers=2,alias=) 24 | CiscoHost(name=myHost,ipAddr=10.0.1.201,desc= description mdube's VM in lab,alias=) 25 | CiscoHost(name=H_10.0.1.101,ipAddr=10.0.1.101,desc=,alias=) 26 | Verify: 27 | CiscoServiceRange(name=TCP_8194-8198,port=8194-8198,desc=) 28 | CiscoServiceRange(name=TCP_4209-4220,port=4209-4220,desc=) 29 | CiscoServiceGroup(name=MyCustomAppPorts,desc=,nbMembers=3) 30 | CiscoServiceRange(name=TCP_8194-8198,port=8194-8198,desc=) 31 | CiscoServiceRange(name=TCP_4209-4220,port=4209-4220,desc=) 32 | CiscoServicePort(name=ldap,port=389,desc=Lightweight Directory Access Protocol,alias=) 33 | Verify: 34 | ACLRule(name=lan,src=myLAN,dst=any,port=http;https;ftp,action=permit,pol=My_Policy,inst=My_Firewall,disabled=False,desc=LAN access to internet) 35 | Desc:LAN access to internet 36 | Src: CiscoNet(name=myLAN,ipAddr=10.0.1.0/255.255.255.0,desc= description LAN,alias=) 37 | Dst: CiscoAnyHost(name=any,ipAddr=None,desc=,alias=) 38 | Port: CiscoServicePort(name=http,port=80,desc=Hypertext Transfer Protocol,alias=) 39 | Port: CiscoServicePort(name=https,port=443,desc=HTTP protocol over TLS/SSL,alias=) 40 | Port: CiscoServicePort(name=ftp,port=21,desc=File Transfer Protocol,alias=) 41 | Verify: 42 | Verify: 43 | ACLRule(name=lan,src=myLAN,dst=myDMZ,port=MyCustomAppPorts,action=permit,pol=My_Policy,inst=My_Firewall,disabled=False,desc=LAN access to DMZ ) 44 | Desc:LAN access to DMZ 45 | Src: CiscoNet(name=myLAN,ipAddr=10.0.1.0/255.255.255.0,desc= description LAN,alias=) 46 | Dst: CiscoNet(name=myDMZ,ipAddr=10.0.2.0/255.255.255.0,desc= description DMZ,alias=) 47 | Port: CiscoServiceGroup(name=MyCustomAppPorts,desc=,nbMembers=3) 48 | CiscoServiceRange(name=TCP_8194-8198,port=8194-8198,desc=) 49 | CiscoServiceRange(name=TCP_4209-4220,port=4209-4220,desc=) 50 | CiscoServicePort(name=ldap,port=389,desc=Lightweight Directory Access Protocol,alias=) 51 | Verify: 52 | ACLRule(name=lan,src=MyAdmins,dst=any,port=any,action=permit,pol=My_Policy,inst=My_Firewall,disabled=False,desc=Admin access) 53 | Desc:Admin access 54 | Src: CiscoNetGroup(name=MyAdmins,desc=,nbMembers=2,alias=) 55 | CiscoHost(name=myHost,ipAddr=10.0.1.201,desc= description mdube's VM in lab,alias=) 56 | CiscoHost(name=H_10.0.1.101,ipAddr=10.0.1.101,desc=,alias=) 57 | Dst: CiscoAnyHost(name=any,ipAddr=None,desc=,alias=) 58 | Port: CiscoAnyPort(name=any,port=0,desc=,alias=) 59 | Verify: 60 | CiscoHost(name=H_10.0.1.10,ipAddr=10.0.1.10,desc=,alias=) 61 | ACLRule(name=dmz,src=myDMZ,dst=H_10.0.1.10,port=MyInternalPorts,action=permit,pol=My_Policy,inst=My_Firewall,disabled=False,desc=DMZ access to internet) 62 | Desc:DMZ access to internet 63 | Src: CiscoNet(name=myDMZ,ipAddr=10.0.2.0/255.255.255.0,desc= description DMZ,alias=) 64 | Dst: CiscoHost(name=H_10.0.1.10,ipAddr=10.0.1.10,desc=,alias=) 65 | Port: CiscoServiceRange(name=MyInternalPorts,port=49152-65535,src_port=1-65535,desc= description Client to DCs tcp Ports) 66 | Verify: 67 | CiscoAnyIcmp(name=icmp-proto,desc=,alias=any) 68 | ACLRule(name=outbound,src=any,dst=MyInternal,port=icmp-proto,action=permit,pol=My_Policy,inst=My_Firewall,disabled=False,desc=Internet access) 69 | Desc:Internet access 70 | Src: CiscoAnyHost(name=any,ipAddr=None,desc=,alias=) 71 | Dst: CiscoNetGroup(name=MyInternal,desc=,nbMembers=2,alias=) 72 | CiscoNet(name=myLAN,ipAddr=10.0.1.0/255.255.255.0,desc= description LAN,alias=) 73 | CiscoNet(name=myDMZ,ipAddr=10.0.2.0/255.255.255.0,desc= description DMZ,alias=) 74 | Port: CiscoAnyIcmp(name=icmp-proto,desc=,alias=any) 75 | Verify: 76 | ACLRule(name=outbound,src=MyInternal,dst=any,port=http;https;ftp,action=permit,pol=My_Policy,inst=My_Firewall,disabled=False,desc=) 77 | Desc: 78 | Src: CiscoNetGroup(name=MyInternal,desc=,nbMembers=2,alias=) 79 | CiscoNet(name=myLAN,ipAddr=10.0.1.0/255.255.255.0,desc= description LAN,alias=) 80 | CiscoNet(name=myDMZ,ipAddr=10.0.2.0/255.255.255.0,desc= description DMZ,alias=) 81 | Dst: CiscoAnyHost(name=any,ipAddr=None,desc=,alias=) 82 | Port: CiscoServicePort(name=http,port=80,desc=Hypertext Transfer Protocol,alias=) 83 | Port: CiscoServicePort(name=https,port=443,desc=HTTP protocol over TLS/SSL,alias=) 84 | Port: CiscoServicePort(name=ftp,port=21,desc=File Transfer Protocol,alias=) 85 | Verify: 86 | -------------------------------------------------------------------------------- /tests/test_policy.CONFIG: -------------------------------------------------------------------------------- 1 | ! 2 | ! **** First lines removed for brevity **** 3 | ! 4 | object network myHost 5 | description mdube's VM in lab 6 | host 10.0.1.201 7 | ! 8 | object network myLAN 9 | description LAN 10 | subnet 10.0.1.0 255.255.255.0 11 | object network myDMZ 12 | description DMZ 13 | subnet 10.0.2.0 255.255.255.0 14 | ! 15 | object service MyInternalPorts 16 | service tcp source range 1 65535 destination range 49152 65535 17 | description Client to DCs tcp Ports 18 | ! 19 | object-group network MyInternal 20 | network-object object myLAN 21 | network-object object myDMZ 22 | ! 23 | object-group network MyAdmins 24 | network-object object myHost 25 | network-object host 10.0.1.101 26 | ! 27 | object-group service MyCustomAppPorts tcp 28 | description All Web Ports 29 | port-object range 8194 8198 30 | port-object range 4209 4220 31 | port-object eq ldap 32 | ! 33 | ! ** Currently buggy. TODO: Fix this ** 34 | !object-group icmp-type MyICMP 35 | ! icmp-object echo 36 | ! icmp-object echo-reply 37 | ! icmp-object time-exceeded 38 | ! icmp-object unreachable 39 | ! 40 | !object-group protocol TCPUDP 41 | ! protocol-object udp 42 | ! protocol-object tcp 43 | ! 44 | access-list lan remark LAN access to internet 45 | access-list lan extended permit tcp object myLAN any4 eq www https 46 | access-list lan extended permit tcp object myLAN any4 eq ftp 47 | access-list lan remark LAN access to DMZ 48 | access-list lan extended permit tcp object myLAN object myDMZ object-group MyCustomAppPorts 49 | access-list lan remark Admin access 50 | access-list lan extended permit ip object-group myAdmins any4 51 | access-list dmz remark DMZ access to internet 52 | access-list dmz extended permit object MyInternalPorts object myDMZ host 10.0.1.10 53 | access-list outbound remark Internet access 54 | access-list outbound extended permit icmp any4 object-group MyInternal object-group MyICMP 55 | access-list outbound extended permit tcp object-group MyInternal any4 eq www https ftp 56 | ! 57 | ! **** Last lines removed for brevity **** 58 | ! 59 | -------------------------------------------------------------------------------- /tools/dbedit_export_objects.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "printxml network_objects" > printxml_netobj.txt 3 | echo "printxml services" > printxml_services.txt 4 | echo '' > customer_network_objects.xml 5 | dbedit -local -f printxml_netobj.txt >> customer_network_objects.xml 6 | echo '' >> customer_network_objects.xml 7 | echo '' > customer_service_objects.xml 8 | dbedit -local -f printxml_services.txt >> customer_service_objects.xml 9 | echo '' >> customer_service_objects.xml 10 | # rm printxml_netobj.txt 11 | # rm printxml_services.txt 12 | -------------------------------------------------------------------------------- /tools/mass_object_update.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoSecure/Cisco2Checkpoint/2c0ffe066541646a64eb43ad9574d6e753f566cf/tools/mass_object_update.xlsx --------------------------------------------------------------------------------