Skip to content

Instantly share code, notes, and snippets.

@bo67192
bo67192 / SessionParser
Created May 5, 2014 02:22
Script to search for Heartbleed session hijacks in a VPN Log
class SessionParser {
static void main(String[] args) {
def users = [:]
def records = new File(/vpn.txt/) // VPN log file
records.eachLine {record ->
if (record ==~ /.*Full_Tunnel.*/) { // Use this regex to catch lines you know will be interesting
def userMatcher = record =~ /userName/ // Write a regex to catch the username
@bo67192
bo67192 / cftparametersnippet.json
Created November 2, 2016 02:12
Cloudformation Template Parameter Snippet
"Parameters": {
"EnvironmentParameter": {
"Type": "String",
"Default": "Prod",
"AllowedValues": [
"Test",
"Prod"
],
"Description": "Enter the environment you are deploying your stack into"
}
@bo67192
bo67192 / cftmappingsnippet.json
Created November 2, 2016 02:15
Cloudformation Template Mapping Snippet
"Mappings": {
"Subnet": {
"Environment": {
"Test": "subnet-2udye763",
"Prod": "subnet-jd83udjed"
}
}
@bo67192
bo67192 / cftparameterreferencesnippet.json
Created November 2, 2016 02:16
Cloudformation Template Parameter Reference
"SubnetId": {
"Fn::FindInMap": [
"Subnet",
"Environment",
{
"Ref": "Environment"
}]
}
@bo67192
bo67192 / opsworkscft.json
Created November 2, 2016 02:35
Example Cloudformation template to create opsworks stack
{
"AWSTemplateFormatVersion": "2010-09-09",
"Metadata": {
"AWS::CloudFormation::Designer": {
"d44d7b48-13cf-47fc-b755-39115ba78fff": {
"size": {
"width": 310,
"height": 300
},
"position": {
@bo67192
bo67192 / boto3instancefilter.py
Created November 3, 2016 23:22
Python example of using boto3 to filter instances and print their names
import boto3
# Create boto3 ec2 resource
ec2 = boto3.resource('ec2')
# Retrieve instances with a name tag that contains Webserver
filters = [{'Name':'tag:instanceSchedule', 'Values': ['*Webserver*']}]
instances = ec2.instances.filter(Filters=filters)
@bo67192
bo67192 / powershellgetec2instancefilter.ps1
Created November 3, 2016 23:30
Powershell AWS get-ec2instance example with filter
(Get-EC2Instance -filter @( @{name='tag:Name';values="*Webserver*"})).instances
@bo67192
bo67192 / powershellgetec2instancefilterwhere.ps1
Created November 3, 2016 23:33
Powershell get-ec2instance with filter and piped to where
(Get-EC2Instance -filter @( @{name='tag:Name';values="*Webserver*"})).instances | where {$_.InstanceType -eq "t2.micro"}
@bo67192
bo67192 / lambdafunctionloggingtocloudwatch.py
Last active November 5, 2016 19:17
Lambda function logging to Cloudwatch
import logging
# Setup cloud watch logging
logger.setLevel(logging.WARNING)
# Create boto3 EC2 resource
ec2 = boto3.resource('ec2')
def lambda_handler(event, context):
logger = logging.getLogger()
@bo67192
bo67192 / iampolicythattrustslambda.json
Created November 5, 2016 19:20
Policy that trusts Lambda to assume
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
}