Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View ei-grad's full-sized avatar

Andrew Grigorev ei-grad

View GitHub Profile
package main
import (
"bytes"
"context"
"fmt"
"io"
"log"
"net/http"
"os"
@ei-grad
ei-grad / refresh-session-token.py
Created February 27, 2024 18:13
Maintain AWS temporary credentials with Yubikey as MFA and `pass` to store static secret key
#!/usr/bin/env python
"""
This script is used to refresh the session token for the AWS CLI.
It maintains credentials in the AWS_SHARED_CREDENTIALS_FILE file, and
refreshes the session token when it is about to expire.
It relies on the following tools:
- pass: a password manager
@ei-grad
ei-grad / draw-projected
Last active February 22, 2024 11:59
Draw OSM geometries over each other projected to 1km units
#!/usr/bin/env python
#
# Draw OSM geometries over each other projected to 1km units
#
# Install requirements:
# pip install osmnx matplotlib
#
# Usage:
# draw-projected "Cyprus island" "RU-MOW"
#
@ei-grad
ei-grad / radiusd.conf
Last active January 12, 2024 22:18
FreeRadius configuration for WiFi WPA2/3 Enterprise EAP TLS
name = radiusd
prefix = ""
logdir = "/var/log/radius"
run_dir = "/var/run/radiusd"
libdir = "/usr/lib/freeradius"
debug_level = 2
proxy_requests = no
raddbdir = "/etc/raddb"
certdir = "${raddbdir}/certs"
@ei-grad
ei-grad / get-cf-records
Created January 2, 2024 14:59
Script to fetch list of all cloudflare DNS records
#!/bin/bash
cf_api_fetch() {
curl -s "https://api.cloudflare.com/client/v4/$1" \
-H "X-Auth-Email: $CLOUDFLARE_EMAIL" \
-H "X-Auth-Key: $CLOUDFLARE_API_KEY" \
| jq -r "$2"
}
for zone_id in $(cf_api_fetch "zones" '.result[] | .id'); do
@ei-grad
ei-grad / beamforming.py
Created July 7, 2023 13:38
Example of ~realtime audio processing in Python. Pretending to be a beamforming noise-cancellation, but doing something strange actually.
import threading
import logging
from numpy.fft import fft, ifft
import numpy as np
import jack
def denoice(left, right):
fft_l = fft(left)
@ei-grad
ei-grad / solve.py
Created June 29, 2023 15:33
SPbCTF - iZba
import sys
import random
import requests
http = requests.Session()
http.cert = 'client.pem'
base_url = 'https://its-izba-4ncvjm8.spbctf.ru:13443'
@ei-grad
ei-grad / exact_size_chunks_iter.py
Last active October 6, 2023 18:58
Generator function that efficiently transforms an iterator yielding data chunks of arbitrary sizes into an iterator yielding chunks of a specified exact size, except possibly for the last chunk.
from typing import TypeVar, Iterable, Generator, Callable, cast, Sequence
T = TypeVar('T', bound=Sequence)
def exact_size_chunks_iter(
chunks_iter: Iterable[T],
chunk_size: int,
concat: Callable[[Iterable[T]], T] = cast(Callable[[Iterable[T]], T], b''.join),
@ei-grad
ei-grad / ubuntu-install-docker.sh
Last active June 9, 2023 10:28
Small snippet to install docker in ubuntu
#!/bin/bash
ARCH="$(dpkg --print-architecture)"
CODENAME="$(. /etc/os-release && echo "$VERSION_CODENAME")"
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor > /etc/apt/trusted.gpg.d/docker.gpg
echo "deb [arch="$(dpkg --print-architecture)"] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" \
> /etc/apt/sources.list.d/docker.list
[sources.journald]
type = "journald"
[transforms.remove_systemd_fields]
type = "remap"
inputs = ["journald"]
source = '''
del(._BOOT_ID)
del(._CAP_EFFECTIVE)
del(._CMDLINE)