From 8dcacd6aad481de9ff36aaadcf8eca31a0a4aa2d Mon Sep 17 00:00:00 2001 From: koalatea Date: Sat, 22 Apr 2017 22:23:24 -0400 Subject: [PATCH 1/5] Added Cisco2911 script to reset to factory defaults including when a password is set --- Cisco2911/README.md | 5 ++ Cisco2911/requirements.txt | 1 + Cisco2911/reset.py | 97 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 Cisco2911/README.md create mode 100644 Cisco2911/requirements.txt create mode 100644 Cisco2911/reset.py diff --git a/Cisco2911/README.md b/Cisco2911/README.md new file mode 100644 index 0000000..a7c586a --- /dev/null +++ b/Cisco2911/README.md @@ -0,0 +1,5 @@ +# GCCIS-IST-LabAutomation +Ensure python2.4 is installed and pip is installed then run either
+python -m pip install -r requirements.txt
+or
+pip install -r requirements.txt
diff --git a/Cisco2911/requirements.txt b/Cisco2911/requirements.txt new file mode 100644 index 0000000..f6c1a1f --- /dev/null +++ b/Cisco2911/requirements.txt @@ -0,0 +1 @@ +pyserial diff --git a/Cisco2911/reset.py b/Cisco2911/reset.py new file mode 100644 index 0000000..a2a792d --- /dev/null +++ b/Cisco2911/reset.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# writen for python 2.7 + +# should reset a ciscos password and configuration if plugged into a 2911 +# router when it is rebooting +# EDIT THE TWO port= LINES IF YOUR COM PORT IS DIFFERENT +import serial +import subprocess +import shlex + +#baudrate = get_baudrate('COM1') # linux + +console = serial.Serial( + port='COM1', #windows + #port='/dev/ttyUSB0', #what I expect it to be on Linux, dmesg when you plug in to find out + baudrate=9600, #default baudrate + parity='N', #default parity + stopbits=1, #default stopbits + bytesize=8, #default bytesize + timeout=8 +) + +print(console.isOpen()) + +#wait until break will do something +startup_text = '' +while 'program load complete,' not in startup_text: + startup_text += console.read(console.inWaiting()) + +#send break command +while 'rommon' not in startup_text: + console.send_break() + startup_text += console.read(console.inWaiting()) + print(startup_text) + +#make sure we enter rommon and set config register +if 'rommon' in startup_text: + print("entered rommon") + console.write('confreg 0x2142\r\n') + print("confreg 0x2142") + console.write('reset\r\n') + print("reset") + +#TODO Should be able to change this to a one line so that port does not need to be reused +print("closing connection in case default baudrate was not used") +console.close() +console = serial.Serial( + port='COM1', #windows + #port='/dev/ttyUSB0', #what I expect it to be on Linux, dmesg when you plug in to find out + baudrate=9600, #default baudrate + parity='N', #default parity + stopbits=1, #default stopbits + bytesize=8, #default bytesize + timeout=8 +) +print("console opened") +print(console.isOpen()) + +print("entering boot read loop") +#watch for the initialization prompt +startup_text = '' +while '[yes/no]:' not in startup_text: + startup_text += console.read(console.inWaiting()) + +print("Removing the current configuration") +#reset the device +console.write('no\r\n') + +print("waiting for Router>") +startup_text = '' +while 'Router>' not in startup_text: + console.write('\r\n') + startup_text += console.read(console.inWaiting()) +print(startup_text) + +console.write('enable\r\n') +console.write('delete nvram:/startup-config\r\n') +console.write('\r\n') +console.write('\r\n') +console.write('write erase\r\n') +console.write('\r\n') +console.write('\r\n') +print(console.read(console.inWaiting())) +console.write('configure terminal\r\n') +console.write('config-register 0x2102\r\n') +console.write('exit\r\n') +console.write('reload\r\n') +console.write('no\r\n') +print("completed") +#console.write('...\r\n') #\r\n is windows syntax? need to write a break + +def get_baudrate(device): + command = 'stty < {0}'.format(device) + proc_retval = subprocess.check_output(shlex.split(command)) + baudrate = int(proc_retval.split()[1]) + return baudrate From df72f4990f1a2d46be0d40b490dafa4533b4bdfe Mon Sep 17 00:00:00 2001 From: koalatea Date: Tue, 26 Sep 2017 14:45:29 -0400 Subject: [PATCH 2/5] added 3550 reset --- Cisco3550/README.md | 5 +++ Cisco3550/requirements.txt | 1 + Cisco3550/reset.py | 83 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 Cisco3550/README.md create mode 100644 Cisco3550/requirements.txt create mode 100644 Cisco3550/reset.py diff --git a/Cisco3550/README.md b/Cisco3550/README.md new file mode 100644 index 0000000..a7c586a --- /dev/null +++ b/Cisco3550/README.md @@ -0,0 +1,5 @@ +# GCCIS-IST-LabAutomation +Ensure python2.4 is installed and pip is installed then run either
+python -m pip install -r requirements.txt
+or
+pip install -r requirements.txt
diff --git a/Cisco3550/requirements.txt b/Cisco3550/requirements.txt new file mode 100644 index 0000000..f6c1a1f --- /dev/null +++ b/Cisco3550/requirements.txt @@ -0,0 +1 @@ +pyserial diff --git a/Cisco3550/reset.py b/Cisco3550/reset.py new file mode 100644 index 0000000..26f3d87 --- /dev/null +++ b/Cisco3550/reset.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# writen for python 2.7 + +# should reset a ciscos password and configuration if plugged into a 2911 +# router when it is rebooting +# EDIT THE TWO port= LINES IF YOUR COM PORT IS DIFFERENT +import serial +import subprocess +import shlex + +#baudrate = get_baudrate('COM1') # linux + +console = serial.Serial( + port='COM1', #windows + #port='/dev/ttyUSB0', #what I expect it to be on Linux, dmesg when you plug in to find out + baudrate=9600, #default baudrate + parity='N', #default parity + stopbits=1, #default stopbits + bytesize=8, #default bytesize + timeout=8 +) + +print(console.isOpen()) + +#wait until break will do something +startup_text = '' +while 'program load complete,' not in startup_text: + startup_text += console.read(console.inWaiting()) + +#send break command +while 'rommon' not in startup_text: + console.send_break() + startup_text += console.read(console.inWaiting()) + print(startup_text) + +#make sure we enter rommon and set config register +if 'rommon' in startup_text: + print("entered rommon") + console.write('flash_init\r\n') + print("flash_init") + console.write('load_helper\r\n') + print('load_helper') + console.write('rename flash:config.txt flash:config.old\r\n') + print('renamed config') + console.write('boot') + print("booting") + +print("entering boot read loop") +#watch for the initialization prompt +startup_text = '' +while '[yes/no]:' not in startup_text: + startup_text += console.read(console.inWaiting()) + +print("Removing the current configuration") +#reset the device +console.write('no\r\n') + +print("waiting for Router>") +startup_text = '' +while 'Router>' not in startup_text: + console.write('\r\n') + startup_text += console.read(console.inWaiting()) +print(startup_text) + +console.write('enable\r\n') +console.write('delete flash:config.old\r\n') +console.write('\r\n') +console.write('\r\n') +console.write('write erase\r\n') +console.write('\r\n') +console.write('\r\n') +print(console.read(console.inWaiting())) +console.write('reload\r\n') +console.write('no\r\n') +print("completed") +#console.write('...\r\n') #\r\n is windows syntax? need to write a break + +def get_baudrate(device): + command = 'stty < {0}'.format(device) + proc_retval = subprocess.check_output(shlex.split(command)) + baudrate = int(proc_retval.split()[1]) + return baudrate From d3e7f513513b57cafe10774d783f2b34d4ea7a68 Mon Sep 17 00:00:00 2001 From: koalatea Date: Tue, 26 Sep 2017 15:53:43 -0400 Subject: [PATCH 3/5] updated readmes and edited 3550 reset --- Cisco2911/README.md | 5 +++++ Cisco3550/README.md | 5 +++++ Cisco3550/reset.py | 4 ++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Cisco2911/README.md b/Cisco2911/README.md index a7c586a..16cac23 100644 --- a/Cisco2911/README.md +++ b/Cisco2911/README.md @@ -3,3 +3,8 @@ Ensure python2.4 is installed and pip is installed then run either
python -m pip install -r requirements.txt
or
pip install -r requirements.txt
+ +to reset a 2911 to write erased state bypassing a password, ensure the serial cable is plugged into the serial port on the 2911 and the COM is correct in reset.py +then run +python reset.py +and power cycle the 2911 \ No newline at end of file diff --git a/Cisco3550/README.md b/Cisco3550/README.md index a7c586a..c2295e3 100644 --- a/Cisco3550/README.md +++ b/Cisco3550/README.md @@ -3,3 +3,8 @@ Ensure python2.4 is installed and pip is installed then run either
python -m pip install -r requirements.txt
or
pip install -r requirements.txt
+ +to reset a 3550 to write erased state bypassing a password, ensure the serial cable is plugged into the serial port on the 2911 and the COM is correct in reset.py +then run +python reset.py +and power cycle the 3550 and hold the mode button \ No newline at end of file diff --git a/Cisco3550/reset.py b/Cisco3550/reset.py index 26f3d87..92c841f 100644 --- a/Cisco3550/reset.py +++ b/Cisco3550/reset.py @@ -29,13 +29,13 @@ startup_text += console.read(console.inWaiting()) #send break command -while 'rommon' not in startup_text: +while 'switch' not in startup_text: console.send_break() startup_text += console.read(console.inWaiting()) print(startup_text) #make sure we enter rommon and set config register -if 'rommon' in startup_text: +if 'switch' in startup_text: print("entered rommon") console.write('flash_init\r\n') print("flash_init") From 2a23ca79305e0d2961a024d506beb260ed139e84 Mon Sep 17 00:00:00 2001 From: koalatea Date: Tue, 26 Sep 2017 15:55:40 -0400 Subject: [PATCH 4/5] fixed readmes --- Cisco2911/README.md | 8 ++++---- Cisco3550/README.md | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cisco2911/README.md b/Cisco2911/README.md index 16cac23..4842c3b 100644 --- a/Cisco2911/README.md +++ b/Cisco2911/README.md @@ -4,7 +4,7 @@ python -m pip install -r requirements.txt
or
pip install -r requirements.txt
-to reset a 2911 to write erased state bypassing a password, ensure the serial cable is plugged into the serial port on the 2911 and the COM is correct in reset.py -then run -python reset.py -and power cycle the 2911 \ No newline at end of file +to reset a 2911 to write erased state bypassing a password, ensure the serial cable is plugged into the serial port on the 2911 and the COM is correct in reset.py
+then run
+python reset.py
+and power cycle the 2911
\ No newline at end of file diff --git a/Cisco3550/README.md b/Cisco3550/README.md index c2295e3..2d08959 100644 --- a/Cisco3550/README.md +++ b/Cisco3550/README.md @@ -4,7 +4,7 @@ python -m pip install -r requirements.txt
or
pip install -r requirements.txt
-to reset a 3550 to write erased state bypassing a password, ensure the serial cable is plugged into the serial port on the 2911 and the COM is correct in reset.py -then run -python reset.py -and power cycle the 3550 and hold the mode button \ No newline at end of file +to reset a 3550 to write erased state bypassing a password, ensure the serial cable is plugged into the serial port on the 2911 and the COM is correct in reset.py
+then run
+python reset.py
+and power cycle the 3550 and hold the mode button
\ No newline at end of file From 751ea3193f7dfe95d9f1dd12a727c6a9021ade7d Mon Sep 17 00:00:00 2001 From: koalatea Date: Tue, 26 Sep 2017 15:56:23 -0400 Subject: [PATCH 5/5] edited 3550 readme --- Cisco3550/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cisco3550/README.md b/Cisco3550/README.md index 2d08959..cea0916 100644 --- a/Cisco3550/README.md +++ b/Cisco3550/README.md @@ -4,7 +4,7 @@ python -m pip install -r requirements.txt
or
pip install -r requirements.txt
-to reset a 3550 to write erased state bypassing a password, ensure the serial cable is plugged into the serial port on the 2911 and the COM is correct in reset.py
+to reset a 3550 to write erased state bypassing a password, ensure the serial cable is plugged into the serial port on the 3550 and the COM is correct in reset.py
then run
python reset.py
and power cycle the 3550 and hold the mode button
\ No newline at end of file