Category Archives: windows

Powershell random password generator – with complexity!

Recently we needed to automate password randomization for account creation purposes. In order to ensure the password policy was met we needed, 8 characters total, 1 uppercase letter, 1 number, and 1 special character. We also needed to control the character set of special characters due to certain finicky applications. This script grabs a base password from http://random.org, verifies that it has all but our special character, and finally randomly inserts one of our special characters into the password.

Function Get-Seed{
# Generate a seed for future randomization
$RandomBytes = New-Object -TypeName 'System.Byte[]' 4
$Random = New-Object -TypeName 'System.Security.Cryptography.RNGCryptoServiceProvider'
$Random.GetBytes($RandomBytes)
[BitConverter]::ToInt32($RandomBytes, 0)
}

do
{
$initialPW = $(Invoke-RestMethod https://www.random.org/passwords/?num=1&len=7&format=plain&rnd=new) -replace "`n"

if($initialPW -cmatch "[A-Z]") { $containsUpper = $True } else { $containsUpper = $False }
if($initialPW -cmatch "[a-z]") { $containsLower = $True } else { $containsLower = $False }
if($initialPW -match "[0-9]") { $containsNumbr = $True } else { $containsNumbr = $False }

$specCharArray = [Char[]]"!#$&*_-"
$specChar = $($specCharArray | Get-Random -Count 1)

if (($containsUpper -eq $True) -and ($containsLower -eq $True) -and $($containsNumbr -eq $True))
{
$seed = $(Get-Random -Maximum 7 -Minimum 1 -SetSeed $(Get-Seed))
$initialPW.Insert($seed,$specChar)
break
}
}
While ($True)

srvany.exe service wrapper

I put this together for a project recently, if you’ve ever used the instsrv.exe and srvany.exe utilities from the Windows 2003 resource kit you know they have their limitations. For instance if the executable you’re daemonizing with srvany.exe crashes or is killed, the service still shows as running. Not really helpful when you’re talking about, let’s say, cluster fail-over, or monitoring for that matter. Here’s a script I put together that captures process IDs for a sub-process that the script calls, the process for the script itself, and the parent process of the script. If the sub-process called by the script dies, it will destroy it’s parent process and terminate itself.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' srvany.exe wrapper from the Windows 2003 resource kit Please use at you own risk - this      ''
'' script is without warranty. This script checks every 5 seconds if the process it spawned is  ''
'' still alive. If the spawned process is not alive it will kill the parent process and         ''
'' terminate itself.                                                                            ''
'' Set: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\YourService\Parameters\Application ''
'' To: cscript.exe /nologo "C:\path\to\this\script.vbs"                                         ''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Const SW_NORMAL = 1
dim strCommand, strComputer
strComputer = "."
strCommand = "C:\path\to\your\executable.exe" ' This can be anything, try "c:\windows\notepad.exe" and run the script interactively

' Create WMI object
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

' Create configuration object required by Win32_Process to create a new process
Set objStartup = objWMIService.Get("Win32_ProcessStartup")
Set objConfig = objStartup.SpawnInstance_
objConfig.ShowWindow = SW_NORMAL

' Create process object
Set objNewProcess = objWMIService.Get("Win32_Process")

' Create process based on strCommand
intReturn = objNewProcess.Create(strCommand, Null, objConfig, intProcessID)

Do Until pCheck <> 0

'Object for checking script process ID and parent process ID
Set objSWbemServices = GetObject ("WinMgmts:Root\Cimv2")
Set colProcess = objSWbemServices.ExecQuery ("Select * From Win32_Process")

'Object for checking if our application is alive
Set objSWbemServicesSub = GetObject("WinMgmts:Root\Cimv2")
Set OurProcess = objSWbemServicesSub.ExecQuery("Select * From Win32_Process where ProcessID = " & intProcessID)
   
    If OurProcess.Count = 0 Then
    ' Process no longer exists - crashed or terminated - now terminate script and parent processes
    For Each objProcess In colProcess
        If InStr (objProcess.CommandLine, WScript.ScriptName) <> 0 Then
           
            ' Object needed to grab parent process ID from objProcess (this script)
            Set objSWbemServicesParent = GetObject("WinMgmts:Root\Cimv2")
            Set ParentProcess = objSWbemServicesParent.ExecQuery("Select * from Win32_Process where ProcessID = " & objProcess.ParentProcessId)
           
            ' Terminate parent process
            For Each srvProcess In ParentProcess
                srvProcess.Terminate()
               
                ' Terminate script handler (Loop check)
                pCheck = 1
            Next
           
           
        Else
           
        End If
    Next

    End If

Wscript.Sleep 5000

Loop

Packet sniffing – not Sharpie sniffing!

Seriously, have you ever smelled those Expo dry erase markers? I really think you can get high off those things.  Honestly though, let’s take a look at a case where you might need to sniff packets instead of Sharpies.  If you’ve ever worked in IT, at some point, you’ve needed a packet sniffer even if you didn’t realize it.  As a desktop IT person, if a server you’re trying to communicate with isn’t responding appropriately, a packet sniffer will prove it.  As an engineer it will give you the proof you need to explain to people in Vietnam why they should not be in the networking business.  Let’s take a look at two tools that will become invaluable to you in IT so long as you know what you’re looking at and how to use the information they provide (Wireshark and tcpdump).
Continue reading

Shrewsoft VPN: 64bit VPN client for Cisco 3000 VPN Concentrators

You heard it right folks – you can have access from your 64-bit Windows systems to those old Cisco 3000 VPN concentrators. Here’s how to setup Shrewsoft to work with a standard Cisco 3000 VPN concentrator (Client download is here):

After you have installed the software, open the access manager, click “Add“, and type in the hostname or IP address to which you wish to connect:
Screenshot

Next click the “Authentication” tab and change the “Authentication Method” to “Mutual PSK + XAuth” (This assumes you have a named group and group password).  Change the “Identification Type” to “Key Identifier” and enter the group name (Provided by the VPN concentrator administrator) under “Key ID String“:
Screenshot

While still on the “Authentication” tab, click the sub-tab labeled “Credentials” where you will set your group password in the “Pre Shared Key” field:
Screenshot

That’s about it really – click “Save” and you’re ready to connect.  Highlight your new connection in the connection manager and click “Connect“.  Provide your user credentials and your tunnel is established:
Screenshot

how to: domain information groper (dig) basics

If every IT administrator was issued a swiss army knife full of technical tools, dig would certainly be in it.  If you have ever hosted, registered, or administered a domain name or DNS server then you have likely run across this tool at some point.  Here are the basics of DNS and how to use dig to get the information you need:

NOTE: Headers and footers have been removed from these queries for ease of use.  In headers and footers you will see information regarding the version of dig you are using and how long your query took respectively.
Continue reading

gnu utilities for windows

Great for when you need grep, gzip, tar, and many more in a Windows environment (Gzip is especially great for compressing logs quickly and efficiently at 2AM when you’re out of disk space).

Check ’em out: http://gnuwin32.sourceforge.net/