Skip to content

Instantly share code, notes, and snippets.

View whiler's full-sized avatar
🇨🇳

whiler whiler

🇨🇳
View GitHub Profile
@whiler
whiler / bits.py
Created August 21, 2019 08:27
Bitwise Operators in Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Ref. https://wiki.python.org/moin/BitwiseOperators
def setbit(i, x):
"""
set the bit at position x in integer i to 1
"""
@whiler
whiler / debug.log
Created December 4, 2019 07:37
TCP forward in python
python forward.py :8080 google.com:80
[INFO] 2019-12-04 15:37:12 CST ('127.0.0.1', 54949) -> ':8080' -> 'google.com:80'
[DEBUG] 2019-12-04 15:37:12 CST ('127.0.0.1', 54949) -> 79 bytes -> ('172.217.10.78', 80)
[DEBUG] 2019-12-04 15:37:13 CST ('172.217.10.78', 80) -> 724 bytes -> ('127.0.0.1', 54949)
curl -I -H 'Host: www.google.com' localhost:8080
HTTP/1.1 200 OK
Date: Wed, 04 Dec 2019 07:37:13 GMT
Expires: -1
@whiler
whiler / GEOIPAddressBlocks.md
Created January 21, 2020 09:53
GEO IP address block
@whiler
whiler / hmac-sha256.sh
Last active October 3, 2024 08:43
hmac sha256 encode with url safe base64 in bash shell
$ echo -en "message" | openssl dgst -sha256 -hmac "key" -binary | base64 | sed -e 's/+/-/g' -e 's/\//_/g' | tr -d =
bp7ym3X__Ft6uuUn1Y_a2y_kLnIZARl2kXNDBl9Y7Uo
@whiler
whiler / http-proxy.go
Last active May 19, 2020 14:26
HTTP Proxy in Golang
package main
import (
"context"
"flag"
"fmt"
"io"
"log"
"net"
"net/http"
@whiler
whiler / escape.sh
Last active December 27, 2022 21:46
escape string in bash shell
escape() {
sed -e 's/[]\/$*.^[]/\\&/g' <<<"${1}"
}
@whiler
whiler / utun.py
Last active March 26, 2024 16:19
open utun device in OS X
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# open utun device in OS X
# Refs:
# - https://github.com/python/cpython/blob/master/Modules/socketmodule.c
# - https://opensource.apple.com/source/xnu/xnu-4570.31.3/bsd/sys/kern_control.h.auto.html
# - https://opensource.apple.com/source/xnu/xnu-344.49/bsd/sys/sys_domain.h.auto.html
# - https://opensource.apple.com/source/xnu/xnu-2782.20.48/bsd/net/if_utun.h.auto.html
#
@whiler
whiler / hostcgi.go
Created May 21, 2020 17:02
host CGI in golang
package main
import (
"flag"
"fmt"
"log"
"net/http"
"net/http/cgi"
"os"
"path"
@whiler
whiler / new-instance.go
Created May 22, 2020 20:44
create new instance from pointer with reflect
// Ref. https://medium.com/capital-one-tech/learning-to-use-go-reflection-822a0aed74b7
package main
import (
"fmt"
"reflect"
)
func main() {
type CustomType struct {
@whiler
whiler / sniff_tls.go
Created August 28, 2020 10:26
sniff TLS hello information
package main
import (
"bytes"
"crypto/tls"
"io"
"net"
"time"
)