Skip to content

Instantly share code, notes, and snippets.

View rachejazz's full-sized avatar
:octocat:
Automating and hunting for loopholes

Divya Goswami rachejazz

:octocat:
Automating and hunting for loopholes
View GitHub Profile
@rachejazz
rachejazz / append.sh
Last active October 17, 2023 11:41
nuxmv pull to bashrc
curl -Lo nuxmv.tar.gz https://nuxmv.fbk.eu/theme/download.php?file=nuXmv-2.0.0-linux64.tar.gz
gunzip nuxmv.tar.gz
tar -xvf nuxmv.tar
cat << EOF >> ~/.bashrc
export PATH="$PATH:$(pwd)/nuXmv-2.0.0-Linux/bin/"
alias nu="nuXmv"
EOF
source ~/.bashrc
@rachejazz
rachejazz / automate_error_jira.py
Last active August 22, 2022 22:52
Automate Error Reports from GCP to Jira along with attaching log file
#!/usr/bin/env python3
"""
This is a prototype for automating prod error tickets from GCP to Jira.
"""
import os
import json
import argparse
import subprocess
import logging as pylog
import datetime as d
@rachejazz
rachejazz / ssl-expiry.py
Created August 22, 2022 22:37
script to monitor ssl cert expiration on a given list of hosts
#!/usr/bin/env python
"""
This script is a prototype of a ssl monitoring system.
It checks for the expiration date and alerts whether cert is
1. Expired
2. About to expire in 2 weeks
3. Valid, with the expiration date
Script uses asyncio to speed up checking hostnames simultaneously.
"""
@rachejazz
rachejazz / sudo_notifier.sh
Created August 22, 2022 22:34
Sends an alert on webhook if an unprivileged user uses sudo on a machine
#!/bin/bash
while inotifywait -e modify /var/log/auth.log;
do
word=`tail -n1 /var/log/auth.log | grep 'user NOT in sudoers'`
if [[ $word ]]; then
echo '{"text":"'$word'"}' > sendtoslack
curl -X POST \
-H 'Content-type: application/json' \
--data @sendtoslack \
<webhook url>
@rachejazz
rachejazz / instance_logs.py
Created August 22, 2022 22:33
Retrieves logs from s3 bucket within the mentioned range of time and uploads it to sqs for display on kibana
import boto3
import json
import datetime
PREFIX = ""
client_1 = boto3.client('s3')
client_2 = boto3.client('sqs',
aws_access_key_id='KEY',
aws_secret_access_key='KEY'
)
@rachejazz
rachejazz / get_users.sh
Created August 22, 2022 22:31
Gets list of all users with access levels across gitlab organisation
#!/bin/bash
#Usage:
#./getusers.sh <TOKEN> <GROUP ID>
#
i=1
rm users ids final
while [[ $i -ne 10 ]]
do
curl -s --header "PRIVATE-TOKEN: $1" "https://gitlab.com/api/v4/groups/$2/projects?simple=true&order_by=last_activity_at&pagination=keyset&per_page=100&page=$i" | jq -r '.[]|.id' > ids
while read -r line
@rachejazz
rachejazz / s3_transfer.sh
Created August 22, 2022 22:30
transfers log files from an s3 bucket to another
#this script transfers log files from s3 bucket to desired remote server
DIR = '~/var/logs'
COPIED_TO = ''
ssh remote_user@<IP> find $DIR -maxdepth <max depth here> -mtime -$1 -mtime +$2 -type f > loglist.txt
while read -r line
do
rsync -chavzP --stats user@remote.host:$line $COPIED_TO
done < loglist.txt
aws s3 cp $COPIED_TO s3://bucket/ --recursive \
@rachejazz
rachejazz / get_list_repo.py
Created August 22, 2022 22:28
Creates a neat markdown table with info of creation date, last activity and web_url
#!/bin/python
import requests
import sys
import json
def getlist(token, page_no = 10):
group_id = ""
data = ""
data_json = []
data_list = []
@rachejazz
rachejazz / purge_stale_gcp_iam.py
Created August 22, 2022 22:26
Cleanups expired iam permissions older than one month of same year or older than current year
#!/usr/bin/env bash
set -e
cleanup() {
rm -f "$iam_output_file" "$jq_output_file"
}
trap 'cleanup' 0 1 2 15 # cleanup tmp files in case script ends upbruptly.
usage() { # Function: Print a help message
@rachejazz
rachejazz / user_disable_shortcut.sh
Last active August 22, 2022 22:58
Shortcut user management automation: Shortcut (formerly Clubhouse) is a type of project management application. This script helps in deactivating users in bulk using their api. (For educational purpose only. Not recommended for production use)
#!/bin/bash
### CREDS
email='user_email'
org_name='org'
echo 'from shortcut.com workspace web portal, go to inspect -> storage -> enter the following cookies'
echo 'Enter ajs_anonymous_id cookie: '
read ajs_anonymous_id
echo 'Enter ajs_user_id'
read ajs_user_id