Skip to content

Instantly share code, notes, and snippets.

View ctigeek's full-sized avatar

Steven Swenson ctigeek

View GitHub Profile
@ctigeek
ctigeek / Config.cs
Last active February 4, 2018 23:52
Save name-object pairs securely.
public static class Config
{
public const int MaxValueLength = 7990; //If you change the size of the [secret] column then this needs to be changed.
public static string ConnectionString { get; set; }
public static string AesKey { get; set; }
public static int SecretPaddingSize { get; set; } = 1000; //e.g. any secret less than 1000 bytes will be padded so that it is at least 1000 bytes. This is to prevent information leaking regarding the size of the secret. Set to 0 to disable padding.
@ctigeek
ctigeek / Get-AllMailboxes.ps1
Last active April 6, 2023 09:11
Get all Hex and Rackspace mailboxes for your account, and any indirect accounts.
## This code released under the MIT open source license.
## See here for details: https://opensource.org/licenses/MIT
## This code is provided with NO SUPPORT and NO WARRANTY and NO GUARANTEE. Use at your own risk.
[string] $ApiKey = ""
[string] $ApiSecret = ""
## only populate $indirectAccountNumber if you want a list from one specific account, otherwise leave blank.
[string] $indirectAccountNumber = ""
[string] $path = "AllMailboxes.csv"
@ctigeek
ctigeek / QuartzClustered.config
Created November 28, 2017 21:29
Quartz clustered configuration.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<quartz>
<add key="quartz.scheduler.instanceName" value="test1" />
<add key="quartz.scheduler.instanceId" value="AUTO" />
<add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz" />
<add key="quartz.threadPool.threadCount" value="10" />
@ctigeek
ctigeek / Configure-Https.ps1
Last active September 22, 2017 19:54
Configure self-hosted app for HTTPS
## the cert dns doesn't really matter since it's self-signed.
$certName = "myappname.local"
$cert = New-SelfSignedCertificate -CertStoreLocation Cert:\LocalMachine\My -DnsName $certName
Write-Host "Created self signed cert: $($cert.Thumbprint) "
$guid = [guid]::NewGuid()
$ip = "0.0.0.0:443"
"http add sslcert ipport=$ip certhash=$($cert.Thumbprint) appid={$guid} " | netsh
#### netsh http delete sslcert ipport=$ip
@ctigeek
ctigeek / JsonConverter.cs
Last active September 21, 2017 15:33
TcpAppender for log4net. Also a json converter and example app.config. (I'm using it to write to an instance of logstash.)
/// This code is copywright 2017 by Steven Swenson and released under the MIT open source license.
/// https://opensource.org/licenses/MIT
using System;
using System.IO;
using log4net.Core;
using log4net.Layout.Pattern;
using Newtonsoft.Json;
namespace TestLog4Net
@ctigeek
ctigeek / Enable-DynamicIpThrottling.ps1
Created July 26, 2017 17:57
Enable dynamic IP throttling in IIS.
function Enable-DynamicIpThrottling($webSiteName, [bool] $enabled, [int]$maxRequests, [int]$intervalMilliseconds, [bool] $loggingOnly = $false) {
##https://docs.microsoft.com/en-us/iis/configuration/system.webserver/security/dynamicipsecurity/
Add-Type -Path "$env:SystemRoot\System32\inetsrv\Microsoft.Web.Administration.dll"
$manager = New-Object Microsoft.Web.Administration.ServerManager
$config = $manager.GetApplicationHostConfiguration();
$cpSecConfig = $config.GetSection("system.webServer/security/dynamicIpSecurity", $websiteName)
$cpSecConfig.SetAttributeValue("enableLoggingOnlyMode", $loggingOnly)
$requestRate = $cpSecConfig.ChildElements["denyByRequestRate"]
@ctigeek
ctigeek / Enable-IpSecurityProxyMode.ps1
Created July 26, 2017 16:02
Enable proxy mode in the IP security settings in IIS.
function Enable-IpSecurityProxyMode($websiteName) {
Add-Type -Path "$env:SystemRoot\System32\inetsrv\Microsoft.Web.Administration.dll"
$manager = New-Object Microsoft.Web.Administration.ServerManager
$config = $manager.GetApplicationHostConfiguration();
$cpSecConfig = $config.GetSection("system.webServer/security/ipSecurity", $websiteName)
$cpSecConfig.SetAttributeValue("enableProxyMode",$true)
$manager.CommitChanges();
$manager.Dispose()
@ctigeek
ctigeek / Add-IpToIisBlacklist.ps1
Last active July 26, 2017 14:08
Add an IP address to a black-list for an IIS website.
function Add-IpToIisBlacklist($websiteName, $ip, $subnetMask = $null) {
Add-Type -Path "$env:SystemRoot\System32\inetsrv\Microsoft.Web.Administration.dll"
$manager = New-Object Microsoft.Web.Administration.ServerManager
$config = $manager.GetApplicationHostConfiguration();
$cpSecConfig = $config.GetSection("system.webServer/security/ipSecurity", $websiteName)
$cpSecCollection = $cpSecConfig.GetCollection()
$newAdd = $cpSecCollection.CreateElement("add")
$newAdd["ipAddress"] = $ip
if ($subnetMask) {
@ctigeek
ctigeek / Get-DomainsAltAlias.ps1
Created May 24, 2017 17:48
Get all domains and alias/alternate domains from CP REST API.
function Get-XapiSignature($userAgent, $apiKey, $apiSecret) {
$dateTime = [DateTime]::UtcNow.ToString("yyyyMMddHHmmss");
$dataToSign = [String]::Format("{0}{1}{2}{3}", $apikey, $userAgent, $dateTime, $apiSecret);
$sha1 = [System.Security.Cryptography.SHA1]::Create();
$signedBytes = $sha1.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($dataToSign));
$signature = [System.Convert]::ToBase64String($signedBytes);
$sha1.Dispose()
[String]::Format("{0}:{1}:{2}", $apikey, $dateTime, $signature);
}
@ctigeek
ctigeek / Load-WhoisServers.ps1
Created April 11, 2017 19:32
Load whois servers from @weppos's repo.
if (-not $hostMap) {
$whoisHostMapUrl = "https://raw.githubusercontent.com/weppos/whois/master/data/tld.json"
$raw = Invoke-RestMethod $whoisHostMapUrl
$hostMap = @{}
$raw.psobject.Properties | ?{ $_.Value.host } | Foreach { $hostMap[$_.Name] = $_.Value.host }
}
## $hostMap["com"] will return whois.verisign-grs.com