-
Notifications
You must be signed in to change notification settings - Fork 0
/
SYS-BUILD.ADMIN.ACCOUNTS.py
67 lines (67 loc) · 3.38 KB
/
SYS-BUILD.ADMIN.ACCOUNTS.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
#--!/usr/bin/env python3
#-- -*- coding: Latin-1 -*-
#--
#-- ************************************************************************************************************:
#-- *************************************** CREATE LOCAL ADMIN ACCOUNTS ****************************************:
#-- ************************************************************************************************************:
#-- Author: JBALLARD (JEB) :
#-- Date: 2023.6.15 :
#-- Script: SYS-BUILD.ADMIN.ACCOUNTS.py :
#-- Purpose: A python script that remotely creates Local Admin Accounts on usr specific Systems. :
#-- Class: python -m pip install paramiko :
#-- Version: 1.0 :
#-- ************************************************************************************************************:
#-- ************************************************************************************************************:
#--
#-- ********************************************************:
#-- DEFINE PARAMS, CONSTANTS, CONFIG PATHS, CLASSES, & LIBS :
#-- ********************************************************:
import paramiko
#--
def BLD_LOC_ADMIN_Act(hostname, username, password, new_username, new_password):
try:
#-- CONNECT TO REMOTE SYS:
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname, username=username, password=password)
#--
#-- BUILD NEW LOCAL ADMIN ACT:
command = f"net user {new_username} {new_password} /add"
stdin, stdout, stderr = client.exec_command(command)
#--
#-- VERIFY SUCCESSFUL ACT CREATION:
if "The command completed successfully" in stdout.read().decode():
print(f"NOTE - SUCCESSFULLY CREATED LOCAL ADMIN ACCOUNT FOR {new_username} ON {hostname}:")
else:
print(f"ERROR - FAILED TO CREATE LOCAL ADMIN ACCOUNT ON {hostname}:")
#--
#-- CLOSE SSH CONNECTION:
client.close()
except Exception as e:
print(f"ERROR - FAILED TO CREATE LOCAL ADMIN ACCOUNT ON {hostname}: {str(e)}")
#--
#-- DEFINE LIST OF DESIRED SYSTEMS TO CREATE LOCAL ACTS ON:
systems = [
{
"hostname": "SYSLP1.JBHOME.com",
"username": "JBallard",
"password": "NevrGuessPW@1",
"new_username": "JBallardAdmin",
"new_password": "NevrGuessAdPW@1"
},
{
"hostname": "SYSLP2.JBHOME.com",
"username": "JBallard",
"password": "NevrGuessPW@1",
"new_username": "JBallardAdmin",
"new_password": "NevrGuessAdPW@1"
},
]
#--
#-- CREATE LOCAL ADMIN ACTS FOR EACH SYS:
for system in systems:
BLD_LOC_ADMIN_Act(system["hostname"], system["username"], system["password"], system["new_username"], system["new_password"])
#--
#-- ********************************************************:
#-- END OF PYTHON SCRIPT :
#-- ********************************************************: