Skip to content

Instantly share code, notes, and snippets.

@klapcsik
klapcsik / cf_create_or_update.py
Created April 30, 2022 12:35 — forked from svrist/cf_create_or_update.py
Update or create a CloudFormation stack given a name and template + params'
'Update or create a stack given a name and template + params'
from __future__ import division, print_function, unicode_literals
from datetime import datetime
import logging
import json
import sys
import boto3
import botocore
@klapcsik
klapcsik / dom_performance_reflow_repaint.md
Created April 30, 2022 04:40 — forked from faressoft/dom_performance_reflow_repaint.md
DOM Performance (Reflow & Repaint) (Summary)

DOM Performance

Rendering

  • How the browser renders the document
    • Receives the data (bytes) from the server.
    • Parses and converts into tokens (<, TagName, Attribute, AttributeValue, >).
    • Turns tokens into nodes.
    • Turns nodes into the DOM tree.
  • Builds CSSOM tree from the css rules.
import boto3 #Calling Boto3 library
ec2 = boto3.resource('ec2', region_name='us-west-2')
sgs = ec2.security_groups.all() # Fetching all security groups in AWS account
all_sgs = set([sg.group_name for sg in sgs]) # Creating a list of only security group names
instances = ec2.instances.all() # Getting all instances in AWS account
@klapcsik
klapcsik / add_ip_to_ipset.sh
Created April 2, 2022 13:14 — forked from RichardBronosky/add_ip_to_ipset.sh
Add IP to AWS WAF IP set via CLI
#!/usr/bin/env bash -eux
function usage(){
cat<<USAGE
NAME
add_ip_to_ipset - Add a single IP to a WAF IP Set
SYNOPSIS
add_ip_to_ipset IP IP_SET_NAME
@klapcsik
klapcsik / remove-waf-acls.sh
Created April 2, 2022 13:07 — forked from activeshadow/remove-waf-acls.sh
Remove AWS WAF ACLs
#!/bin/bash
ACLS=$(aws waf list-web-acls | jq -r ".WebACLs[] | .WebACLId")
for acl in $ACLS; do
TOKEN=$(aws waf get-change-token | jq -r .ChangeToken)
RULE=$(aws waf get-web-acl --web-acl-id $acl | jq ".WebACL.Rules[0]")
aws waf update-web-acl --cli-input-json '{"WebACLId": "'$acl'", "ChangeToken": "'$TOKEN'", "Updates": [{"Action": "DELETE", "ActivatedRule": '"$RULE"'}]}'
@klapcsik
klapcsik / waf.py
Created April 1, 2022 07:21 — forked from juanesech/waf.py
Create a ip set based rule and ACL on AWS WAF using boto3
import boto3
import sys
import fileinput
client = boto3.client('waf')
app_name = sys.argv[1]
acl_action = sys.argv[2]
rule_action = sys.argv[3]
ip_set = ''
@klapcsik
klapcsik / gencert.py
Created March 30, 2022 22:18 — forked from toolness/gencert.py
Python script to create server SSL certs and sign them with a custom CA.
#! /usr/bin/python
"""
This simple script makes it easy to create server certificates
that are signed by your own Certificate Authority.
Mostly, this script just automates the workflow explained
in http://www.tc.umn.edu/~brams006/selfsign.html.
Before using this script, you'll need to create a private
@klapcsik
klapcsik / newcert.py
Created March 30, 2022 22:16 — forked from Zeerg/newcert.py
Python script to generate CSR/Self Signed Cert. Needs pyOpenssl and python-whois
#!/usr/bin/python
from OpenSSL import crypto
import os
import sys
import datetime
import whois
#Variables
TYPE_RSA = crypto.TYPE_RSA
TYPE_DSA = crypto.TYPE_DSA
event_name="ConsoleLogin"
aws cloudtrail lookup-events --lookup-attributes \
AttributeKey=EventName,AttributeValue=$event_name --query \
'Events[*].{Ev:CloudTrailEvent,User:Username}' |
jq '.[]| "Username: " + .User, " " + (.Ev| fromjson | "EventTime: " + .eventTime, "SourceIP: " + .sourceIPAddress) '
for event_name in AuthorizeSecurityGroupEgress AuthorizeSecurityGroupIngress CreatePolicy \
CreateSecurityGroup DeleteTrail ModifyVpcAttribute PutUserPolicy PutRolePolicy \
RevokeSecurityGroupEgress RevokeSecurityGroupIngress UpdateTrail; do
@klapcsik
klapcsik / clean_orphaned_snapshots.py
Created March 19, 2022 15:02 — forked from mjbommar/clean_orphaned_snapshots.py
Cleans orphaned snapshots from an EC2 account. Requires boto config.
'''
@author Bommarito Consulting, LLC
@date 20120622
Identify and, if requested, remove orphaned snapshots from an EC2 account.
'''
# Imports
import boto