Last active
December 28, 2015 23:39
-
-
Save chmeee/7580328 to your computer and use it in GitHub Desktop.
Script en expect para efectuar pruebas de reglas en cotafuegos Palo Alto.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env expect | |
# Cada test debe ser de la forma: | |
# protocol XX from XX to XX source XX destination XX destination-port XX application XX | |
# protocol es obligatorio y puede ser 1 si es ICMP, 6 si es TCP, 17 si es UDP (ver /etc/protocols) | |
# destination-port es obligatorio | |
# application es opcional aunque conveniente si se sabe | |
# es conveniente indicar las zonas con from XX y to XX (es conveniente para evitar que se vaya por otra regla) | |
# El nombre del fichero se proporciona en el primer parámetro | |
set test_file [lindex $argv 0] | |
# Función para probar un test | |
proc test_palo {test} { | |
expect "(active)> " | |
send "test security-policy-match $test\r" | |
} | |
# Conexión al paloalto por ssh | |
spawn ssh -o VisualHostKey=no user@firewall | |
# Descomentar y poner la contraseña si no se usa clave ssh | |
# expect "Password: " | |
# send "xxxxxxxx!\r" | |
# Evitar que haga paginación cuando el resultado excede de la pantalla | |
expect "(active)> " | |
send "set cli pager off\r" | |
# Abre el fichero de pruebas y lanza una prueba por cada linea | |
set tests [open $test_file r] | |
while {[gets $tests test] != -1} { | |
test_palo $test | |
} | |
close $tests | |
# Finalizar la conexión | |
expect "(active)> " | |
send "exit\r" | |
expect eof |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment