Disaster Recovery for Cisco NAC L3 OOB with ACLs using NCM

NetCraftsmen®

#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
use Opsware::NAS::Connect;

my($host,$port,$user,$pass) = (‘localhost’,’$tc_proxy_telnet_port$’,’$tc_user_username$’,’$tc_user_password$’);
my $device = ‘#$tc_device_id$’;
my @output;
my @data;
my @auth_ports = ();
my $foundauth_flag = 0;
my $foundaccess_flag = 0;
my $done_flag = 0;
my $access_vlan;
my $auth_vlan;

my $con = Opsware::NAS::Connect->new(-user => $user, -pass => $pass, -host => $host, -port => $port);

$con->login();
$con->connect( $device ) or die “Failed to connect.”;

$con->cmd(“terminal length 0”);

# Looking for the authentication VLAN ID associated with # the VLAN name and the ports assigned to the authentication # VLAN
@output = $con->cmd(“show vlan name authentication”);

# Running through the output for each line of the results
foreach (@output) {
  # Printing the line of the command for display
  print “$_ “;
  # Splitting the line into an array based on white space   # as delimiters
  @data = split(/s+/);
  # Making sure there is data on the line, the line starts
  # with a number and has “authentication” as the second
  # field.  First field is the VLAN ID   if ($#data > 1 && $data[0] =~ /d+/ && $data[1] =~ /authentication/) {
    $auth_vlan = $data[0];
    $foundauth_flag = 1;
  }
  # Gathering switch ports in the VLAN
  if ($foundauth_flag == 1) {
    foreach (@data) {
      if ($data[0] =~ /VLAN/) {
        $done_flag = 1;
        last;
      }
      elsif (/Fa/ or /Gi/) {
        if (/,/) {
          chop;
        }
        $auth_ports[++$#auth_ports] = $_;
      }
    }    }
  if ($done_flag == 1) {
    last;
  }
}
# Gathering the VLAN ID for the access VLAN
@output = $con->cmd(“show vlan name staff1a”);
foreach (@output) {
  @data = split (/s+/);
  if ($#data > 2) {
    if ($data[0] =~ /d+/ && $data[1] =~ /staff1a/) {
      $access_vlan = $data[0];
      $foundaccess_flag = 1;
      last;
    }
  }
}

# Error Checking before assigning switch ports
if ($foundaccess_flag != 1) {
  print “Error:  Access VLAN not found “;
  exit 1;
}
if ($foundauth_flag != 1) {
  print “Error:  Authentication VLAN not found “;
  exit 1;
}

# Entering “configuration terminal” mode
@output = $con->cmd(“config t”);

# Displaying message saying that switchports are being # changed
print ” ################################################# “;
print “All ports in the authentication VLAN are being moved “;
print “to the access VLAN “;
print ” ################################################# “;
# Assigning the authentication VLAN ports to the access
# VLAN foreach (@auth_ports) {
  @output = $con->cmd(“int $_”);
  print join(” “, @output,” “);
  @output = $con->cmd(“switchport access vlan $access_vlan”);
  print join(” “, @output,” “);  }

@output = $con->cmd(“end”);
print join(” “, @output);

 
@output = $con->disconnect();

$con->logout();
undef $con;
exit(0);
 
 

Leave a Reply

 

Nick Kelly

Cybersecurity Engineer, Cisco

Nick has over 20 years of experience in Security Operations and Security Sales. He is an avid student of cybersecurity and regularly engages with the Infosec community at events like BSides, RVASec, Derbycon and more. The son of an FBI forensics director, Nick holds a B.S. in Criminal Justice and is one of Cisco’s Fire Jumper Elite members. When he’s not working, he writes cyberpunk and punches aliens on his Playstation.

 

Virgilio “BONG” dela Cruz Jr.

CCDP, CCNA V, CCNP, Cisco IPS Express Security for AM/EE
Field Solutions Architect, Tech Data

Virgilio “Bong” has sixteen years of professional experience in IT industry from academe, technical and customer support, pre-sales, post sales, project management, training and enablement. He has worked in Cisco Technical Assistance Center (TAC) as a member of the WAN and LAN Switching team. Bong now works for Tech Data as the Field Solutions Architect with a focus on Cisco Security and holds a few Cisco certifications including Fire Jumper Elite.

 

John Cavanaugh

CCIE #1066, CCDE #20070002, CCAr
Chief Technology Officer, Practice Lead Security Services, NetCraftsmen

John is our CTO and the practice lead for a talented team of consultants focused on designing and delivering scalable and secure infrastructure solutions to customers across multiple industry verticals and technologies. Previously he has held several positions including Executive Director/Chief Architect for Global Network Services at JPMorgan Chase. In that capacity, he led a team managing network architecture and services.  Prior to his role at JPMorgan Chase, John was a Distinguished Engineer at Cisco working across a number of verticals including Higher Education, Finance, Retail, Government, and Health Care.

He is an expert in working with groups to identify business needs, and align technology strategies to enable business strategies, building in agility and scalability to allow for future changes. John is experienced in the architecture and design of highly available, secure, network infrastructure and data centers, and has worked on projects worldwide. He has worked in both the business and regulatory environments for the design and deployment of complex IT infrastructures.