Skip to content

Instantly share code, notes, and snippets.

View andymotta's full-sized avatar

Andy Motta andymotta

View GitHub Profile
@andymotta
andymotta / ansiBool.yml
Created October 5, 2016 15:53
Force JSON boolean in json jinja template
query_boolean: false
query_string: "{{ query_boolean | bool | to_json }}"
@andymotta
andymotta / main.yml
Last active August 18, 2022 14:34
Trigger Jenkins job with Ansible
---
- name: trigger jenkins job
shell: "{{ lookup('template', 'trigger-jenkins.j2') }}"
delegate_to: localhost
- name: wait for job to complete
wait_for:
path: {{ lockfile }}
timeout: 600
@andymotta
andymotta / buckets_public_read.py
Last active December 9, 2017 03:07
Compliance: Find S3 buckets with public access, send offending statements to SNS topic
#!/usr/bin/env python
import json
import boto3
import botocore
s3 = boto3.resource('s3')
client = boto3.client('s3')
sns = boto3.client('sns')
@andymotta
andymotta / strokeit.py
Last active August 15, 2017 00:00
Wrapper to scan network with built-in OS X port scanner
#!/usr/bin/env python3
# python3 strokeit.py 192.168.1.0/24 0 1024
import subprocess
import ipaddress
import os
import sys
strokeEC="/System/Library/CoreServices/Applications/Network Utility.app/Contents/Resources/stroke"
@andymotta
andymotta / find_user_from_access_key.py
Last active June 22, 2022 11:17
Find an AWS IAM user corresponding to an AWS Access Key (boto3)
# Find the IAM username belonging to the TARGET_ACCESS_KEY
import boto3
from botocore.exceptions import ClientError
iam = boto3.client('iam')
def find_user(key):
try:
key_info = iam.get_access_key_last_used(AccessKeyId=key)
@andymotta
andymotta / credentials.py
Created June 14, 2017 00:24
Read or Write to ~/.aws/credentials file with SafeConfigParser
from ConfigParser import SafeConfigParser
credentials = os.path.join(os.environ['HOME'], '.aws', 'credentials')
parser = SafeConfigParser()
parser.read(credentials)
print parser.get('default', 'aws_access_key_id',)
parser.set('default', 'aws_access_key_id', 'AKXXX55555XXXXXXXXXA')
parser.set('default', 'aws_secret_access_key', 'XXXXXXXXXX00000/555XXXXX555555555XXXXX')
@andymotta
andymotta / 2s3.py
Created August 9, 2017 03:21
Watch a directory for changes with Python Watchdog then multipart upload to S3
import sys
import os
import time
from watchdog.observers import Observer
from watchdog.events import FileModifiedEvent, FileCreatedEvent
import boto3
import mimetypes
from botocore.exceptions import ClientError
# Create an S3 client
@andymotta
andymotta / boto3_iam_access_key_rotation.py
Last active November 24, 2021 10:04
Rotate AWS IAM access keys for every Boto profile on host (Compliance)
## Meant to be scheudled on a cron/timer of 90 days (CIS Benchmark)
## The target keys need permissions to rotate themselves
import boto3
from botocore.exceptions import ClientError
import os
from datetime import datetime
import shutil
from ConfigParser import SafeConfigParser
@andymotta
andymotta / delete_all_inactive_keys.py
Created October 30, 2017 23:36
Delete ALL inactive IAM keys for each profile on server
import boto3
from botocore.exceptions import ClientError
import datetime
from datetime import date
import os
from ConfigParser import SafeConfigParser
access_file = os.path.join(os.environ['HOME'], '.aws', 'credentials')
access_list = SafeConfigParser()
@andymotta
andymotta / active_keys_never_used.py
Last active October 30, 2017 23:41
Find all active IAM access keys that have never been used
import boto3
from botocore.exceptions import ClientError
import datetime
from datetime import date
import os, re
global DEFAULT_AGE_THRESHOLD_IN_DAYS
DEFAULT_AGE_THRESHOLD_IN_DAYS = 7
def main():