Skip to content

Instantly share code, notes, and snippets.

View teknoraver's full-sized avatar
🖥️
coding

Matteo Croce teknoraver

🖥️
coding
View GitHub Profile
@teknoraver
teknoraver / memflood.c
Last active November 24, 2025 12:53
Allocates memory and trigger pgscan activity
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
void allocate_memory(size_t gb)
{
size_t bytes = gb * 1024 * 1024 * 1024ULL;
size_t pgsize = sysconf(_SC_PAGESIZE);
unsigned char *ptr = malloc(bytes);
@teknoraver
teknoraver / unixdump.rs
Last active November 19, 2025 17:42
Dump UNIX sockets to standard output
use std::env;
use std::fs;
use std::io::{self, Read, Write};
use std::os::unix::fs::PermissionsExt;
use std::os::unix::net::{UnixListener, UnixStream};
use std::path::Path;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::thread;
@teknoraver
teknoraver / unixdump.go
Last active November 19, 2025 17:35
Dump UNIX sockets to standard output
package main
import (
"fmt"
"io"
"net"
"os"
"os/signal"
"sync"
"syscall"
@teknoraver
teknoraver / bpf_capa_calc.py
Last active September 29, 2025 11:37
calculate the minimum BPF features needed to run a program
#!/usr/bin/env python3
import subprocess
import sys
cmds = [
"BPFMapCreate", "BPFMapLookupElem", "BPFMapUpdateElem", "BPFMapDeleteElem",
"BPFMapGetNextKey", "BPFProgLoad", "BPFObjPin", "BPFObjGet",
"BPFProgAttach", "BPFProgDetach", "BPFProgTestRun", "BPFProgGetNextId",
"BPFMapGetNextId", "BPFProgGetFdById", "BPFMapGetFdById",
"BPFObjGetInfoByFd", "BPFProgQuery", "BPFRawTracepointOpen",
@teknoraver
teknoraver / bpffs.c
Last active July 17, 2025 01:11
Sample code to mount a bpffs filesystem with delegates
/* run as:
* gcc -O2 -Wall bpffs.c -o bpffs
* sudo strace -f -e fsopen,fsconfig,fspick,fsmount,move_mount,unshare ./bpffs
*/
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
@teknoraver
teknoraver / bpf_token.c
Last active July 16, 2025 18:07
Sample tool to create a BPF token
/* run as:
* gcc -O2 -Wall bpf_token.c -o bpf_token -lbpf
* sudo strace -f -e fsopen,fsconfig,fspick,fsmount,move_mount,unshare,bpf ./bpf_token
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@teknoraver
teknoraver / parentdev.c
Last active July 9, 2025 09:53
Get the parent device of a partition
/*
* 3-Clause BSD NON-AI License
*
* Copyright 2025 Matteo Croce
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
*
/*
* membench.c - simple memory benchmarking tool
* Copyright (C) 2020 Matteo Croce <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
@teknoraver
teknoraver / testalign.c
Last active November 29, 2024 00:48
test block size of FICLONERANGE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <linux/fs.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
int setup_src(const char *path, size_t size)
{
@teknoraver
teknoraver / ghclone
Created August 8, 2024 11:06
Clone a GitHub repo and, if it's a fork, setup the upstream as remote
#!/bin/sh
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <git-repo-url>"
exit 1
fi
url=$1
repo=$url