-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssh_fw_password_change.py
74 lines (54 loc) · 2.06 KB
/
ssh_fw_password_change.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
# By James Wright - April 13, 2015
# Changes account password on Gaia OS
import paramiko
import sys
import getpass
match = 0
port = 22
login_fails=[]
hostsFile = raw_input("\n\n[?] Enter the file containing the IP address list to use: ")
username = raw_input("\n[?] Enter the username to login with: ")
password = getpass.getpass("\n[?] Enter the password for the '" + username + "' account:")
new_account= raw_input("\n\n[?] Now enter the account you are changing the password for.\nThis can be the same account as you log in with: ")
while (match < 1) :
if (match < 1) :
new_password = getpass.getpass("\n[?] Enter the new password for " + new_account + ": ")
verify_password = getpass.getpass("\n[?] Enter the same password again: ")
if (new_password == verify_password) :
print "[*] Passwords Match"
match = 1
else :
print "[!] Passwords do not match, try again..."
match = 0
command0 = "lock database override"
command1 = "set user " + new_account + " password"
with open(hostsFile, 'r') as f:
for hostname in f:
hostname = hostname.strip()
print("\nCurrently trying: " + hostname)
try:
if __name__ == "__main__":
paramiko.util.log_to_file('ssh_connections.log')
s = paramiko.SSHClient()
s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
s.connect(hostname, port, username, password)
print "[*] Getting configuration lock..."
stdin, stdout, stderr = s.exec_command(command0)
print "[*] Changing password for " + new_account + "..."
stdin, stdout, stderr = s.exec_command(command1)
stdin.write(new_password + "\n")
stdin.write(verify_password + "\n")
print stdout.read()
print "[*] Process for " + hostname + " complete"
s.close()
except:
print ("Connection or Authentication error\n")
login_fails.append(hostname)
continue
if not hostname:
continue
if fail_list:
print "\nCould not connect to these hosts. \nPlease verify the host name or IP address, and/or try manually:\n"
for each in fail_list:
print each