Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

automated conduit and outbound to acl conversion

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have a bunch of old PIXs someone left with conduits and outbounds, and I couldn't find anyone else who wrote a script...so I made one myself. Should work with most configs. But like any translation, there are differences that can't be translated exactly, but it does 99% of the work. But someone else may find it usefull.
Runs on UNIX with awk. Tested with standard linux and gawk 3.1.0.

#!/bin/sh
#
# Program to convert old conduit and outbound PIX configs to access-lists.
# This program attempts to convert conduits/outbounds to ACLs with the same function. Due to functionality
# differences, this is not always possible. Output will contain warnings if questionable commands are used.
#
# ACLs have an implicit DENY at the end, outbounds do not...THIS IS A HUGE DIFFERENCE and could block traffic!
# Again...verify all work before applying the output to a live PIX!!!!
#
# Written by: Will Morgan CCIE, CISSP
# Date Written: 02-12-02
# Date Modified: 02-14-02
# Version 2.01
# As this was written mostly in awk, it requires awk to run...duh.
#
# To report problems, or to comment email morgwil@hotmail.com
#
# Usage: pixconverter [-s] <file>
# &quot;-s&quot; will suppress WARNING messages


# The following lines parse the command line input for any options
SILENT=&quot;no&quot;
while [ $# -gt 0 ]
do
case &quot;$1&quot; in
-s) SILENT=&quot;yes&quot;;;
*) OLDCONFIG=$1;;
esac
shift
done

TMPDIR=/tmp
TMPCONFIG=$TMPDIR/tmpconf
INTINFO=$TMPDIR/info

# Following lines simply get &quot;apply&quot;s to beginning of file, conduits rely on this for correct processing
cat $OLDCONFIG | grep apply | awk -F &quot;(&quot; '{print $1&quot; &quot;$2}' | awk -F &quot;)&quot; '{print $1 $2}' > $TMPCONFIG
cat $OLDCONFIG | grep -v apply >> $TMPCONFIG

awk -v suppress=$SILENT '
BEGIN {
aclcount=0
staticcount=0
}
{
src1=&quot;\b&quot;
src2=&quot;\b&quot;
sp1=&quot;\b&quot;
sp2=&quot;\b&quot;
sp3=&quot;\b&quot;
dst1=&quot;\b&quot;
dst2=&quot;\b&quot;
dp1=&quot;\b&quot;
dp2=&quot;\b&quot;
dp3=&quot;\b&quot;
if ($1 == &quot;static&quot;) {
staticcount=staticcount+1
staticarray[staticcount,1]=$3
split($2, temparray, &quot;,&quot;)
split(temparray[2], temparray, &quot;)&quot;)
staticarray[staticcount,2]=temparray[1]
addtolist(staticarray[staticcount,2])
print
} else
if ($1 == &quot;conduit&quot;) {
applyacl=&quot;yes&quot;
action=$2
type=$3
i=4
getdst()
if (type != &quot;icmp&quot;) getdport()
getsrc()
if (type != &quot;icmp&quot;) getsport()
if (type == &quot;icmp&quot;) geticmp()
if (dst1 == &quot;host&quot;) {
dest=dst2 }
else dest=dst1
staticmatch=&quot;no&quot;
if (dest == &quot;any&quot;) {
staticmatch=&quot;yes&quot;
for (z = 1; z <= aclcount; z++) {
print &quot;access-list acl-&quot;aclarray[z]&quot; &quot;action&quot; &quot;type&quot; &quot;src1&quot; &quot;src2&quot; &quot;sp1&quot; &quot;sp2&quot; &quot;sp3&quot; &quot;dst1&quot; &quot;dst2&quot; &quot;dp1&quot; &quot;dp2&quot; &quot;dp3
}
} else
for (x = 1; x <= staticcount; x++) {
if (dest == staticarray[x,1]) {
print &quot;access-list acl-&quot;staticarray[x,2]&quot; &quot;action&quot; &quot;type&quot; &quot;src1&quot; &quot;src2&quot; &quot;sp1&quot; &quot;sp2&quot; &quot;sp3&quot; &quot;dst1&quot; &quot;dst2&quot; &quot;dp1&quot; &quot;dp2&quot; &quot;dp3
staticmatch=&quot;yes&quot;
}
}
if (staticmatch == &quot;no&quot;) {
if (suppress != &quot;yes&quot;) print &quot;WARNING! No exact static match...assuming outside interface for following line:&quot;
print &quot;access-list acl-outside &quot;action&quot; &quot;type&quot; &quot;src1&quot; &quot;src2&quot; &quot;sp1&quot; &quot;sp2&quot; &quot;sp3&quot; &quot;dst1&quot; &quot;dst2&quot; &quot;dp1&quot; &quot;dp2&quot; &quot;dp3
}
} else
if ($1 == &quot;apply&quot;) {
intarray[$3]=$2
dirarray[$3]=$4
} else
if ($1 == &quot;outbound&quot;) {
applyacl=&quot;yes&quot;
processoutbound()
if (dirarray[listnum] == &quot;outgoing_src&quot;) {
print &quot;access-list &quot;listname&quot; &quot;action&quot; &quot;ip&quot; &quot;mask&quot; &quot;p1&quot; &quot;p2&quot; &quot;p3&quot; any&quot;
}
else {
print &quot;access-list &quot;listname&quot; &quot;action&quot; any &quot;ip&quot; &quot;mask&quot; &quot;p1&quot; &quot;p2&quot; &quot;p3
}
}
else
if (applyacl == &quot;yes&quot;) {
for (i = 1; i <= aclcount; i++) {
print &quot;access-group acl-&quot;aclarray&quot; in interface &quot;aclarray
}
applyacl=&quot;no&quot;
print
}
else print
}

# This function adds the interface to a list of all interfaces that have acls on them.
# It first checks to see if the interface is already in the list
function addtolist(intf) {
for (y = 1; y <= aclcount; y++) {
if (aclarray[y] == intf) return
}
aclcount=aclcount+1
aclarray[aclcount]=intf
}

# This function parses an &quot;outbound&quot; statement and puts the parts in a variable. It keeps track
# of the last action to determine what &quot;except&quot; commands are desired to do.
function processoutbound() {
action=$3
if (action == &quot;permit&quot;) except=&quot;deny&quot;
if (action == &quot;deny&quot;) except=&quot;permit&quot;
if (action == &quot;except&quot;) {
action=except
if (suppress != &quot;yes&quot;) print &quot;WARNING! except line detected, assuming &quot;action&quot; for following command:&quot;
}
listnum=$2
ip=$4
mask=$5
p2=$6
if (p2 == &quot;0&quot;) {
p1=&quot;\b&quot;
p2=&quot;\b&quot;
p2=&quot;\b&quot;
}
else {
pnum=split(p2, parray, &quot;-&quot;)
if (pnum == 1) {
p1=&quot;eq&quot;
p2=parray[1]
p3=&quot;\b&quot;
}
else {
p1=&quot;range&quot;
p2=parray[1]
p3=parray[2]
}
}
if (NF < 7) { proto=&quot;ip&quot; } else proto=$7
if (proto == &quot;0&quot;) {proto=&quot;ip&quot;}
listname=&quot;acl-&quot;intarray[listnum]
addtolist(intarray[listnum])
}

# This function gets the source ip and mask from a conduit statement and increments the index pointer &quot;i&quot;
function getsrc() {
if (i <= NF) {
if ($i == &quot;any&quot;) {
src1=$i
i=i+1
src2=&quot;\b&quot;
}
else {
src1=$i
i=i+1
src2=$i
i=i+1
}
}
else {
src1=&quot;\b&quot;
src2=&quot;\b&quot;
}
}

# This function gets the destination ip and mask from a conduit statement.
function getdst() {
if (i <= NF) {
if ($i == &quot;any&quot;) {
dst1=$i
i=i+1
dst2=&quot;\b&quot;
}
else {
dst1=$i
i=i+1
dst2=$i
i=i+1
}
}
else {
dst1=&quot;\b&quot;
dst2=&quot;\b&quot;
}
}

# This function gets icmp info from a conduit statment if it exists.
function geticmp() {
if (i <= NF) {
dp1=$i
dp2=&quot;\b&quot;
dp3=&quot;\b&quot;
}
}

# This function gets the source port info from a conduit statement.
function getsport() {
if (i <= NF) {
if ($i == &quot;eq&quot;) {
sp1=$i
i=i+1
sp2=$i
i=i+1
sp3=&quot;\b&quot;
} else
if ($i == &quot;neq&quot;) {
sp1=$i
i=i+1
sp2=$i
i=i+1
sp3=&quot;\b&quot;
} else
if ($i == &quot;gt&quot;) {
sp1=$i
i=i+1
sp2=$i
i=i+1
sp3=&quot;\b&quot;
} else
if ($i == &quot;lt&quot;) {
sp1=$i
i=i+1
sp2=$i
i=i+1
sp3=&quot;\b&quot;
} else
if ($i == &quot;range&quot;) {
sp1=$i
i=i+1
sp2=$i
i=i+1
sp3=$i
i=i+1
}
}
else {
sp1=&quot;\b&quot;
sp2=&quot;\b&quot;
sp3=&quot;\b&quot;
}
}

# This function gets destination port info from a conduit.
function getdport() {
if (i <= NF) {
if ($i == &quot;eq&quot;) {
dp1=$i
i=i+1
dp2=$i
i=i+1
dp3=&quot;\b&quot;
} else
if ($i == &quot;neq&quot;) {
dp1=$i
i=i+1
dp2=$i
i=i+1
dp3=&quot;\b&quot;
} else
if ($i == &quot;gt&quot;) {
dp1=$i
i=i+1
dp2=$i
i=i+1
dp3=&quot;\b&quot;
} else
if ($i == &quot;lt&quot;) {
dp1=$i
i=i+1
dp2=$i
i=i+1
dp3=&quot;\b&quot;
} else
if ($i == &quot;range&quot;) {
dp1=$i
i=i+1
dp2=$i
i=i+1
dp3=$i
i=i+1
}
}
else {
dp1=&quot;\b&quot;
dp2=&quot;\b&quot;
dp3=&quot;\b&quot;
}
}
' $TMPCONFIG
rm -Rf $TMPCONFIG


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top