Skip to content

Instantly share code, notes, and snippets.

@jix
jix / main.rs
Created January 29, 2022 17:09
Lifetime GAT emulation on stable rust
// This is a technique to emulate lifetime GATs (generic associated types) on stable rust starting
// with rustc 1.33.
//
// I haven't seen this exact technique before, but I would be surprised if no one else came up with
// it. I think this avoids most downsides of other lifetime GAT workarounds I've seen.
//
// In particular, neither implementing nor using traits with emulated lifetime GATs requires adding
// any helper items. Only defining the trait requires a single helper trait (+ a single helper impl
// for the 2nd variant) per GAT. This also makes the technique viable without any boilerplate
// reducing macros.
@chrisdone
chrisdone / gist:02e165a0004be33734ac2334f215380e
Last active April 7, 2024 19:40
Build and run minimal Linux / Busybox systems in Qemu

Common

export OPT=/opt
export BUILDS=/some/where/mini_linux
mkdir -p $BUILDS

Linux kernel

@jaysonsantos
jaysonsantos / main.rs
Last active September 23, 2023 18:44
rust ring example
extern crate ring;
use ring::aead::*;
use ring::pbkdf2::*;
use ring::rand::SystemRandom;
fn main() {
// The password will be used to generate a key
let password = b"nice password";
@awjuliani
awjuliani / Q-Table Learning-Clean.ipynb
Last active October 25, 2022 07:57
Q-Table learning in OpenAI grid world.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@noahwilliamsson
noahwilliamsson / hostapd.conf
Created November 5, 2015 22:48
WPA-EAP (Enterprise) configuration for hostapd
interface=wlan0
# --------------------------------------
bss=wlan1
ssid=EAP
# IEEE 802.11 specifies two authentication algorithms. hostapd can be
# configured to allow both of these or only one. Open system authentication
# should be used with IEEE 802.1X.
# Bit fields of allowed authentication algorithms:
# bit 0 = Open System Authentication
@2bard
2bard / mitmproxy cheat sheet
Created February 13, 2015 19:44
mitmproxy cheat sheet
Movement:
j, k down, up
h, l left, right (in some contexts)
space page down
pg up/down page up/down
arrows up, down, left, right
# -*- coding: utf-8 -*-
#!/usr/bin/env python
#
#__author__= 'ihciah@gmail.com'
import urllib,urllib2
def login(username, password):
url="http://10.108.255.249/include/auth_action.php"
data={"username": username,
@klzgrad
klzgrad / Naive-VPN.md
Created November 17, 2014 00:43
朴素VPN:一个纯内核级静态隧道

朴素VPN:一个纯内核级静态隧道

由于路由管控系统的建立,实时动态黑洞路由已成为最有效的封锁手段,TCP连接重置和DNS污染成为次要手段,利用漏洞的穿墙方法已不再具有普遍意义。对此应对方法是多样化协议的VPN来抵抗识别。这里介绍一种太简单、有时很朴素的“穷人VPN”。

朴素VPN只需要一次内核配置(Linux内核),即可永久稳定运行,不需要任何用户态守护进程。所有流量转换和加密全部由内核完成,原生性能,开销几乎没有。静态配置,避免动态握手和参数协商产生指纹特征导致被识别。并且支持NAT,移动的内网用户可以使用此方法。支持广泛,基于L2TPv3标准,Linux内核3.2+都有支持,其他操作系统原则上也能支持。但有两个局限:需要root权限;一个隧道只支持一个用户。

朴素VPN利用UDP封装的静态L2TP隧道实现VPN,内核XFRM实现静态IPsec。实际上IP-in-IP隧道即可实现VPN,但是这种协议无法穿越NAT,因此必须利用UDP封装。内核3.18将支持Foo-over-UDP,在UDP里面直接封装IP,与静态的L2TP-over-UDP很类似。

创建一个朴素VPN

@madeye
madeye / sysctl.conf
Last active June 5, 2018 11:05
Optimized sysctl.conf for shadowsocks
net.core.wmem_max = 12582912
net.core.rmem_max = 12582912
net.ipv4.tcp_rmem = 10240 87380 12582912
net.ipv4.tcp_wmem = 10240 87380 12582912
net.ipv4.ip_local_port_range = 18000 65535
net.ipv4.netfilter.ip_conntrack_tcp_timeout_time_wait = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_max_syn_backlog = 3240000
net.core.somaxconn = 3240000
net.ipv4.tcp_max_tw_buckets = 1440000