Automating with PowerShell: Adding domains to IT-Glue programmatically.

So ITGlue is a great application and has a lot of API’s available. Unfortunately there is no API to add domains or SSL certificates to IT-Glue. Seeing as I have a couple of sources where domains and SSL certificates come from I’d still like to add them programmatically.

To do this, I’ve created the small function below. It uses the Chrome cookies to login to the ITGlue webpage instead and commit a new domain. It’s quite hacky but works wonders when you need to grab data from a lot of different systems and smush them together in IT-Glue.

You could make some modifications to do this for other non-API available endpoints such as Documents, or SSL certificates.

<#
.SYNOPSIS
    Creates ITG domains using the current ITG cookie
.DESCRIPTION
    A method to create ITGlue domains by abusing the cooking and commiting the normal form workflow. This is due to no Domain API is currently available. The function expects you to be logged into ITGlue using Chrome as your browser.
.EXAMPLE
    PS C:\> New-ITGDomain -OrgID 12345 -DomainName 'example.com' -ITGURL 'Yourcompany.Itglue.com'
    Creates a new ITGlue domain example.com in organisation 12345 for the ITglue YourCompany.ITGlue.com. Please note to *not* use the API URL in this case.
.INPUTS
    OrgID = Organisation ID in IT-Glue
    DomainName = Domain name you wish to add.
    ITGURL = The normal access URL to your IT-Glue instance.
.OUTPUTS
    Fail/Success
.NOTES
   No notes
#>
function New-ITGDomain {
    param (
        [string]$OrgID,
        [string]$DomainName,
        [string]$ITGURL
    )
    $ChromeCookieviewPath = "$($ENV:TEMP)/Chromecookiesview.zip"
    if (!(Test-Path $ChromeCookieviewPath)) {
        write-host "Downloading ChromeCookieView" -ForegroundColor Green
        Invoke-WebRequest 'https://www.nirsoft.net/utils/chromecookiesview.zip' -UseBasicParsing -OutFile $ChromeCookieviewPath
        Expand-Archive -path $ChromeCookieviewPath -DestinationPath  "$($ENV:TEMP)" -Force
    }
    Start-Process -FilePath "$($ENV:TEMP)/Chromecookiesview.exe" -ArgumentList "/scomma $($ENV:TEMP)/chromecookies.csv"
    start-sleep 1
    $Cookies = import-csv "$($ENV:TEMP)/chromecookies.csv"
    write-host "Grabbing Chrome Cookies" -ForegroundColor Green
    $hosts = $cookies | Where-Object { $_.'host name' -like '*ITGlue*' }

    write-host "Found cookies. Trying to create request" -ForegroundColor Green
    write-host "Grabbing ITGlue session" -ForegroundColor Green
    $null = Invoke-RestMethod -uri "https://$($ITGURL)/$($orgid)/domains/new" -Method GET -SessionVariable WebSessionITG
    foreach ($CookieFile in $hosts) {
        $cookie = New-Object System.Net.Cookie
        $cookie.Name = $cookiefile.Name
        $cookie.Value = $cookiefile.Value
        $cookie.Domain = $cookiefile.'Host Name'
        $WebSessionITG.Cookies.Add($cookie)
    }
    write-host "Grabbing ITGlue unique token" -ForegroundColor Green
    $AuthToken = (Invoke-RestMethod -uri "https://$($ITGURL)/$($orgid)/domains/new" -Method GET -WebSession $WebSessionITG) -match '.*csrf-token"'
    $Token = $matches.0 -split '"' | Select-Object -Index 1
    write-host "Creating domain" -ForegroundColor Green
    $Result = Invoke-RestMethod -Uri "https://$($ITGURL)/$($orgid)/domains?submit=1" -Method "POST" -ContentType "application/x-www-form-urlencoded"   -Body "utf8=%E2%9C%93&authenticity_token=$($Token)&domain%5Bname%5D=$($DomainName)&domain%5Bnotes%5D=&domain%5Baccessible_option%5D=all&domain%5Bresource_access_group_ids%5D%5B%5D=&domain%5Bresource_access_accounts_user_ids%5D%5B%5D=&commit=Save" -WebSession $WebSessionITG
    if ($Result -like "*Domain has been created successfully.*") {
        write-host "Succesfully created domain $DomainName for $OrgID" -ForegroundColor Green
    }
    else {
        write-host "Failed to create $DomainName for $orgid" -ForegroundColor Red
    }

}

Recent Articles

The return of CyberDrain CTF

CyberDrain CTF returns! (and so do I!)

It’s been since september that I actually picked up a digital pen equivalent and wrote anything down. This was due to me being busy with life but also my side projects like CIPP. I’m trying to get back into the game of scripting and blogging about these scripts. There’s still so much to automate and so little time, right? ;)

Monitoring with PowerShell: Monitoring Acronis Backups

Intro

This is a monitoring script requested via Reddit, One of the reddit r/msp users wondered how they can monitor Acronis a little bit easier. I jumped on this because it happened pretty much at the same time that I was asked to speak at the Acronis CyberSummit so it kinda made sense to script this so I have something to demonstrate at my session there.

Monitoring with PowerShell: Monitoring VSS Snapshots

Intro

Wow! It’s been a while since I’ve blogged. I’ve just been so swamped with CIPP that I’ve just let the blogging go entirely. It’s a shame because I think out of all my hobbies it’s one I enjoy the most. It’s always nice helping others achieve their scripting target. I even got a couple of LinkedIn questions asking if I was done with blogging but I’m not. Writing always gives me some more piece of mind so I’ll try to catch up again. I know I’ve said that before but this time I’ll follow through. I’m sitting down right now and scheduling the release of 5 blogs in one go. No more whining and no more waiting.