From 5acc9238835215cdcc0c37b27697436c0f895d4d Mon Sep 17 00:00:00 2001 From: Vadim Kurland Date: Mon, 28 Dec 2009 02:02:33 +0000 Subject: [PATCH] * PolicyCompiler_iosacl.cpp (PolicyCompiler_iosacl::addDefaultPolicyRule): compiler for IOS ACL added only inbound automatic rule to permit ssh access from the management workstation but did not add a rule to permit reply packets. This fixes #993 --- build_num | 2 +- doc/ChangeLog | 5 + src/cisco_lib/PolicyCompiler_cisco.cpp | 57 +- src/cisco_lib/PolicyCompiler_cisco.h | 2 +- src/cisco_lib/PolicyCompiler_iosacl.cpp | 30 + src/cisco_lib/PolicyCompiler_iosacl.h | 2 + test/iosacl/objects-for-regression-tests.fwb | 1008 ++++++++++-------- test/iosacl/quick-cmp.sh | 2 +- test/pix/objects-for-regression-tests.fwb | 19 +- 9 files changed, 646 insertions(+), 481 deletions(-) diff --git a/build_num b/build_num index 41306e751..e05d55d6a 100644 --- a/build_num +++ b/build_num @@ -1 +1 @@ -#define BUILD_NUM 2282 +#define BUILD_NUM 2283 diff --git a/doc/ChangeLog b/doc/ChangeLog index d0bae82f9..e3333175a 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,5 +1,10 @@ 2009-12-27 vadim + * PolicyCompiler_iosacl.cpp (PolicyCompiler_iosacl::addDefaultPolicyRule): + compiler for IOS ACL added only inbound automatic rule to permit + ssh access from the management workstation but did not add a rule + to permit reply packets. This fixes #993 + * CompilerDriver_iosacl_run.cpp (CompilerDriver_iosacl::run): fixed bug (no #): compiler for iosacl failed to open output file because of the wrong path. diff --git a/src/cisco_lib/PolicyCompiler_cisco.cpp b/src/cisco_lib/PolicyCompiler_cisco.cpp index deee797c4..45f4c8240 100644 --- a/src/cisco_lib/PolicyCompiler_cisco.cpp +++ b/src/cisco_lib/PolicyCompiler_cisco.cpp @@ -110,11 +110,15 @@ void PolicyCompiler_cisco::addDefaultPolicyRule() if ( getCachedFwOpt()->getBool("mgmt_ssh") && !getCachedFwOpt()->getStr("mgmt_addr").empty() ) { - PolicyRule *r; TCPService *ssh = dbcopy->createTCPService(); ssh->setDstRangeStart(22); ssh->setDstRangeEnd(22); - dbcopy->add(ssh,false); + dbcopy->add(ssh, false); + + TCPService *ssh_rev = dbcopy->createTCPService(); + ssh_rev->setSrcRangeStart(22); + ssh_rev->setSrcRangeEnd(22); + dbcopy->add(ssh_rev, false); Network *mgmt_workstation = dbcopy->createNetwork(); mgmt_workstation->setAddressNetmask( @@ -122,52 +126,11 @@ void PolicyCompiler_cisco::addDefaultPolicyRule() dbcopy->add(mgmt_workstation, false); - r= dbcopy->createPolicyRule(); - temp_ruleset->add(r); - r->setAction(PolicyRule::Accept); - r->setLogging(false); - r->setDirection(PolicyRule::Inbound); - r->setPosition(-1); -// r->setComment(" backup ssh access rule "); - r->setHidden(true); - r->setFallback(false); - r->setLabel("backup ssh access rule"); - - RuleElement *src=RuleElement::cast( - r->getFirstByType(RuleElementSrc::TYPENAME) ); - src->addRef(mgmt_workstation); - - RuleElement *dst=RuleElement::cast( - r->getFirstByType(RuleElementDst::TYPENAME) ); - dst->addRef(fw); - - RuleElement *srv=RuleElement::cast( - r->getFirstByType(RuleElementSrv::TYPENAME) ); - srv->addRef(ssh); - - combined_ruleset->push_front(r); + PolicyCompiler::addMgmtRule( + mgmt_workstation, fw, ssh, + NULL, PolicyRule::Inbound, PolicyRule::Accept, + "backup ssh access rule"); } - - // Ciscos provide built-in fallback rule so we do not need - // this. Besides, desired behavior is that if the user did not - // create any rules for a given interface (at all), then generated - // config file should have none. Adding fallback rule here creates - // 'deny any any' rule for such interfaces and screws things big - // time. -#if 0 - PolicyRule *r= dbcopy->createPolicyRule(); - - temp_ruleset->add(r); - r->setAction(PolicyRule::Deny); - r->setLogging(false); -// r->setDirection(PolicyRule::Both); - r->setPosition(10000); - r->setComment(" fallback rule "); - r->setLabel("fallback rule"); - r->setFallback(true); - r->setHidden(true); - combined_ruleset->push_back(r); -#endif } bool PolicyCompiler_cisco::splitIfSrcAny::processNext() diff --git a/src/cisco_lib/PolicyCompiler_cisco.h b/src/cisco_lib/PolicyCompiler_cisco.h index 19c588110..59df38028 100644 --- a/src/cisco_lib/PolicyCompiler_cisco.h +++ b/src/cisco_lib/PolicyCompiler_cisco.h @@ -58,7 +58,7 @@ protected: * this unconditional blocking rule in the end. See also comment * in the code regarding "pass_all_out" option */ - void addDefaultPolicyRule(); + virtual void addDefaultPolicyRule(); /** * prints rule in some universal format (close to that visible diff --git a/src/cisco_lib/PolicyCompiler_iosacl.cpp b/src/cisco_lib/PolicyCompiler_iosacl.cpp index 16536e638..59d9906cc 100644 --- a/src/cisco_lib/PolicyCompiler_iosacl.cpp +++ b/src/cisco_lib/PolicyCompiler_iosacl.cpp @@ -87,6 +87,36 @@ int PolicyCompiler_iosacl::prolog() return PolicyCompiler::prolog(); } +void PolicyCompiler_iosacl::addDefaultPolicyRule() +{ + PolicyCompiler_cisco::addDefaultPolicyRule(); + +/* + * PolicyCompiler_cisco::addDefaultPolicyRule() adds a rule to permit + * backup ssh access to the firewall. Since IOS ACL are stateless, we + * need to add another rule to permit reply packets. + */ + if ( getCachedFwOpt()->getBool("mgmt_ssh") && + !getCachedFwOpt()->getStr("mgmt_addr").empty() ) + { + TCPService *ssh_rev = dbcopy->createTCPService(); + ssh_rev->setSrcRangeStart(22); + ssh_rev->setSrcRangeEnd(22); + dbcopy->add(ssh_rev, false); + + Network *mgmt_workstation = dbcopy->createNetwork(); + mgmt_workstation->setAddressNetmask( + getCachedFwOpt()->getStr("mgmt_addr")); + + dbcopy->add(mgmt_workstation, false); + + PolicyCompiler::addMgmtRule( + fw, mgmt_workstation, ssh_rev, + NULL, PolicyRule::Outbound, PolicyRule::Accept, + "backup ssh access rule (out)"); + } +} + bool PolicyCompiler_iosacl::checkForDynamicInterface::findDynamicInterface( PolicyRule *rule, RuleElement *rel) { diff --git a/src/cisco_lib/PolicyCompiler_iosacl.h b/src/cisco_lib/PolicyCompiler_iosacl.h index 7ad6d5b59..e8e4abb61 100644 --- a/src/cisco_lib/PolicyCompiler_iosacl.h +++ b/src/cisco_lib/PolicyCompiler_iosacl.h @@ -55,6 +55,8 @@ namespace fwcompiler { protected: + virtual void addDefaultPolicyRule(); + /** * dynamic interfaces can not be used in policy rules in IOS ACLs */ diff --git a/test/iosacl/objects-for-regression-tests.fwb b/test/iosacl/objects-for-regression-tests.fwb index 753c35351..fad3baaf7 100644 --- a/test/iosacl/objects-for-regression-tests.fwb +++ b/test/iosacl/objects-for-regression-tests.fwb @@ -2,7 +2,7 @@ - + @@ -53,11 +53,11 @@ - + - + @@ -136,46 +136,46 @@ - + dscp af11 - - - - - - + + + + + + - + dscp af12 - - - - - - + + + + + + - + dscp af11 - - - - - - + + + + + + - - + + + - - + @@ -194,7 +194,8 @@ - + + @@ -213,7 +214,8 @@ - + + @@ -233,7 +235,8 @@ - + + @@ -254,7 +257,8 @@ - + + @@ -274,7 +278,8 @@ - + + @@ -294,7 +299,8 @@ - + + @@ -314,7 +320,8 @@ - + + @@ -334,7 +341,8 @@ - + + @@ -354,7 +362,8 @@ - + + @@ -374,7 +383,8 @@ - + + @@ -394,7 +404,8 @@ - + + @@ -414,7 +425,8 @@ - + + @@ -434,7 +446,8 @@ - + + @@ -454,7 +467,8 @@ - + + @@ -474,7 +488,8 @@ - + + @@ -494,7 +509,8 @@ - + + @@ -514,7 +530,8 @@ - + + @@ -534,7 +551,8 @@ - + + @@ -554,7 +572,8 @@ - + + @@ -574,7 +593,8 @@ - + + @@ -594,7 +614,8 @@ - + + @@ -613,19 +634,21 @@ - - + + + + + - - + - + - + @@ -638,12 +661,13 @@ - + - + @@ -662,15 +686,16 @@ - + - + - + - + + @@ -681,10 +706,10 @@ - + + - @@ -705,19 +730,20 @@ - - + - + + - - + @@ -737,7 +763,8 @@ - + + @@ -757,7 +784,8 @@ - + + @@ -777,7 +805,8 @@ - + + @@ -797,7 +826,8 @@ - + + @@ -817,7 +847,8 @@ - + + @@ -837,7 +868,8 @@ - + + @@ -856,7 +888,8 @@ - + + @@ -875,7 +908,8 @@ - + + @@ -894,7 +928,8 @@ - + + @@ -914,7 +949,8 @@ - + + @@ -936,7 +972,8 @@ - + + @@ -955,7 +992,8 @@ - + + @@ -975,7 +1013,8 @@ - + + @@ -996,7 +1035,8 @@ - + + @@ -1016,7 +1056,8 @@ - + + @@ -1035,7 +1076,8 @@ - + + @@ -1054,15 +1096,17 @@ - - + + + + + - - + - + @@ -1075,10 +1119,10 @@ - + - @@ -1091,21 +1135,21 @@ - - - - - + - + @@ -1115,10 +1159,10 @@ - - @@ -1140,17 +1184,17 @@ - - - + + + - - + @@ -1169,7 +1213,8 @@ - + + @@ -1188,7 +1233,8 @@ - + + @@ -1208,7 +1254,8 @@ - + + @@ -1229,7 +1276,8 @@ - + + @@ -1249,7 +1297,8 @@ - + + @@ -1269,7 +1318,8 @@ - + + @@ -1289,7 +1339,8 @@ - + + @@ -1309,7 +1360,8 @@ - + + @@ -1329,7 +1381,8 @@ - + + @@ -1349,7 +1402,8 @@ - + + @@ -1369,7 +1423,8 @@ - + + @@ -1389,7 +1444,8 @@ - + + @@ -1409,7 +1465,8 @@ - + + @@ -1429,7 +1486,8 @@ - + + @@ -1449,7 +1507,8 @@ - + + @@ -1469,7 +1528,8 @@ - + + @@ -1489,7 +1549,8 @@ - + + @@ -1509,7 +1570,8 @@ - + + @@ -1529,7 +1591,8 @@ - + + @@ -1548,15 +1611,17 @@ - - + + + + + - - + - + @@ -1569,11 +1634,12 @@ - + + @@ -1587,19 +1653,20 @@ - - + - + - - + - + + @@ -1610,10 +1677,10 @@ - + + - @@ -1634,19 +1701,20 @@ - - + - + + - - + @@ -1665,7 +1733,8 @@ - + + @@ -1684,7 +1753,8 @@ - + + @@ -1703,7 +1773,8 @@ - + + @@ -1722,7 +1793,8 @@ - + + @@ -1741,7 +1813,8 @@ - + + @@ -1760,7 +1833,8 @@ - + + @@ -1779,7 +1853,8 @@ - + + @@ -1798,7 +1873,8 @@ - + + @@ -1819,7 +1895,8 @@ - + + @@ -1838,7 +1915,8 @@ - + + @@ -1857,7 +1935,8 @@ - + + @@ -1876,7 +1955,9 @@ - + + + @@ -1914,26 +1995,25 @@ - + - - + - + - + - + - + @@ -1946,8 +2026,8 @@ - + @@ -1959,10 +2039,10 @@ - - @@ -1971,10 +2051,10 @@ - - + @@ -1989,7 +2069,7 @@ - @@ -2010,19 +2090,19 @@ - - - + + - - + @@ -2041,7 +2121,8 @@ - + + @@ -2061,9 +2142,11 @@ - + + + - + @@ -2082,7 +2165,8 @@ - + + @@ -2101,7 +2185,8 @@ - + + @@ -2120,7 +2205,8 @@ - + + @@ -2139,7 +2225,8 @@ - + + @@ -2158,7 +2245,8 @@ - + + @@ -2177,7 +2265,8 @@ - + + @@ -2196,7 +2285,8 @@ - + + @@ -2215,7 +2305,8 @@ - + + @@ -2234,7 +2325,8 @@ - + + @@ -2253,7 +2345,8 @@ - + + @@ -2272,7 +2365,8 @@ - + + @@ -2292,7 +2386,8 @@ - + + @@ -2311,7 +2406,8 @@ - + + @@ -2334,11 +2430,13 @@ - - + + + + + - - + @@ -2351,34 +2449,34 @@ - + - + - - - + - + + + @@ -2387,7 +2485,7 @@ - @@ -2396,13 +2494,13 @@ - - + + - @@ -2417,18 +2515,18 @@ - - - + - + + @@ -2447,7 +2545,7 @@ - @@ -2499,12 +2597,12 @@ - - - @@ -2515,11 +2613,11 @@ - + + - - + @@ -2538,7 +2636,8 @@ - + + @@ -2558,9 +2657,11 @@ - + + + - + @@ -2579,7 +2680,8 @@ - + + @@ -2598,7 +2700,8 @@ - + + @@ -2617,7 +2720,8 @@ - + + @@ -2636,7 +2740,8 @@ - + + @@ -2655,7 +2760,8 @@ - + + @@ -2674,7 +2780,8 @@ - + + @@ -2693,7 +2800,8 @@ - + + @@ -2712,7 +2820,8 @@ - + + @@ -2731,7 +2840,8 @@ - + + @@ -2750,7 +2860,8 @@ - + + @@ -2769,7 +2880,8 @@ - + + @@ -2789,7 +2901,8 @@ - + + @@ -2808,7 +2921,8 @@ - + + @@ -2831,11 +2945,13 @@ - - + + + + + - - + @@ -2848,34 +2964,34 @@ - + - + - - - + - + + + @@ -2884,7 +3000,7 @@ - @@ -2893,13 +3009,13 @@ - - + + - @@ -2918,14 +3034,14 @@ - - + - + + @@ -2944,7 +3060,7 @@ - @@ -2996,12 +3112,12 @@ - - - @@ -3012,11 +3128,11 @@ - + + - - + @@ -3035,7 +3151,8 @@ - + + @@ -3057,7 +3174,8 @@ - + + @@ -3077,9 +3195,11 @@ - + + + - + @@ -3098,7 +3218,8 @@ - + + @@ -3117,7 +3238,8 @@ - + + @@ -3136,7 +3258,8 @@ - + + @@ -3155,7 +3278,8 @@ - + + @@ -3174,7 +3298,8 @@ - + + @@ -3193,7 +3318,8 @@ - + + @@ -3212,7 +3338,8 @@ - + + @@ -3231,7 +3358,8 @@ - + + @@ -3250,7 +3378,8 @@ - + + @@ -3269,7 +3398,8 @@ - + + @@ -3288,7 +3418,8 @@ - + + @@ -3308,7 +3439,8 @@ - + + @@ -3327,7 +3459,8 @@ - + + @@ -3350,16 +3483,18 @@ - - + + + + + - - + - + @@ -3371,34 +3506,34 @@ - + - + - - - + - + + + @@ -3407,7 +3542,7 @@ - @@ -3416,13 +3551,13 @@ - - + + - @@ -3441,14 +3576,14 @@ - - + - + + @@ -3467,7 +3602,7 @@ - @@ -3519,12 +3654,12 @@ - - - @@ -3535,11 +3670,11 @@ - + + - - + @@ -3558,7 +3693,8 @@ - + + @@ -3578,9 +3714,11 @@ - + + + - + @@ -3599,7 +3737,8 @@ - + + @@ -3618,9 +3757,11 @@ - + + + - + @@ -3640,11 +3781,13 @@ - - + + + + + - - + @@ -3657,34 +3800,34 @@ - + - + - - - + - + + + @@ -3693,7 +3836,7 @@ - @@ -3702,13 +3845,13 @@ - - + + - @@ -3723,18 +3866,18 @@ - - - + - + + @@ -3753,7 +3896,7 @@ - @@ -3805,12 +3948,12 @@ - - - @@ -3821,11 +3964,11 @@ - + + - - + @@ -3845,7 +3988,8 @@ - + + @@ -3865,7 +4009,8 @@ - + + @@ -3885,7 +4030,8 @@ - + + @@ -3905,7 +4051,8 @@ - + + @@ -3925,7 +4072,8 @@ - + + @@ -3945,7 +4093,8 @@ - + + @@ -3964,7 +4113,8 @@ - + + @@ -3983,7 +4133,8 @@ - + + @@ -4002,7 +4153,8 @@ - + + @@ -4022,7 +4174,8 @@ - + + @@ -4044,7 +4197,8 @@ - + + @@ -4063,7 +4217,8 @@ - + + @@ -4082,7 +4237,8 @@ - + + @@ -4101,15 +4257,17 @@ - - + + + + + - - + - + @@ -4122,10 +4280,10 @@ - + - @@ -4138,21 +4296,21 @@ - - - - - + - + @@ -4162,10 +4320,10 @@ - - @@ -4187,7 +4345,7 @@ - @@ -4196,16 +4354,7 @@ - - - - - established - - established - -m state --state ESTABLISHED,RELATED - @@ -4238,14 +4387,23 @@ - - + + established - + + established + -m state --state ESTABLISHED,RELATED + + + + established + established -m state --state ESTABLISHED,RELATED + + diff --git a/test/iosacl/quick-cmp.sh b/test/iosacl/quick-cmp.sh index d4f939c2a..3d4d4c6a3 100755 --- a/test/iosacl/quick-cmp.sh +++ b/test/iosacl/quick-cmp.sh @@ -7,7 +7,7 @@ for f in $(ls *.fw.orig) do V="$f <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" echo "echo \"$V\" | cut -c1-72" - new_f=$(echo $f | sed 's/.org//') + new_f=$(echo $f | sed 's/.orig//') echo "$DIFFCMD $f $new_f" done exit 0 diff --git a/test/pix/objects-for-regression-tests.fwb b/test/pix/objects-for-regression-tests.fwb index 024610533..43534539b 100644 --- a/test/pix/objects-for-regression-tests.fwb +++ b/test/pix/objects-for-regression-tests.fwb @@ -892,7 +892,7 @@ - + @@ -1808,6 +1808,7 @@ + @@ -1828,6 +1829,7 @@ + @@ -1844,8 +1846,8 @@ - - + + @@ -1880,6 +1882,7 @@ + @@ -1888,11 +1891,11 @@ - + - + - + @@ -1956,6 +1959,7 @@ + @@ -1968,7 +1972,9 @@ + + @@ -1996,6 +2002,7 @@ +