Lets Automate It

from Josh Rickard

Script Adding Exchange Resource Accounts to Your Outlook

2018-08-07 Josh Rickard

I work for a large public University and we have many Resource Accounts.  We needed a way to move from Public Folders but we wanted it to be seemless as possible.  To do this, I created this VBS script that allows anyone to add Resource Accounts to their Outlook 2013/2010 calendar as a shared calendar.  The user in question will have to run this script while Outlook is open and it will pull the Resource Account (add the Resource Account name in the RESOURCEACCOUNTNAME variable below) from the GAL and add it to the users calendar.  I hope this helps anyone interested in doing the same.

Continue reading

Script Removing Proxy From Firefox User Prefs Js

2018-08-07 Josh Rickard

So, I was tasked with removing proxy settings from Firefox because of Webroot Desktop Proxy.  Removing them from the %Programfiles% directory was easy, the hard part was the user prefs.js.  Anyways, here’s a little script I created to remove Proxy settings and set them to No Proxy.

cd /D “%APPDATA%\Mozilla\Firefox\Profiles" cd *.default set ffile=%cd% type “%ffile%\prefs.js” | findstr /v “user_pref(“network.proxy.type”, 2);">"%ffile%\prefs_.js” type “%ffile%\prefs.js” | findstr /v “user_pref(“network.proxy.type”, 0);">"%ffile%\prefs_.js” ren “prefs.js” “prefs_.js” del “%ffile%\prefs.js” ren “prefs_.js” “prefs.js” del “%ffile%\prefs_.js” echo user_pref(“network.proxy.type”, 0);>>"%ffile%\prefs.js” set ffile= cd %windir%

Powershell Updating Local Admin Passwords Securely 3 of 3

2018-08-07 Josh Rickard

Below is an example of how to remotely (using PowerShell) update and change the Local Administrator password securely.  This is not my script, I received this script along with many others from the SANS SEC 505 course.  I have not altered it in any way.

Updating the Passwords of the Local Administrator on remote mahcines (You must have a Certificate either from your CA or another Certificate Authority):

This script will remove older local administrator passwords that you have created with the first part (1 of 3) which is decrypted by your Private Key Certificate in (2 of 3).

Copy this text into a PowerShell Script called CleanUp_PasswordArchive.ps1

[code ]

#################################################################################### #.Synopsis

Carefully delete only the correct password archive files previously

created with the companion script named Update-PasswordArchive.ps1.

#.Description

Deletes older password archive files while retaining a chosen number

(default = 5) of prior successful and failed archive files for each

unique combination of computer and user (total of 10 files by default

for each unique combination). Scheduling this script will help to

maintain a reasonable number of password archive files.

#.Parameter PasswordArchivePath

The local or UNC path to where the encrypted password files are kept.

#.Parameter ComputerName

Name of the computer with the local account whose password was reset

and whose password was encrypted and saved to a file. The computer

name will match the names of files in the PasswordArchivePath. This

parameter can accept a computer name with a wildcard in it. When

specified, only the archives for that computer (or for those matching

computers with a wildcard) will be cleaned up instead of the default,

which is to clean up archive files for all computers.

#.Parameter ArchivesToKeep

The number of current and prior password archive files to keep for

each combination of computer name and user name. A single computer

might have multiple local user accounts whose passwords are managed

by these scripts, so the clean up must handle this gracefully. The

default is 5 (5 successful files + 5 failures files = 10 files).

#.Parameter VerboseReporting

Switch to show verbose information.

#.Parameter DoNotDelete

Switch to do a -WhatIf dry run that will not actually delete any

files. Use this switch along with -VerboseReporting for testing.

#.Parameter DeleteAllPasswordArchives

Switch to delete all password archive files without exception.

#.Example

.\CleanUp-PasswordArchive.ps1 -PasswordArchivePath \server\share

Deletes all but the last 5 password archive files for each computer

and user combination. Also, deletes all but the last 5 failure-type

files for each combination. Hence, if the last successful reset was

six months ago, followed by many failures, the last 5 successful

reset archive files will not be deleted.

#.Example

.\CleanUp-PasswordArchive.ps1 -PasswordArchivePath \server\share -ComputerName WKS*

Only cleans up the archive files for computers which match the "WKS*" file

pattern. A full computer name can be specified, wildcards are not required.

Regular expressions are not supported.

#.Example

.\CleanUp-PasswordArchive.ps1 -PasswordArchivePath \server\share -DoNotDelete -VerboseReporting

