Skip to content

Instantly share code, notes, and snippets.

View HirbodBehnam's full-sized avatar

Hirbod Behnam HirbodBehnam

View GitHub Profile
@HirbodBehnam
HirbodBehnam / ipv6-rotate.sh
Created May 17, 2024 08:20
Rotate your server's IPv6
#!/bin/bash
# Put it in crontab: */5 * * * * /bin/bash /root/scripts/ipv6-rotate.sh
# Get the next IPv6
CURRENT_IP=$(cat ~/.config/rotate-ip)
NEXT_IP=$(((CURRENT_IP+1)%65534))
echo "$NEXT_IP" > ~/.config/rotate-ip
CURRENT_IP=$(printf "%x" "$CURRENT_IP")
NEXT_IP=$(printf "%x" "$NEXT_IP")
CURRENT_IP="x:x:x::$CURRENT_IP"
NEXT_IP="x:x:x::$NEXT_IP"
@HirbodBehnam
HirbodBehnam / cargo-config.toml
Last active May 10, 2024 13:11
The Cargo config file I use for cross compiling
# Place this file as $CARGO_HOME/config.toml
# Run this command before compiling anything to install compilers
# apt install apt install gcc-x86-64-linux-gnu gcc-aarch64-linux-gnu gcc-mingw-w64
[target.x86_64-unknown-linux-musl]
linker = "rust-lld"
[target.aarch64-unknown-linux-musl]
linker = "rust-lld"
@HirbodBehnam
HirbodBehnam / tcp-syn.py
Created April 29, 2024 20:14
Send a TCP syn using raw sockets
from socket import *
import struct
import random
def get_checksum(data: bytes) -> int:
sum = 0
for index in range(0, len(data), 2):
word = (data[index] << 8) + (data[index+1])
sum = sum + word
sum = (sum >> 16) + (sum & 0xffff)
@HirbodBehnam
HirbodBehnam / nfa-to-dfa.py
Last active March 8, 2024 07:23
Convert NFA to DFA and visualize it with networkx
import networkx as nx
import matplotlib.pyplot as plt
EPSILON = "e"
class NFA:
def __init__(self, alphabet: list[str], adjacency_list: list[dict[str, list[int]]]):
"""
@HirbodBehnam
HirbodBehnam / busy-init-live.sh
Last active October 2, 2023 08:17
Simple busybox init file
#!/bin/sh
mount -t devtmpfs none /dev
mount -t proc none /proc
mount -t sysfs none /sys
dmesg -n 1
echo "Welcome to CrowOS Live Linux (64-bit)!"
# Mount live CD to reallocate to it
echo "Mounting live volume..."
mkdir /livecd
mount UUID=6e422120-13ad-4a4d-b75e-02ab7757b3ae /livecd
@HirbodBehnam
HirbodBehnam / lock.c
Created December 13, 2022 20:14
Experimental semaphore with unix pipe
typedef struct {
int reader;
int writer;
} semaphore;
semaphore make_semaphore(int n) {
int pipe_fd[2];
pipe(pipe_fd);
semaphore result = {
.reader = pipe_fd[0],
@HirbodBehnam
HirbodBehnam / depot-downloader-splitter.sh
Created November 23, 2022 06:50
Split the files of a steam depot with maximum size of each group
#!/bin/bash
# A manifest file generated from https://github.com/SteamRE/DepotDownloader must be passed to the script.
# It should contain only the file lines.
# Use this script like bash depot-downloader-splitter.sh mainfest.txt 40000000000
rm part*.txt # remove old files
MAX_SIZE=$2 # maximum size of each part
CURRENT_SIZE=0
COUNTER=1
while read -r line; do
line=$(echo $line) # trim each column
@HirbodBehnam
HirbodBehnam / xstat.sh
Last active May 2, 2024 14:04
Get stats of xray in style
xray api statsquery --server=127.0.0.1:10085 | jq -r '.stat | (.[].value |= (. // "0" | tonumber)) | (.[].name |= split(">>>")) | group_by(.name[1]) | (.[] |= {download: (if .[0].name[3] == "downlink" then .[0].value else .[1].value end), upload: (if .[0].name[3] == "downlink" then .[1].value else .[0].value end), name: .[0].name[1], total: (.[0].value + .[1].value)}) | sort_by(.total) | reverse | .[] | .name + " ↓" + (.download / 1024 / 1024 | floor | tostring) + "MB ↑" + (.upload / 1024 / 1024 | floor | tostring) + "MB ↕" + (.total / 1024 / 1024 | floor | tostring) + "MB"' | column -t -s' '
@HirbodBehnam
HirbodBehnam / sni-block-check.go
Created September 29, 2022 06:08
Check if SNI is blocked with Golang
package main
import (
"crypto/tls"
"log"
"net"
)
const hostname = "www.google.com"
const request = "GET / HTTP/1.1\r\nHost: " + hostname + "\r\nConnection: close\r\n\r\n"
@HirbodBehnam
HirbodBehnam / meme-generator.sh
Last active September 3, 2022 16:22
A meme generator based on code of esmBot
#!/bin/bash
# This script is based on esmBot caption command. See code here: https://github.com/esmBot/esmBot/blob/master/natives/caption.cc
# It needs ffmpeg + ffprobe + vips installed. The meme is created with dark mode caption
# I used vips 8.13 and ffmepg build of 2022-06-16
# It must be used like this: bash meme-generator.sh template.png "my caption of meme"
# Font is also available at https://github.com/esmBot/esmBot/blob/master/assets/caption.otf
WIDTH=$(ffprobe -v error -select_streams v -show_entries stream=width -of csv=p=0:s=x "$1")
FONT_SIZE=$((WIDTH/10))
vips text caption.png "<span foreground=\"white\" background=\"black\">$2</span>" --width $WIDTH --font "futura bold $FONT_SIZE" --align centre --rgba
ffmpeg -i caption.png -vf "pad=$WIDTH:ih+$FONT_SIZE:(ow-iw)/2:(oh-ih)/2" caption2.png