Skip to content

Instantly share code, notes, and snippets.

@MatthewJDavis
MatthewJDavis / New-CtfmonRegKey.ps1
Created July 28, 2018 15:17
Add ctfmon.exe to registry to run on login
$keyName = 'run-ctfmon-search-fix'
$keyValue = 'C:\Windows\system32\ctfmon.exe'
$keyPath = 'HKCU:Software\Microsoft\Windows\CurrentVersion\run'
# Add the ctfmon.exe to the HKey_Current_User run registry key
New-ItemProperty -Name $keyName -Value $keyValue -Path $keyPath
# View the registry keys that run when a user logs in
Get-ItemProperty -Path $keyPath
@MatthewJDavis
MatthewJDavis / New-WebhookDisplayData.ps1
Created July 30, 2018 00:43
PowerShell runbook for Azure automation webhook example
<#
Script to demo how to get data from a posted webhook
#>
Param
(
[object]$WebhookData
)
if ($WebhookData) {
@MatthewJDavis
MatthewJDavis / get-ec2amiName.ps1
Created August 5, 2018 21:33
Get the ami name and other properties using the EC2 filter model
# Has to be lower case windows for the platform, despite Windows is returned in the results.
$filterPlatform = New-Object Amazon.EC2.Model.Filter
$filterPlatform.Name = 'platform'
$filterPlatform.Value = 'windows'
# The name is case sensitive, base will not bring any results back
$filterName = New-Object Amazon.EC2.Model.Filter
$filterName.Name = 'name'
$filterName.Value = '*Windows*1803*Base*'
@MatthewJDavis
MatthewJDavis / Packer-EC2-1803-DNSAmi.JSON
Created August 5, 2018 21:42
Packer build to use the latest version of Windows 1803 to build a lightweight DNS server.
{
"builders": [
{
"type": "amazon-ebs",
"region": "eu-west-1",
"instance_type": "t2.micro",
"ami_name": "1803-dns-{{timestamp}}",
"communicator": "winrm",
"winrm_username": "Administrator",
"winrm_use_ssl": true,
<# Reset a user's Azure mfa settings. This wipes the current settings so the user must provide them again next time the try to authenticate.
User running the command from slack must be in the authorisedUsers hashtable.
Requires the user's correct UPN in Azure otherwise will fail.
https://api.slack.com/slash-commands for the format of how the data is sent to the webhook
Percent encoding is used for the data see wikipedia for info: https://en.wikipedia.org/wiki/Percent-encoding
Using Write-Output to outpupt information to Azure Automation runbook history to make searching who ran the command easier
#>
param
(
[object] $WebhookData
@MatthewJDavis
MatthewJDavis / SSLPoke.java
Created January 10, 2019 00:15
Java SSL poke from atlassian
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import java.io.*;
/** Establish a SSL connection to a host and port, writes a byte and
* prints the response. See
* http://confluence.atlassian.com/display/JIRA/Connecting+to+SSL+services
*/
public class SSLPoke {
public static void main(String[] args) {
@MatthewJDavis
MatthewJDavis / New-AWSbackupVault.ps1
Created April 6, 2019 00:26
Create a new aws backup vault
# Create a backup vault
$VaultName = 'demo'
$ProjectTag = @{'Project' = 'Demo' }
New-BAKBackupVault -BackupVaultName $VaultName -BackupVaultTag $ProjectTag
@MatthewJDavis
MatthewJDavis / New-AWSbackupPlan.ps1
Last active April 8, 2019 14:30
Create lifecycle and rules then create an AWS backup plan
# Create backup lifecycle, tags and plan
$BackupLifeCycle = New-Object -TypeName Amazon.Backup.Model.Lifecycle
$BackupLifeCycle.DeleteAfterDays = 7
# $BackupLifeCycle.MoveToColdStorageAfterDays = Commented out so no cold storage. Uncomment and assign a value if cold storage is required
# Create the tags to be applied to items created by this backup plan
$RecoveryTags = New-Object -TypeName 'system.collections.generic.dictionary[string,string]'
$RecoveryTags.Add('created:by:aws:backup:plan', '4-AM-7-Day-Retention')
@MatthewJDavis
MatthewJDavis / New-AWSbackupSelection.ps1
Created April 6, 2019 00:30
Create a new backup plan selection based on a tag value
# Resource selection https://docs.aws.amazon.com/sdkfornet/v3/apidocs/index.html?page=Backup/TBackupCondition.html&tocid=Amazon_Backup_Model_Condition
$BackupSelectionName = '4AM-7-Day-Retention-Tag'
$IAMRoleARN = (Get-IAMRole -RoleName AWSBackupDefaultServiceRole).arn # using the default created role here
$BackupCondition = New-Object -TypeName Amazon.Backup.Model.Condition
$BackupCondition.ConditionKey = 'BackupPolicy'
$BackupCondition.ConditionValue = '4AM-7-Day-Retention'
$BackupCondition.ConditionType = 'STRINGEQUALS'
@MatthewJDavis
MatthewJDavis / ec2Instance.ps1
Created April 6, 2019 01:01
Handy ec2 commands
# Output the instance name from the tag along with a few properties
$ec2 = Get-EC2Instance
($ec2).Instances | ForEach-Object {
$properties = [ordered]@{
Name = ($_ | Select-Object -ExpandProperty tags | Where-Object -Property Key -eq Name ).value
InsanceID = $_.InstanceId
PrivateIP = $_.PrivateIpAddress
SubnetId = $_.SubnetId
InstanceType = $_.InstanceType