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 / neighbour2.c
Created July 24, 2020 18:38
This is process 2: He wants to finish the fight with his neighbour once and for all, thus gives the user the choice of action.
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
/*the tree is made to demonstrate some time lapse after the user inputs the action.
After the user input the process will TAKE SOMETIME to send the signal through shared memory route*/
@rachejazz
rachejazz / neighbour1.c
Last active July 25, 2020 11:16
This is process 1: He is annoying and will only stop once it receives a signal from his neighbour.
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
/*If he causes any problem, do a `kill -9 <Neighbour ID> on a separate terminal.*/
@rachejazz
rachejazz / main.py
Last active March 14, 2022 21:28
Keka Reminder Telegram Bot. Is a telegram scheduler bot that can be used to send timely messages into chats/groups as desired
import logging
import pytz
import datetime
from telegram import Update
from telegram.ext import Updater, CommandHandler, CallbackContext
API_KEY = "API TOKEN"
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO
@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 / 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 / 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_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 / 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 / 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 / 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.
"""