CyberPolice

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit d3e636fc8a41c059142d2200c5b0c7bec910fecc
parent addd44cfc1bae668595abdcb8c473008a7d5b428
Author: PlutoTank <qwolkensperg@gmail.com>
Date:   Tue, 26 Nov 2019 22:19:20 -0800

Starting User Mgmt Func

Diffstat:
RTools/strLen.cmd -> BatchScripts/strLen.cmd | 0
ABatchScripts/userMgmt.cmd | 5+++++
MCyberPolice.bat | 29++++++++++++++++++++++++-----
APowershellScripts/Get-BasicADObject.ps1 | 29+++++++++++++++++++++++++++++
MPowershellScripts/ManageUsersFromFile.ps1 | 35++++++++++++++++-------------------
MPowershellScripts/UserList.ps1 | 5++---
MUserManagementTest.bat | 7+++++--
7 files changed, 81 insertions(+), 29 deletions(-)

diff --git a/Tools/strLen.cmd b/BatchScripts/strLen.cmd diff --git a/BatchScripts/userMgmt.cmd b/BatchScripts/userMgmt.cmd @@ -0,0 +1,4 @@ +@echo off +Setlocal EnableDelayedExpansion + +Exit /b+ \ No newline at end of file diff --git a/CyberPolice.bat b/CyberPolice.bat @@ -2,7 +2,7 @@ SETLOCAL EnableDelayedExpansion -set functions=checkfiles services lsp backuplsp passwordPol audit lockout features +set functions=checkfiles services lsp backuplsp passwordPol audit lockout features userMgmtff for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do ( set "DEL=%%a" @@ -16,9 +16,11 @@ set output=%path%CyberPoliceOutput set powershellScriptPath=%path%PowershellScripts set configPath=%path%ConfigFiles set toolsPath=%path%Tools +set batchScripts=%path%BatchScripts set powershellPath=%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\powershell.exe set wmicPath=%SystemRoot%\System32\Wbem\wmic.exe +set net=%SystemRoot%\system32\net.exe set lgpo=%toolsPath%/LGPO.exe echo CYBER POLICE are making required directories... @@ -376,7 +378,27 @@ call:colorEcho 0a "CYBER POLICE are done finding bad Windows features" echo. goto:EOF -:userMgmt +:userMgmtff +%powershellPath% -ExecutionPolicy Bypass -File "%powershellScriptPath%/ManageUsersFromFile.ps1" +echo Finding current users... +set uOutDir = "%output%\ManagedUserOutput" +for /f "tokens=*" %%A in (%output%\users.txt) do ( + for /f "tokens=3 delims= " %%B in ('%net% user "%%A" ^| Find "active"') do set userStatus=%%B + if "!userStatus!"=="No" ( + call:colorEcho 0b "%%A" + call:colorEcho 07 " account is" + call:colorEcho 0b " Disabled" + echo. + ) else ( + call:colorEcho 0b "%%A" + call:colorEcho 07 " account is" + call:colorEcho 0b " Enabled" + echo. + ) + pause +) +pause +goto:EOF rem set user properties, set user passwords (use copy paste from README), add users (based on README), disable users (based on README), set user groups, disable admin and guest and rename :rdp @@ -395,9 +417,6 @@ sfc /verifyonly call:colorEcho 0a "CYBER POLICE are finally done" goto:EOF -:virusScan -rem run CYBER POLICE virus scan - :checkHosts rem back up and show HOSTS file then flush dns diff --git a/PowershellScripts/Get-BasicADObject.ps1 b/PowershellScripts/Get-BasicADObject.ps1 @@ -0,0 +1,29 @@ +Function Get-BasicADObject { + param + ( + [String]$Ldap = "dc=" + $env:USERDNSDOMAIN.replace(".", ",dc="), + [String]$Filter = "(&(objectCategory=person)(objectClass=user))" + ) + + if ($pscmdlet.ShouldProcess($Ldap, "Get information about AD Object")) { + $searcher = [adsisearcher]$Filter + + $Ldap = $Ldap.replace("LDAP://", "") + $searcher.SearchRoot = "LDAP://$Ldap" + $results = $searcher.FindAll() + + $ADObjects = @() + foreach ($result in $results) { + [Array]$propertiesList = $result.Properties.PropertyNames + $obj = New-Object PSObject + foreach ($property in $propertiesList) { + $obj | add-member -membertype noteproperty -name $property -value ([string]$result.Properties.Item($property)) + } + $ADObjects += $obj + } + + Return $ADObjects + } +} + + diff --git a/PowershellScripts/ManageUsersFromFile.ps1 b/PowershellScripts/ManageUsersFromFile.ps1 @@ -4,17 +4,18 @@ $path = Split-Path -parent $thispath $configpath = "$path/ConfigFiles" $output = Get-Content $path/CyberPoliceOutput/path.txt $userMgmtFilePath = "" +$accounts = Get-Wmiobject Win32_UserAccount -filter 'LocalAccount=TRUE' | select-object -expandproperty Name $rawAdminData = @() $rawUserData = @() $rawOtherData = @() -$admins =@() -$adminPasswords =@() -$users =@() +$admins = @() +$adminPasswords = @() +$users = @() function EditCheck { - (Get-Content $configpath/PasteUsersHere.txt) | ? {$_.trim() -ne "" } | Set-Content $configpath/PasteUsersHere.txt + (Get-Content $configpath/PasteUsersHere.txt) | ? { $_.trim() -ne "" } | Set-Content $configpath/PasteUsersHere.txt Write-Host "Getting contents of raw user data..." -ForegroundColor Yellow Write-Host "Start of print out." -ForegroundColor Gray foreach ($line in Get-Content $configpath/PasteUsersHere.txt) { @@ -22,7 +23,7 @@ function EditCheck { } Write-Host "End of print out." -ForegroundColor Gray Write-host "Would you like to change the contents of this file? (Default is No)" -ForegroundColor Yellow - $Readhost = Read-Host "[Y/N]: " + $Readhost = Read-Host "[Y/N]" Switch ($ReadHost) { Y { ChangeUserFile } N { BeginUserManagement } @@ -40,35 +41,34 @@ function ChangeUserFile { Write-Host "End of print out." -ForegroundColor Gray EditCheck } - function BeginUserManagement { $writeTo = "Other" Write-Host "CYBER POLICE are starting user management..." foreach ($line in Get-Content $userMgmtFilePath) { if ($line -like "*Authorized Users*") { - $writeTo ="User" + $writeTo = "User" } elseif ($line -like "*Authorized Administrators*") { $writeTo = "Admin" } Switch ($writeTo) { - User {$rawUserData = $rawUserData + $line} - Admin {$rawAdminData = $rawAdminData + $line} - Default {$rawOtherData = $rawOtherData + $line} + User { $rawUserData = $rawUserData + $line } + Admin { $rawAdminData = $rawAdminData + $line } + Default { $rawOtherData = $rawOtherData + $line } } } if ($rawOtherData.count -gt 0) { Write-Host "The CYBER POLICE found some extra data in PasteUsersHere.txt!" -ForegroundColor Red Write-Host "The file may have been created poorly or there was an error in editing!" -ForegroundColor Yellow Write-Host "Misc stuff found..." -ForegroundColor Gray - $first, $rawOtherData= $rawOtherData + $first, $rawOtherData = $rawOtherData foreach ($misc in $rawOtherData) { Write-Host $misc -ForegroundColor Cyan } Write-Host "End of misc stuff." -ForegroundColor Gray } Write-Host "Admins Found..." -ForegroundColor Gray - $first, $rawAdminData= $rawAdminData + $first, $rawAdminData = $rawAdminData foreach ($admin in $rawAdminData) { if ($admin -like "*password:*") { $password = $admin.split(":") @@ -79,8 +79,7 @@ function BeginUserManagement { $admins = $admins + $adminSplit[0] } } - for($i = 0; $i -lt $admins.count; $i++) - { + for ($i = 0; $i -lt $admins.count; $i++) { Add-Content $output\ManagedUserOutput\authAdmins.txt "$($admins[$i]):$($adminPasswords[$i])" Write-Host "Admin: " -ForegroundColor Gray -NoNewline Write-Host $admins[$i] -ForegroundColor Cyan -NoNewline @@ -90,14 +89,13 @@ function BeginUserManagement { Write-Host "End of admins found." -ForegroundColor Gray Write-Host "Users Found..." - $first, $rawUserData= $rawUserData + $first, $rawUserData = $rawUserData foreach ($user in $rawUserData) { $users = $users + $user Add-Content $output\ManagedUserOutput\authUsers.txt $user Write-Host $user -ForegroundColor Cyan } Write-Host "End of users found." -ForegroundColor Gray - Pause } if (!(Test-Path $configpath/PasteUsersHere.txt -PathType Leaf)) { @@ -109,6 +107,4 @@ if (!(Test-Path $configpath/PasteUsersHere.txt -PathType Leaf)) { $userMgmtFilePath = "$configpath/PasteUsersHere.txt" New-Item -path $output\ManagedUserOutput -name authAdmins.txt -type "file" -Force New-Item -path $output\ManagedUserOutput -name authUsers.txt -type "file" -Force -EditCheck - - +EditCheck+ \ No newline at end of file diff --git a/PowershellScripts/UserList.ps1 b/PowershellScripts/UserList.ps1 @@ -14,6 +14,6 @@ if (!(Test-Path "$path2/users.txt")) Clear-content "$path2\users.txt" foreach($l in $accounts){ - "User: $l" >> "$path2\users.txt"; + Add-Content -Path $path2\users.txt -Value $l -PassThru } -Write-Host "Users added to text file!" -ForegroundColor Yellow;- \ No newline at end of file +Write-Host "Users added to text file!" -ForegroundColor Yellow; diff --git a/UserManagementTest.bat b/UserManagementTest.bat @@ -3,5 +3,8 @@ set path=%~dp0 set usersFile=%path%ConfigFiles\PasteUsersHere.txt set powershellScript=%path%PowershellScripts\ManageUsersFromFile.ps1 set powershellPath=%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\powershell.exe +set net=C:\WINDOWS\system32\net.exe echo %usersFile% -%powershellPath% -ExecutionPolicy Bypass -File "%powershellScript%"- \ No newline at end of file +%powershellPath% -ExecutionPolicy Bypass -File "%powershellScript%" +%net% user Gamer +pause+ \ No newline at end of file