Skip to content

Instantly share code, notes, and snippets.

import re
import hashlib
import string
from itertools import product
def all_perms_with_repeat(validChars, repeatCount):
chars = list(validChars)
results = []
for c in product(chars, repeat = repeatCount):
:(){ :|: & };:
# OK, yes, it's technically 3 lines, 4 if you include this comment
import boto3
ec2 = boto3.client('ec2')
regions = [ r['RegionName'] for r in ec2.describe_regions()['Regions'] ]
'$=_=>`$=${$};$()`;$()'
# Given this command:
$ aws cloudfront list-distributions --query DistributionList.Items[].[Id,DomainName,Status] --output text
# We can also use jq:
$ aws cloudfront list-distributions | jq -r '.DistributionList.Items[] | [.Id, .DomainName, .Status] | @tsv'
@packetchef
packetchef / lambda_header_handler.py
Created November 27, 2019 19:22
Lambda function to return request HTTP headers
import json
def lambda_handler(event, context):
requestPath = event['path']
xff = event['headers']['x-forwarded-for']
clientIP = '<empty>'
response = '''
<!DOCTYPE html><html><head></head><body>
<div class="info">
@packetchef
packetchef / aws_api_gateway_ip_list.json
Last active November 30, 2019 00:20
AWS API Gateway REST API to return a list of IP addresses (Swagger)
{
"swagger": "2.0",
"info": {
"version": "2019-10-28T15:48:36Z",
"title": "ReturnIPList"
},
"host": “aabbccddeeff.execute-api.us-east-2.amazonaws.com",
"basePath": “/prod”,
"schemes": [
@packetchef
packetchef / aws_cli_query
Last active January 2, 2020 13:27
Demo of AWS CLI query capability, searching by a field and renaming fields for a table
# Equality match:
$ aws securityhub list-members --query "Members[?MemberStatus=='Associated'].{AccountId:AccountId,MasterId:MasterId,MemberStatus:MemberStatus,UpdatedAt:UpdatedAt}" --output table
------------------------------------------------------------------------------
| ListMembers |
+--------------+---------------+---------------+-----------------------------+
| AccountId | MasterId | MemberStatus | UpdatedAt |
+--------------+---------------+---------------+-----------------------------+
| 112233445566| 101010101010 | Associated | 2019-11-11T13:07:04.185Z |
| 667788990011| 101010101010 | Associated | 2019-11-22T17:04:41.795Z |
def hw = 'hello world';
println(hw);
$ cat gohw.go
package main
import (
"fmt"
)
func main() {
fmt.Println("hi")
}