Netmiko: How to send the enable password on a Cisco ASA after establishing the SSH session?

Created on 27 Aug 2018  路  10Comments  路  Source: ktbyers/netmiko

I have the following code in python.

device = form.cleaned_data['device'] username = form.cleaned_data['username'] password = form.cleaned_data['password'] dev = netmiko.ConnectHandler(device_type='cisco_asa', ip=device, username=username, password=password) if dev: enablepass = form.cleaned_data['enablepass'] dev.exit_enable_mode() print(dev.find_prompt()) dev.secret = enablepass dev = netmiko.redispatch(dev, device_type = 'cisco_asa') dev.enable() print(dev.find_prompt())

However i am unable to get the device to enter in to the enable mode.. What am I missing?

The idea is to have 2-factor which is used for both login and enable.

Most helpful comment

Try it with passing in the secret kwarg, that is how that is meant to function. Then you can also issue sshdevice.enable() this will handle it all for you.

sshdevice = netmiko.ConnectHandler(ip=device, device_type=device_type, username=username, password=password,secret=secret)
sshdevice.enable()

All 10 comments

I believe that you are needing to pass in the enable secret when creating your connection handler, this is what I do when needing to make connections to ASAs.

netmiko.ConnectHandler(ip=device, device_type=device_type, username=username, password=password, secret=enable_password)

I can do that just fine. The situation I am in is that initial SSH is using RSA. Next, once authenticated and inside the device, the "enable" authentication is again RSA. Hence I cannot send the secret during the initial connect. The alternate I think is to first

sshdevice = netmiko.ConnectHandler(ip=device, device_type=device_type, username=username, password=password)

Once the SSH connection is established i can do a "sshdevice.send_command("enable")". At this point the firewall is at the "Password: " prompt. I interact with the user to input the second RSA code. How will I pass this to the device?

How can I get "send_command_expect(command, expect_string='Password')" to work.?

Try it with passing in the secret kwarg, that is how that is meant to function. Then you can also issue sshdevice.enable() this will handle it all for you.

sshdevice = netmiko.ConnectHandler(ip=device, device_type=device_type, username=username, password=password,secret=secret)
sshdevice.enable()

Got it to work. Here is what I did.

            dev.send_command("enable"+'\n', expect_string=r'Password:')
            dev.send_command(enablepass, expect_string=r'#')
            dev.send_command(enablepass)

That would work but I think you're making it more difficult vs using the built in functions in netmiko.

I use this and it Works!

cisco_asa = {
'device_type': 'cisco_asa',
'ip': '10.251.11.11',
'username': 'soc5-itq',
'password': '***',
'secret': '
****',
'verbose': False,
}

Listado de Comandos a ejecutar

commands = [
'copy startup-config tftp:',
'10.250.2.73',
hostname,
]

net_connect = ConnectHandler(**cisco_asa)
net_connect.enable()
output = net_connect.send_config_set(commands)
print output

@whitej6 your solution worked smooth man, thanks a lot;

net_connect = ConnectHandler(**devices)
net_connect.send_command('terminal length 0')
net_connect.enable()
output = net_connect.send_command('show running-config')
print(output)

@dirtflake You probably don't need the terminal length 0 (Netmiko should do that automatically).

@ktbyers I am so happy that you have replied to my comment. I just started learning python and really loving Netmiko, I appreciate your effort to help the Network community.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rajaramanlala picture rajaramanlala  路  7Comments

aegiacometti picture aegiacometti  路  6Comments

akei9 picture akei9  路  7Comments

MichalTaratuta picture MichalTaratuta  路  7Comments

ktbyers picture ktbyers  路  5Comments