├── Config ├── startingAccountsExamples ├── NewPasswords ├── NewPasswordsExamples ├── NewUsers ├── startingAccounts └── NewUsersExamples ├── p.png ├── encoder.jar ├── Plans ├── Linux1MinPlan.sh └── turnoff.ps1 ├── LICENSE ├── Co.py ├── Interpreter.py ├── loader.py ├── README.md └── BlueDucky.py /Config/startingAccountsExamples: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /p.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/M507/BlueDucky/HEAD/p.png -------------------------------------------------------------------------------- /Config/NewPasswords: -------------------------------------------------------------------------------- 1 | Win:THISisTHEnewPASSWORD 2 | Linux:UPDATEDpassword -------------------------------------------------------------------------------- /encoder.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/M507/BlueDucky/HEAD/encoder.jar -------------------------------------------------------------------------------- /Config/NewPasswordsExamples: -------------------------------------------------------------------------------- 1 | OS: 2 | 3 | Example: 4 | Win:password123 5 | Linux:123password -------------------------------------------------------------------------------- /Plans/Linux1MinPlan.sh: -------------------------------------------------------------------------------- 1 | echo 'Customized script' >> /tmp/BlueDucky.execution 2 | echo ':)' >> /tmp/BlueDucky.execution -------------------------------------------------------------------------------- /Config/NewUsers: -------------------------------------------------------------------------------- 1 | Win:Admin123:MyPasswordIs123456:1 2 | Win:user1:123456:0 3 | Linux:Admin:Password123456:1 4 | Linux:user1:123456:0 -------------------------------------------------------------------------------- /Config/startingAccounts: -------------------------------------------------------------------------------- 1 | Win:admin:10.1.2.1:CCDCsucks123# 2 | Win:admin:10.1.2.5:CCDCsucks123# 3 | Win:admin:10.1.2.10:CCDCsucks123# 4 | Win:dnsUser:10.1.2.202:CCDCsucks123# 5 | Linux:root:10.2.2.2:Admin123# 6 | Linux:dnsadmin:10.2.2.202:Admin123# -------------------------------------------------------------------------------- /Config/NewUsersExamples: -------------------------------------------------------------------------------- 1 | OS:username:password:admin/regular 2 | 3 | 4 | # Example: 5 | # In every windows server the user Admin123 will be created 6 | # With this password MyPasswordIs123456 and it will be an Admin. 7 | Win:Admin123:MyPasswordIs123456:1 8 | 9 | # In this case, In every windows server the user intern01 10 | # will be created With this password 1234567890 11 | # and it will NOTbe an Admin. 12 | Win:intern01:1234567890:0 13 | 14 | # In this case, the username is admin with toor as its password 15 | # and it will be added to sudo group. 16 | Linux:admin:toor:1 17 | 18 | 19 | 20 | #You know the drill -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Mohammed 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Co.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | import os.path 3 | 4 | 5 | """ 6 | Stylish input() 7 | """ 8 | def s_input(string): 9 | return input(string+">").strip("\n") 10 | 11 | 12 | """ 13 | Execute command locally 14 | """ 15 | def execute_command(command): 16 | if len(command) > 0: 17 | print(command) 18 | proc = subprocess.Popen(command.split(" "), stdout=subprocess.PIPE) 19 | return proc 20 | 21 | """ 22 | Get all subdirectories of a directory. 23 | """ 24 | def getSubs(dirname): 25 | print("getSubs") 26 | dirs = [d for d in os.listdir(dirname) if os.path.isdir(os.path.join(dirname, d))] 27 | # subdirectories = [dirname + "/" + subDirName for subDirName in subdirectories] 28 | subdirectories = [] 29 | for dir in dirs: 30 | subdirectories.append(dirname + '/' + dir) 31 | return subdirectories 32 | 33 | """ 34 | Get all files of a directory. 35 | """ 36 | def getFiles(dirname): 37 | return [f for f in os.listdir(dirname) if os.path.isfile(os.path.join(dirname, f))] 38 | 39 | 40 | """ 41 | Rocket science 42 | """ 43 | def answer(string): 44 | a = input(string) 45 | if a == "Y" or a == 'y' or a == 'Yes' or a == 'yes': 46 | return True 47 | else: 48 | return False 49 | 50 | """ 51 | Rocket science 52 | """ 53 | def answerExit(string): 54 | if string == "exit" or string == "Exit" or string == "q" or string == "Q": 55 | return True 56 | else: 57 | return False 58 | 59 | -------------------------------------------------------------------------------- /Interpreter.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | def writeOpenPowershell(): 4 | string = "GUI r\n" \ 5 | "DELAY 50\n" \ 6 | "STRING powershell\n" \ 7 | "ENTER\n" \ 8 | "DELAY 300" 9 | return string 10 | 11 | def writeOpenCMD(): 12 | string = "GUI r\n" \ 13 | "DELAY 50\n" \ 14 | "STRING cmd\n" \ 15 | "ENTER\n" \ 16 | "DELAY 300" 17 | return string 18 | 19 | def writeLogin(username,ip,password): 20 | string = "STRING ssh "+username+"@"+ip+"\n" \ 21 | "ENTER\n" \ 22 | "DELAY 500\n" \ 23 | "STRING "+password+"\n" \ 24 | "ENTER\n" \ 25 | "DELAY 500" 26 | 27 | return string 28 | 29 | def writeCommands(script): 30 | string = "STRING "+script+"\n"\ 31 | "ENTER\n"\ 32 | "DELAY 300" 33 | return string 34 | 35 | def changePasswordHelper(OS,user, password): 36 | string = "" 37 | if OS == "Win": 38 | string = "STRING net user "+user+" "+ password +"\n" \ 39 | "ENTER\n"\ 40 | "DELAY 300" 41 | elif OS == "Linux": 42 | string = "STRING passwd\n" \ 43 | "ENTER\n" \ 44 | "DELAY 300\n"\ 45 | "STRING " + password + "\n" \ 46 | "ENTER\n" \ 47 | "DELAY 300\n" \ 48 | "STRING " + password +" \n" \ 49 | "ENTER\n" \ 50 | "DELAY 300" 51 | else: 52 | print("Unknown OS - changePasswordHelper(OS,user, password)") 53 | exit(-1) 54 | return string -------------------------------------------------------------------------------- /loader.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | This function reads Config/NewPasswords file, 4 | and based on that file, all the password will 5 | be changed to the specified parameters accordingly. 6 | """ 7 | def readNewPassword(): 8 | # Win:password123 9 | aList = [] 10 | try: 11 | for line in open("Config/NewPasswords"): 12 | line = line.split(':') 13 | OS = line[0].strip('\n') 14 | password = line[1].strip('\n') 15 | aList.append([OS, password]) 16 | except Exception as e: 17 | print("Error at readNewPassword()") 18 | print(e) 19 | 20 | return aList 21 | 22 | """ 23 | This function reads Config/NewPasswords which should have all 24 | The inputs for the new users. 25 | """ 26 | def readNewUsers(): 27 | # Win:Admin123:MyPasswordIs123456:1 28 | aList = [] 29 | try: 30 | for line in open("Config/NewUsers"): 31 | line = line.split(':') 32 | OS = line[0] 33 | username = line[1].strip('\n') 34 | password = line[2].strip('\n') 35 | admin = line[3].strip('\n') 36 | aList.append([OS, username, password, admin]) 37 | except Exception as e: 38 | print("Error at readNewUsers()") 39 | print(e) 40 | return aList 41 | 42 | 43 | def readCurrentUsers(): 44 | # Win:admin:10.1.2.1:CCDCsucks123# 45 | aList = [] 46 | try: 47 | for line in open("Config/startingAccounts"): 48 | line = line.split(':') 49 | OS = line[0].strip('\n') 50 | username = line[1].strip('\n') 51 | ip = line[2].strip('\n') 52 | password = line[3].strip('\n') 53 | aList.append([OS, username, ip, password]) 54 | except Exception as e: 55 | print("Error at readCurrentUsers()") 56 | print(e) 57 | 58 | return aList 59 | 60 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BlueDucky 2 | ![logo](https://github.com/M507/BlueDucky/raw/master/p.png) 3 | 4 | ### BlueDucky is a blue-team tool. It generates a list of USB-Rubber-Ducky instructions. 5 | 6 | 7 | The idea behind this tool is to create different payloads for each member as fast as possible. Each member of the team will have a USB-Rubber-Ducky. Each member will be responsible of setting up different boxes. Here where the tool comes handy, the team can make a customized USB-Rubber-Ducky payload for each member. Payloads that run PowerShell and SSH into each box and execute a list of instructions for each box and making payloads will not take more than a minute before the competition. 8 | 9 | 10 | The goal is to design the fastest incident response plan, which should include: 11 | - Changing every user's password in every box. 12 | - Executing customized scripts to setup firewall rules, setup up new users, clean cronjobs/scheduled task... you know the drill ... 13 | 14 | ### Setup 15 | ```sh 16 | $ git clone https://github.com/M507/BlueDucky.git 17 | $ cd BlueDucky 18 | $ python3 BlueDucky.py 19 | $ # Follow the instructions 20 | .. 21 | .. 22 | Saving .. 23 | Enter filename > output.txt 24 | $ java -jar duckencode.jar -i output.txt -o inject.bin 25 | $ cp inject.bin // 26 | ``` 27 | 28 | ### Configuration 29 | - All scrpits/plans must be in Config/ 30 | - Windows scrpits/plans must have .ps1 extension 31 | - Linux scrpits/plans must have .sh extension 32 | - BlueDucky/Config/startingAccounts file is where the default credentials should be. 33 | ``` 34 | Win:admin:10.1.2.1:CCDCsucks123# 35 | Win:admin:10.1.2.5:CCDCsucks123# 36 | Win:admin:10.1.2.10:CCDCsucks123# 37 | Win:dnsUser:10.1.2.202:CCDCsucks123# 38 | Linux:root:10.2.2.2:Admin123# 39 | Linux:dnsadmin:10.2.2.202:Admin123# 40 | ``` 41 | - BlueDucky/Config/NewPasswords file must have two inputs, one for Windows users, and the other one for Linux: 42 | ``` 43 | Win:THISisTHEnewPASSWORD 44 | Linux:UPDATEDpassword 45 | ``` 46 | - BlueDucky changes all passwords to what is in Config/NewPasswords file. 47 | 48 | - BlueDucky/Config/NewUsers file is where the backup users shoud be, they will be created after chaning the password for the default users. 49 | ``` 50 | Win:Admin123:MyPasswordIs123456:1 51 | Win:user1:123456:0 52 | Linux:Admin:Password123456:1 53 | Linux:user1:123456:0 54 | ``` 55 | - BlueDucky/Plans directory is where the firewall/anyscrpit scrpts should be. 56 | 57 | ### Requirements 58 | 59 | - python3 60 | - java 61 | 62 | ---- 63 | github.com/M507 64 | -------------------------------------------------------------------------------- /Plans/turnoff.ps1: -------------------------------------------------------------------------------- 1 | # 2 | # This script does simple things but oh so well :) 3 | # @Author: Mr.Rebel 4 | # 5 | # Get Box Name run as ./turnoff.ps1 box_name (LOWERCASE!!!!) 6 | #Set-ExecutionPolicy RemoteSigned 7 | #./MpCmdRun.exe -Scan -ScanType 2 8 | #https://docs.microsoft.com/en-us/windows/security/threat-protection/windows-defender-antivirus/command-line-arguments-windows-defender-antivirus 9 | 10 | param( 11 | [Parameter(Mandatory = $True,valueFromPipeline=$true)][String] $box 12 | ) 13 | 14 | echo "*************************************" 15 | echo "RUNNING FOR BOX: $box" 16 | echo "*************************************" 17 | 18 | function build_wall{ 19 | echo "Putting old rules into rules.txt!!!!" 20 | Get-NetFirewallRule | Out-File -FilePath .\rules.txt -NoClobber 21 | echo "Restoring firewall rules to default" 22 | netsh advfirewall reset 23 | netsh advfirewall set allprofiles state on 24 | netsh advfirewall firewall delete rule name=all 25 | netsh advfirewall set allprofiles firewallpolicy blockinbound,blockoutbound 26 | #Remove-NetFirewallRule -All 27 | echo "*****************************" 28 | echo "BUILDING WALL" 29 | echo "*****************************" 30 | for($num = 21; $num -lt 2000; $num++){ 31 | #depending on box we don't want to block certain ports 32 | if($num -eq 80 -OR $num -eq 443 -OR $num -eq 53 -OR $num -eq 514){ 33 | continue 34 | } 35 | if(($num -eq 22 -OR $num -eq 23) -AND $box -eq "Bonaparte"){ 36 | continue 37 | } 38 | if(($num -eq 67 -OR $num -eq 68) -AND $box -eq "Sulleyman"){ 39 | continue 40 | } 41 | if(($num -eq 25 -OR $num -eq 143 -OR $num -eq 993 -OR $num -eq 465 -OR $num -eq 110) -AND $box -eq "Xerxes" ){ 42 | continue 43 | } 44 | if(($num -eq 636 -OR $num -eq 389 -OR $num -eq 88 -OR $num -eq 445) -AND $box -eq "Alexander"){ 45 | continue 46 | } 47 | if(($num -eq 21 -OR $num -eq 445 -OR $num -eq 139 -OR $num -eq 123 -OR $num -eq 42) -AND $box -eq "Julius"){ 48 | continue 49 | } 50 | echo "Blocking port + $num" 51 | echo "Blocking TCP" 52 | netsh advfirewall firewall add rule name="Blocktcp_in + $num" protocol=TCP dir=in localport=$num action=block 53 | netsh advfirewall firewall add rule name="Blocktcp_out + $num" protocol=TCP dir=out localport=$num action=block 54 | echo "Blocking UDP" 55 | netsh advfirewall firewall add rule name="Blocktcp_in + $num" protocol=UDP dir=in localport=$num action=block 56 | netsh advfirewall firewall add rule name="Blocktcp_out + $num" protocol=UDP dir=out localport=$num action=block 57 | } 58 | 59 | # Sleep for 180 seconds before running again 60 | #Start-Sleep -s 180 61 | } 62 | 63 | function stop_process{ 64 | $tasklist = tasklist.exe 65 | $tasklist = $tasklist.Split(" ") 66 | $truetaskList = @() 67 | 68 | ForEach($task in $tasklist){ 69 | if (($task -match '.exe' -OR -$task -match '.py' -OR $task -match '.ps1') -and -Not($truetaskList.Contains($task)) -and -Not($task -match 'powershell')){ 70 | $truetaskList += $task 71 | } 72 | } 73 | 74 | ForEach($task in $truetaskList){ 75 | Try{ 76 | $truetask = $task.Substring(0,$task.Length-4) 77 | if($truetask -eq "powershell.exe" -OR $truetask -eq "turnoff.ps1"){ 78 | continue 79 | } 80 | echo "Stopping: $truetask" 81 | Stop-Process -Name $truetask 82 | } 83 | Catch{ 84 | continue 85 | } 86 | } 87 | } 88 | 89 | function change_users{ 90 | $Accounts = Get-WmiObject -Class Win32_UserAccount -filter "LocalAccount = True" 91 | $ListUsers = @() 92 | $currentuser = $env:USERNAME 93 | $Accounts = $Accounts -split ' ' 94 | ForEach($account in $Accounts){ 95 | $stringAccount = [string]$account -split '"' 96 | for($i = 0; $i -lt $stringAccount.Count; $i+=1){ 97 | if ($i -eq 3){ 98 | $user = $stringAccount[$i] 99 | $ListUsers += $user 100 | } 101 | } 102 | } 103 | #Disable-LocalUser -Name $username 104 | $Password = (ConvertTo-SecureString -AsPlainText "TenToesDownForLife$10!" -Force) 105 | ForEach($user in $ListUsers){ 106 | Try{ 107 | echo "Changing password for User: $user" 108 | $User | Set-LocalUser -Password $Password 109 | echo "Successfully changed password for $User" 110 | } 111 | Catch{ 112 | $string_err = $_ | Out-String 113 | echo $string_err 114 | continue 115 | } 116 | } 117 | } 118 | 119 | function scan{ 120 | echo "Starting quick scan!!!!!!!" 121 | Try{ 122 | Set-MpPreference -ScanParameters 2 -ScanScheduleDay 0 -ScanScheduleQuickScanTime 1 -UnknownThreatDefaultAction "Quarantine" -SevereThreatDefaultAction "Quarantine" -HighThreatDefaultAction "Quarantine" -LowThreatDefaultAction "Quarantine" -ModerateThreatDefaultAction "Quarantine" -CheckForSignaturesBeforeRunningScan 1 -DisableRealtimeMonitoring 0 123 | Start-MpScan -ThrottleLimit 0 -ScanType 1 124 | echo "Sleeping for 30 seconds then running full scan!" 125 | Start-Sleep 30 126 | Start-MpScan -ThrottleLimit 0 -ScanType 2 127 | } 128 | Catch{ 129 | Try{ 130 | C:\"Program Files"\"Windows Defender"\MpCmdRun.exe -Scan -ScanType 1 131 | echo "Sleeping for 60 seconds then running full scan!" 132 | Start-Sleep 30 133 | C:\"Program Files"\"Windows Defender"\MpCmdRun.exe -Scan -ScanType 2 134 | } 135 | Catch{ 136 | $string_err = $_ | Out-String 137 | echo $string_err 138 | } 139 | } 140 | } 141 | 142 | function main{ 143 | Clear 144 | #$UserAccount = Get-LocalUser -Name "Administrator" 145 | if (-not($box -eq "Julius")){ 146 | # Disable SMB if not scored service! 147 | Try{ 148 | echo "Disabling SMB1" 149 | Disable-WindowsOptionalFeature -Online -FeatureName 'SMB1Protocol' -ErrorAction SilentlyContinue -WarningAction SilentlyContinue -NoRestart | Out-Null 150 | echo "Disabling SMB2" 151 | if(-not($box -eq "Alexander")){ 152 | Set-SmbServerConfiguration -EnableSMB2Protocol $false 153 | echo "Disabling SMB3" 154 | Set-SmbServerConfiguration -EnableSMB3Protocol $false 155 | } 156 | Catch{ 157 | $string_err = $_ | Out-String 158 | echo $string_err 159 | } 160 | } 161 | echo "Disabling RDP!!!" 162 | if((-not($box -eq "Alexander") -AND (-not($box -eq "Bonaparte")))){ 163 | try{ 164 | Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\Terminal Server" -Name "fDenyTSConnections" -Value 0 165 | echo "RDP Disabled" 166 | } 167 | Catch{ 168 | $string_err = $_ | Out-String 169 | echo $string_err 170 | } 171 | } 172 | # set mp preferences 173 | # set environment policy and rerun script!!! 174 | echo "Setting lockdown policy" 175 | Try{ 176 | [Environment]::SetEnvironmentVariable('__PSLockdownPolicy', '4', 'Machine') 177 | } 178 | Catch{ 179 | $string_err = $_ | Out-String 180 | echo $string_err 181 | } 182 | change_users 183 | #stop_process 184 | build_wall 185 | scan 186 | } 187 | 188 | main -------------------------------------------------------------------------------- /BlueDucky.py: -------------------------------------------------------------------------------- 1 | from Co import * 2 | from loader import * 3 | from Interpreter import * 4 | 5 | 6 | """ 7 | Foe every "user" in starting accounts: 8 | Change the "user"'s password according to the OS type. 9 | """ 10 | def changeAllPasswords(stringsList,readCurrentUsersList,readNewPasswordList): 11 | accounts = [] 12 | for user in readCurrentUsersList: 13 | readCurrentUsersList_OS = user[0] 14 | username = user[1] 15 | ip = user[2] 16 | oldPassword = user[3] 17 | for line in readNewPasswordList: 18 | readNewPasswordList_OS = line[0] 19 | newPassword = line[1] 20 | if readCurrentUsersList_OS == readNewPasswordList_OS: 21 | # login 22 | l = writeLogin(username,ip,oldPassword) 23 | stringsList.append(l) 24 | l = changePasswordHelper(readNewPasswordList_OS,username, newPassword) 25 | stringsList.append(l) 26 | l = writeCommands("exit") 27 | stringsList.append(l) 28 | accounts.append([username,ip,newPassword,readNewPasswordList_OS]) 29 | return stringsList, accounts 30 | 31 | """ 32 | For each account in "accounts" list: 33 | -> Login into ssh 34 | -> Execute commands 35 | -> Exit 36 | """ 37 | def forEachAccount(mainList,accounts,commands): 38 | # [username,ip,newPassword,os] 39 | for account in accounts: 40 | username = account[0] 41 | ip = account[1] 42 | newPassword = account[2] 43 | l = writeLogin(username, ip, newPassword) 44 | mainList.append(l) 45 | l = writeCommands(commands) 46 | mainList.append(l) 47 | l = writeCommands("exit") 48 | mainList.append(l) 49 | return mainList 50 | 51 | 52 | """ 53 | Create backup users 54 | """ 55 | def addUsers(mainList, accounts): 56 | # [OS, username, password, admin] 57 | # Win:Admin123:MyPasswordIs123456:1 58 | readNewUsersList = readNewUsers() 59 | 60 | # [username,ip,newPassword,os] 61 | for account in accounts: 62 | # [OS, username, password, admin] 63 | for newUser in readNewUsersList: 64 | OS1 = newUser[0] 65 | newUserUsername = newUser[1] 66 | password = newUser[2] 67 | admin = newUser[3] 68 | 69 | username = account[0] 70 | ip = account[1] 71 | currentPassword = account[2] 72 | OS2 = account[3] 73 | 74 | # If the OS is Windows 75 | print(OS1,OS2) 76 | if OS1 == "Win" and OS2 == "Win": 77 | 78 | # Login first 79 | l = writeLogin(username, ip, currentPassword) 80 | mainList.append(l) 81 | 82 | # Create the new user 83 | command = "net user /add " + newUserUsername + " " + password 84 | l = writeCommands(command) 85 | mainList.append(l) 86 | 87 | # If admin - add it to the admins group 88 | if admin: 89 | command = "new localgroup administrators "+newUserUsername+" /add" 90 | l = writeCommands(command) 91 | mainList.append(l) 92 | 93 | # Logout 94 | l = writeCommands("exit") 95 | mainList.append(l) 96 | 97 | elif OS1 == "Linux" and OS2 == "Linux": 98 | 99 | # Login first 100 | l = writeLogin(username, ip, currentPassword) 101 | mainList.append(l) 102 | 103 | # Create the new user 104 | command = "adduser " + newUserUsername 105 | l = writeCommands(command) 106 | """ 107 | Enter new UNIX password: 108 | Retype new UNIX password: 109 | passwd: password updated successfully 110 | """ 111 | mainList.append(l) 112 | command = password 113 | l = writeCommands(command) 114 | mainList.append(l) 115 | command = password 116 | l = writeCommands(command) 117 | mainList.append(l) 118 | 119 | # If admin - add it to the admins group 120 | if admin: 121 | command = "usermod -aG sudo " + newUserUsername + " /add" 122 | l = writeCommands(command) 123 | mainList.append(l) 124 | command = currentPassword 125 | l = writeCommands(command) 126 | mainList.append(l) 127 | 128 | # Logout 129 | l = writeCommands("exit") 130 | mainList.append(l) 131 | else: 132 | pass 133 | 134 | return mainList 135 | 136 | def setupPlans(): 137 | plans = [] 138 | print("List all plans:") 139 | for dir in getFiles("Plans"): 140 | print(" "+dir) 141 | while 1: 142 | inputs = s_input("Which script would you like to run? or q to exit") 143 | if answerExit(inputs): 144 | break 145 | if os.path.isfile("Plans/"+inputs): 146 | plans.append("Plans/"+inputs) 147 | 148 | print("List of the scripts that will compile:") 149 | for script in plans: 150 | print(" " + script) 151 | 152 | print("The final list:") 153 | for script in plans: 154 | print(" " + script) 155 | return plans 156 | 157 | def executePlans(mainList, plans, accounts): 158 | for plan in plans: 159 | with open(plan, 'r') as f: 160 | output = f.read() 161 | # replace every \n by ; 162 | # since the compiler can not interpret newlines 163 | output = output.replace('\n', ';') 164 | 165 | # For each account in the "accounts" list 166 | for account in accounts: 167 | # [username,ip,newPassword,readNewPasswordList_OS] 168 | username = account[0] 169 | ip = account[1] 170 | currentPassword = account[2] 171 | OS = account[3] 172 | 173 | # If this account is Win, and the plan for windows (.ps1), then true 174 | if OS == "Win" and plan[-2:] == "s1": 175 | # Login first 176 | l = writeLogin(username, ip, currentPassword) 177 | mainList.append(l) 178 | 179 | # Add the plan 180 | command = output 181 | l = writeCommands(command) 182 | mainList.append(l) 183 | 184 | elif OS == "Linux" and plan[-2:] == "sh": 185 | # Login first 186 | l = writeLogin(username, ip, currentPassword) 187 | mainList.append(l) 188 | 189 | # Add the plan 190 | command = output 191 | l = writeCommands(command) 192 | mainList.append(l) 193 | else: 194 | pass 195 | return mainList 196 | 197 | def printList(mainList): 198 | for command in mainList: 199 | print(command) 200 | 201 | 202 | 203 | def setup(): 204 | s_input("Press any key to start..") 205 | print("Loading config files ..") 206 | # [OS, password] 207 | # Win:password123 208 | readNewPasswordList = readNewPassword() 209 | # [OS, username, ip, password] 210 | # Win:admin:10.1.2.1:CCDCsucks123# 211 | readCurrentUsersList = readCurrentUsers() 212 | 213 | 214 | # Start making the main list 215 | # Update the passwords 216 | # And make a list of the active accounts (accounts=[]) 217 | mainList = [] 218 | accounts = [] 219 | if answer("Do you want to change all the users' passwords?"): 220 | 221 | print("writing all the new passwords.. ", end='') 222 | # Open Powershell, change all passwords 223 | mainList.append(writeOpenPowershell()) 224 | mainList, accounts = changeAllPasswords(mainList, readCurrentUsersList, readNewPasswordList) 225 | print("Done") 226 | 227 | 228 | # Start making the plans list 229 | # Execute the plans accoring to the type of each account 230 | plans = [] 231 | if answer("Do you want to use the 'plans' scripts?"): 232 | plans = setupPlans() 233 | mainList = executePlans(mainList, plans, accounts) 234 | 235 | 236 | if answer("Do you want to create new users from Config/NewUsers?"): 237 | mainList = addUsers(mainList, accounts) 238 | 239 | return mainList, plans 240 | 241 | def saveList(mainList): 242 | print("Saving ..") 243 | filename = s_input("Enter filename") 244 | f = open(filename, 'w') 245 | for command in mainList: 246 | f.write(command) 247 | 248 | def start(): 249 | # Setup 250 | mainList, plans = setup() 251 | printList(mainList) 252 | saveList(mainList) 253 | 254 | 255 | def main(): 256 | start() 257 | pass 258 | 259 | if __name__ == '__main__': 260 | main() 261 | 262 | --------------------------------------------------------------------------------