No files will be deleted, but a verbose report of files discovered will be shown.

#Requires -Version 2.0

#.Notes

Author: Jason Fossen, Enclave Consulting (http: //www.sans.org/windows-security/)

Version: 1.0

Updated: 11.Nov.2012

LEGAL: PUBLIC DOMAIN. SCRIPT PROVIDED "AS IS" WITH NO WARRANTIES OR GUARANTEES OF

ANY KIND, INCLUDING BUT NOT LIMITED TO MERCHANTABILITY AND/OR FITNESS FOR

A PARTICULAR PURPOSE. ALL RISKS OF DAMAGE REMAINS WITH THE USER, EVEN IF

THE AUTHOR, SUPPLIER OR DISTRIBUTOR HAS BEEN ADVISED OF THE POSSIBILITY OF

ANY SUCH DAMAGE. IF YOUR STATE DOES NOT PERMIT THE COMPLETE LIMITATION OF

LIABILITY, THEN DELETE THIS FILE SINCE YOU ARE NOW PROHIBITED TO HAVE IT.

#################################################################################### Param ($PasswordArchivePath = ".", $ComputerName = "*", $ArchivesToKeep = 5, [Switch ] $VerboseReporting, [Switch ] $DoNotDelete, [Switch ] $DeleteAllPasswordArchives)

Test access to path.

if (Resolve-Path -Path $PasswordArchivePath) { $PasswordArchivePath = $(Resolve-Path -Path $PasswordArchivePath).Path } else { "nERROR: Cannot resolve path to archive folder: $PasswordArchivePath n" ; exit }

Sanity check on $ArchivesToKeep

if ($ArchivesToKeep -le 0) { "nERROR: The -ArchivesToKeep argument must be 1 or larger.n" ; exit }

Get all matching files.

$filter = $($ComputerName + "+++").Replace("**","*") $files = dir -Path $PasswordArchivePath -Filter $filter if ($VerboseReporting) { "nTotal number of matching ($ComputerName) archive files = " + $files.count $files | foreach { $_.fullname } "n" }

Maybe just delete them all.

if ($DeleteAllPasswordArchives -and $DoNotDelete) { "nERROR: Invalid combination of switches.n" ; exit } if ($DeleteAllPasswordArchives -and $ComputerName -ne "*") { "nERROR: Invalid combination of switches.n" ; exit } if ($DeleteAllPasswordArchives) { "nDeleting all password archive files...n" $files | foreach { remove-item $_ } exit }

Separate successful vs. failed password reset files.

$failurefiles = $files | where { $.Name -like "*FAILURE" } $successfiles = $files | where { $.Name -notlike "*FAILURE" } if ($VerboseReporting) { "Files for failed resets = " + $failurefiles.count } if ($VerboseReporting) { "Files for successful resets = " + $successfiles.count }

Build arrays of unique computername+username combinations.

$failurenames = @() $successnames = @()

foreach ($file in $failurefiles) { $computer = $($file.name -split ‘+’)[ 0 ] + "+" + $($file.name -split ‘+’)[ 1 ] if ($computer -notin $failurenames){ $failurenames += $computer } } if ($VerboseReporting) { "nUnique Computer+User combinations for failed resets = " + $failurenames.count } if ($VerboseReporting) { $failurenames ; "n" }

foreach ($file in $successfiles) { $computer = $($file.name -split ‘+’)[ 0 ] + "+" + $($file.name -split ‘+’)[ 1 ] if ($computer -notin $successnames){ $successnames += $computer } } if ($VerboseReporting) { "Unique Computer+User combinations for successful resets = " + $successnames.count } if ($VerboseReporting) { $successnames ; "`n" }

Delete the non-keepers for each unique name.

$SuccessFileCounter = $FailureFileCounter = 0

foreach ($name in $failurenames) { $targets = $failurefiles | where { $.Name -like ($name + "+*") } | sort Name if ($targets.count -le $ArchivesToKeep) { continue } 0..$($targets.count - $ArchivesToKeep - 1) | foreach { if (-not $DoNotDelete){remove-item $targets[$ ].fullname ; if($?){$FailureFileCounter++ } } } }

foreach ($name in $successnames) { $targets = $successfiles | where { $.Name -like ($name + "+*") } | sort Name if ($targets.count -le $ArchivesToKeep) { continue } 0..$($targets.count - $ArchivesToKeep - 1) | foreach { if (-not $DoNotDelete){remove-item $targets[$ ].fullname ; if($?){$SuccessFileCounter++ } } } }

Default Report

[String ] $SuccessFileCounter + " files deleted out of the set of " + [String ] $successfiles.count + " successful reset files." [String ] $FailureFileCounter + " files deleted out of the set of " + [String ] $failurefiles.count + " failure reset files." "`n"

 

[/code ]

Powershell Updating Local Admin Passwords Securely 2 of 3

2018-08-07 Josh Rickard

 Below is an example of how to remotely (using PowerShell) update and change the Local Administrator password securely.  This is not my script, I received this script along with many others from the SANS SEC 505 course.  I have not altered it in any way.

Updating the Passwords of the Local Administrator on remote mahcines (You must have a Certificate either from your CA or another Certificate Authority):

This script will recover the local administrator password that you have created with the first part (1 of 3) which is decrypted by your Private Key Certificate.

Copy this text into a PowerShell Script called Recover_PasswordArchive.ps1

[code ]

#################################################################################### #.Synopsis

Recover the plaintext password from an encrypted file originally

created with the companion script named Update-PasswordArchive.ps1.

#.Description

Recover the plaintext password from an encrypted file originally

created with the companion script named Update-PasswordArchive.ps1. The

file is encrypted with a public key chosen by the administrator. The

password generated by Update-PasswordArchive.ps1 is random. Recovery

of the encrypted password from the file requires possession of the

private key corresponding to the chosen public key certificate.

#.Parameter PasswordArchivePath

The local or UNC path to where the encrypted password files are kept.

#.Parameter ComputerName

Name of the computer with the local account whose password was reset

and whose password was encrypted and saved to a file. The computer

name will match the names of files in the PasswordArchivePath. This

parameter can accept a computer name with a wildcard in it.

#.Parameter ShowAll

Without this switch, only the most recent plaintext password is shown.

With this switch, all archived passwords for the computer are shown.

This might be necessary when the passwords of multiple local user

accounts are being managed with these scripts.

#.Example

.\Recover-PasswordArchive.ps1 -ComputerName LAPTOP47

Displays in plaintext the last recorded password updated on LAPTOP47.

The user running this script must have loaded into their local cache

the certificate AND private key corresponding to the certificate used

to originally encrypt the password archive files in the present

working directory. A smart card may be used instead.

#.Example

.\Recover-PasswordArchive.ps1 -PasswordArchivePath \server\share -ComputerName WKS*

Instead of the present working directory of the script, search the

password archive files located in \server\share. Another local

folder can be specified instead of a UNC network path. The wildcard

in the computer name will show the most recent password updates for

all matching computer names in \server\share.

#.Example

.\Recover-PasswordArchive.ps1 -PasswordArchivePath \server\share -ComputerName LAPTOP47 -ShowAll

Instead of showing only the last password update, show all archived passwords

in the \server\share folder for the computer named LAPTOP47.

#Requires -Version 2.0

#.Notes

Author: Jason Fossen, Enclave Consulting (http: //www.sans.org/windows-security/)

Version: 1.0

Updated: 11.Nov.2012

LEGAL: PUBLIC DOMAIN. SCRIPT PROVIDED "AS IS" WITH NO WARRANTIES OR GUARANTEES OF

ANY KIND, INCLUDING BUT NOT LIMITED TO MERCHANTABILITY AND/OR FITNESS FOR

A PARTICULAR PURPOSE. ALL RISKS OF DAMAGE REMAINS WITH THE USER, EVEN IF

THE AUTHOR, SUPPLIER OR DISTRIBUTOR HAS BEEN ADVISED OF THE POSSIBILITY OF

ANY SUCH DAMAGE. IF YOUR STATE DOES NOT PERMIT THE COMPLETE LIMITATION OF

LIABILITY, THEN DELETE THIS FILE SINCE YOU ARE NOW PROHIBITED TO HAVE IT.

#################################################################################### Param ($PasswordArchivePath = ".", $ComputerName = "$env:computername", [Switch ] $ShowAll)

Construct and test path to encrypted password files.

$PasswordArchivePath = $(resolve-path -path $PasswordArchivePath).path if ($PasswordArchivePath -notlike "*") { $PasswordArchivePath = $PasswordArchivePath + "" } if (-not $(test-path -path $PasswordArchivePath)) { "nERROR: Cannot find path: " + $PasswordArchivePath + "n" ; exit }

Get encrypted password files and sort by name, which sorts by tick number, i.e., by creation timestamp.

$files = @(dir ($PasswordArchivePath + "$ComputerName+++*") | sort Name) if ($files.count -eq 0) { "nERROR: No password archives for " + $ComputerName + "n" ; exit }

Get the latest archive file only, unless -ShowAll is used.

if (-not $ShowAll){ $files = @($files[ -1 ]) }

Load the current user’s certificates and private keys.

$flags = new-object System.Security.Cryptography.X509Certificates.OpenFlags #ReadOnly $store = new-object System.Security.Cryptography.X509Certificates.X509Store #CurrentUser if (-not $? -or ($store.GetType().fullname -notlike "X509Stor")) { "nERROR: Could not load your certificates and private keys.n" ; exit } $store.open($flags) $certstore = $store.Certificates $store.close() if ($certstore.count -eq 0) { "nERROR: You have no certificates or private keys.n" ; exit }

Process encrypted password archive files and $output objects.

foreach ($lastfile in $files) ` { $output = ($output = " " | select-object ComputerName,FilePath,UserName,TimeStamp,Thumbprint,Valid,Password)

$output.ComputerName = $($lastfile.Name -split ‘+’)[ 0 ] $output.FilePath = $lastfile.fullname $output.UserName = $($lastfile.Name -split ‘+’)[ 1 ] $output.TimeStamp = [DateTime ][Int64 ]$($lastfile.Name -split ‘+’)[ 2 ] $output.Valid = $false #Assume password recovery will fail. $output.Thumbprint = $($lastfile.Name -split ‘+’)[ 3 ]

Check for password reset failure files.

if ($output.Thumbprint -eq "PASSWORD-RESET-FAILURE") { $output.Password = "ERROR: Try to use prior password(s) for this computer." $output continue }

Read in password archive binary file.

[byte[] ] $ciphertext = get-content -encoding byte -path $lastfile.fullname if (-not $?) { $output.Password = "ERROR: Failed to read " + $lastfile.fullname $output continue }

Load the correct certificate and test for possession of private key.

$certpriv = $certstore | where { $_.thumbprint -eq $output.thumbprint } if (-not $certpriv.hasprivatekey) { $output.Password = "ERROR: You do not have the private key for this certificate." $output continue }

Attempt decryption with private key.

$plaintextout = $certpriv.privatekey.decrypt($ciphertext,$false) #Must be $false for my smart card to work. if (-not $?) { $output.Password = "ERROR: Decryption failed." } else { $output.Password = ([char[] ]$plaintextout -join "") }

Confirm that archive file name matches the nonce string encrypted into the file.

Nonce helps to thwart attackers and can be used for troubleshooting too.

if ($lastfile.name -like $output.Password.substring(0, 60) + "*") { $output.Password = $output.Password.substring(60) #Strip out the 60-char nonce. $output.Valid = $true } else { $output.Password = $output.Password.substring(60) #Strip out the 60-char nonce. $output.Password = "ERROR: Integrity check failure: " + $output.Password.substring(60) + " (" + $output.Password + ")" } $output }

 

[/code ]

Powershell Updating Local Admin Passwords Securely 1 of 3

2018-08-07 Josh Rickard

So I haven’t posted in a bit but I’ve seen this request many times.  Below is an example of how to remotely (using PowerShell) update and change the Local Administrator password securely.  This is not my script, I received this script along with many others from the SANS SEC 505 course.  I have not altered it in any way.

Updating the Passwords of the Local Administrator on remote mahcines (You must have a Certificate either from your CA or another Certificate Authority):

Continue reading

Ipad Lockdown Mobileconfig

2018-08-07 Josh Rickard

It is possible to put an iPad or iPhone into ‘Store Demo’ mode so that the home button and swipe to home gesture is disabled. If you have seen the iPads in the Apple Store running the smart sign apps then you will know what I mean.

It is actually pretty trivial to make this work, all you need to do is install a correctly formatted mobile config plist over the air from a web server.

Continue reading

Questions About Mdt 2012 Driver Setup

2018-08-07 Josh Rickard

So I’ve had a lot of questions about my MDT 2012 Driver setup and hopefully this post will explain a little bit about it.  Let me know if you have any questions

Personally I have a folder on my server called _Source_Drivers.  I keep all my drivers here and import them into MDT but keep the original.  Here is what my file structure of this folder looks like.

MDT Source Drivers Structure

Continue reading
Older posts Newer posts