Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/python
- import colorama
- import paramiko
- import time
- import ipaddr
- import os
- import socket
- import getpass
- import thread
- #import csv
- from colorama import Fore, Back, Style
- from threading import *
- def disable_paging(remote_conn):
- '''Disable paging on a Cisco router'''
- remote_conn.send("terminal length 0\n")
- time.sleep(1)
- # Clear the buffer on the screen
- output = remote_conn.recv(1000)
- return output
- def payload (file,docnoconnect,username,password,enable,cmd,cmd2):
- #acquire screenclock
- # Static variable for loop
- count = 1
- #begin output for user
- screenLock.acquire()
- print "[+] Current IP Address: %s" % ip
- screenLock.release()
- # Create instance of SSHClient object
- remote_conn_pre = paramiko.SSHClient()
- # Automatically add untrusted hosts (make sure okay for security policy in your environment)
- remote_conn_pre.set_missing_host_key_policy(
- paramiko.AutoAddPolicy())
- # initiate SSH connectioni
- screenLock.acquire()
- print "[+] Establishing SSH Connection to %s" % ip
- screenLock.release()
- # exectute the ssh connection with exception management
- try:
- remote_conn_pre.connect(ip, username=username, password=password, timeout=2)
- except paramiko.SSHException, e:
- screenLock.acquire()
- print (Fore.RED + "[-] Password is not valid!"),
- print(Fore.RESET + Back.RESET + Style.RESET_ALL)
- screenLock.release()
- return
- except paramiko.AuthenticationException:
- screenLock.acquire()
- print (Fore.RED + "[-] Authentication failed for some reason!"),
- print(Fore.RESET + Back.RESET + Style.RESET_ALL)
- screeLock.Release()
- return
- except socket.error, e:
- screenLock.acquire()
- print (Fore.RED + "[-] Socket connection failed on %s:" % ip),
- print(Fore.RESET + Back.RESET + Style.RESET_ALL)
- screenLock.release()
- count = count + 1
- if docnoconnect in ['y', 'Y' , "yes" , "Yes" , "YES"]:
- f.write("\n")
- f.write("***************")
- f.write("Unable to contact host @ ")
- f.write(ip)
- f.write("***************")
- f.write("\n")
- return
- # SSH established
- screenLock.acquire()
- print "[+] SSH connection established to %s" % ip
- screenLock.release()
- # Use invoke_shell to establish an 'interactive session'
- remote_conn = remote_conn_pre.invoke_shell()
- screenLock.acquire()
- print "[+] Interactive SSH session established"
- screenLock.release()
- # Strip the initial router prompt
- output = remote_conn.recv(1000)
- # Turn off paging
- disable_paging(remote_conn)
- # Send enable command and wait a bit
- remote_conn.send("\n")
- remote_conn.send("enable\n")
- time.sleep(.25)
- output = remote_conn.recv(5000)
- # send enable password
- remote_conn.send(enable)
- remote_conn.send("\n")
- output = remote_conn.recv(5000)
- time.sleep(.25)
- # send the first command line
- screenLock.acquire()
- print "[+] Transmitting command: # %s" % cmd,
- print "to target:%s" % ip
- screenLock.release()
- remote_conn.send(cmd)
- remote_conn.send("\n")
- output = remote_conn.recv(1000)
- # send the second command line
- time.sleep(.25)
- screenLock.acquire()
- print "[+] Transmitting command: # %s" % cmd2,
- print "to target:%s" % ip
- screenLock.release()
- remote_conn.send(cmd2)
- remote_conn.send("\n")
- # Wait for the command to complete
- time.sleep(1)
- output = remote_conn.recv(5000)
- # output and convert to strings for file writing
- # print output
- outputs = str(output)
- ipconvs = str(ip)
- f.write("\n")
- f.write(ipconvs)
- f.write("\n")
- f.write(outputs)
- f.write("\n")
- f.write("\n")
- f.write("**************************************************************\n")
- # sleep just for display remove when only concerned with file writing
- # time.sleep(2)
- def fireatwill():
- for line in fileIN:
- ip = str(line.strip())
- payload (ip,docnoconnect,username,password,enable,cmd,cmd2)
- # Increment counter and increment ip address for scanning
- #count = count + 1
- # ipconv = ipconv + incri
- if __name__ == '__main__':
- # VARIABLES
- os.system("clear")
- inputfile = raw_input("Enter the input file name [Press enter to use input.txt]: ")
- outputfile = raw_input("Enter the output file name [Press enter to use output.txt]: ")
- docnoconnect = raw_input("Do you want to document hosts that don't conenct? ")
- username = raw_input("Username? ")
- password = getpass.getpass("Password? ")
- enable = getpass.getpass("Enable Password? ")
- cmd = raw_input("Enter the first cisco command to execute: #")
- cmd2 = raw_input("Enter the second cisco command to execute: #")
- # semaphore for threading output
- screenLock = Semaphore(value=1)
- if len (inputfile) < 1:
- inputfile = "inputfile.txt"
- if len (outputfile) < 1:
- outputfile = "outputfile.txt"
- f = open(outputfile, 'w')
- #open the input file
- fileIN = open(inputfile, "r")
- #Start the loop based on input file
- for line in fileIN:
- thread.start_new_thread(fireatwill,())
- # thread.start_new_thread(fireatwill,())
- fileIN.close()
- Enter the second cisco command to execute: #
- Unhandled exception in thread started by <function fireatwill at 0x7f577956e398>Unhandled exception in thread started by <function fireatwill at 0x7f577956e398>Unhandled exception in thread started by <function fireatwill at 0x7f577956e398>Unhandled exception in thread started by <function fireatwill at 0x7f577956e398>Unhandled exception in thread started by <function fireatwill at 0x7f577956e398>
- Traceback (most recent call last):
- Traceback (most recent call last):
- Traceback (most recent call last):
- Traceback (most recent call last):
- File "./ciscorev30.py", line 139, in fireatwill
- File "./ciscorev30.py", line 139, in fireatwill
- Traceback (most recent call last):
- File "./ciscorev30.py", line 139, in fireatwill
- for line in fileIN:
- File "./ciscorev30.py", line 139, in fireatwill
- File "./ciscorev30.py", line 139, in fireatwill
- for line in fileIN:
- TypeError: 'NoneType' object is not iterable
- for line in fileIN:
- TypeError: 'NoneType' object is not iterable
- for line in fileIN:
- TypeError: 'NoneType' object is not iterable
- for line in fileIN:
- TypeError: 'NoneType' object is not iterable
- TypeError: 'NoneType' object is not iterable
- valdezd@valdezdub:~/Development$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement