Skip to content

Instantly share code, notes, and snippets.

@dannvix
dannvix / intercept-https-with-python-mitmproxy.md
Last active March 6, 2025 01:41
Intercept and manipulate HTTPs traffic with Python and mitmproxy

Intercepts HTTPs Traffic with Python & mitmproxy

Warning

This Gist is created in 2014, and it's highliy outdated now, according to one of mitmproxy's manjor contributor (check his comment below). Thanks for letting us know, @mhils!

Introduction

Modern applications usually make use of back-end API servers to provide their services. With a non-transparent HTTPs proxy, which intercepts the communication between clients and servers (aka the man-in-the-middle scheme), you can easily manipulate both API requests and responses.

@dannvix
dannvix / nginx-non-transparent-ssl-proxy.md
Last active October 16, 2023 19:07
Guide to set up nginx as non-transparent SSL proxy, which subsitutes strings in the server responses

Use nginx as Non-Transparent SSL Proxy

Introduction

Many mobile apps have back-end API servers. They usually rely on the API replies to determine whether certain information is supposed to be shown. If the API responses could be manipulated on the fly, we may easily fool an unmodified app to expose some private data.

This manual guides you to set up nginx as non-transparent SSL proxy, which just subsitutes strings in the server responses (i.e. man-in-the-middle attack ourself). For both server-side (their API servers) and client-side (your device), the whole process is almost transparent.

@dannvix
dannvix / i-dont-sponsor-facebook.user.js
Last active December 15, 2015 07:59
Userscript for automatically hiding "sponsored posts" (i.e. advertisements) on Facebook. Originally published on http://userscripts.org/scripts/show/160461 in Feb 2013
// ==UserScript==
// @name Facebook Sponsored Posts Cleaner
// @description Automatically Hides Sponsored Posts (Ads) in Facebook Stream
// @namespace http://facebook.example.org
// @author Shao-Chung Chen
// @license MIT (http://opensource.org/licenses/MIT)
// @version 1.3
// @include http://*.facebook.com/*
// @include https://*.facebook.com/*
//
@dannvix
dannvix / decorator.rb
Created March 2, 2013 12:20
Python style decorators for Ruby. Copied from github://michaelfairley/method_decorators
module MethodDecorators
class Decorator
@@current_decorators = []
def self.current_decorators
decs = @@current_decorators
@@current_decorators = []
decs
end
@dannvix
dannvix / nginx_sendfile.rb
Created February 19, 2013 01:28
nginx_sendfile() for streaming mp4 to Safari from Nginx + Passenger + Rails
# customized sendfile() implementation utilizing Nginx's X-Accel-* header options
# needed ecause Rails' built-in sendfile() generates chunked response without Content-Length,
# and Safari rufuses to player videos coming in chunks......
def nginx_sendfile (file_path, options={})
response.headers["Cache-Control"] = options[:cache_control] || "max-age=86400, public"
response.headers["Content-Disposition"] = options[:disposition] || "inline"
response.headers["X-Accel-Limit-Rate"] = options[:limit_rate] || "307200" # byte
response.headers["X-Accel-Buffering"] = options[:buffering] || "yes"
response.headers["X-Accel-Redirect"] = file_path
render :nothing => true
@dannvix
dannvix / sprintf.js
Created February 3, 2013 07:23
sprintf() implementation in JavaScript
function sprintf() {
var i = 0, a, f = arguments[i++], o = [], m, p, c, x, s = '';
while (f) {
if (m = /^[^\x25]+/.exec(f)) {
o.push(m[0]);
}
else if (m = /^\x25{2}/.exec(f)) {
o.push('%');
}
else if (m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) {
@dannvix
dannvix / www-proxy.c
Created January 30, 2013 06:47
very simple HTTP proxy server written by Steve Shipway
/* www-proxy.c Copyright Imperial Business Systems 1995
Proxy http server.
Written by Steve Shipway ([email protected],[email protected])
in the space of 2 hours. It took a further 1 hour to remove the last
bug. And 2 hours to persuade myself to stop playing with Netscape after it
was working.
Command line args:
-d : debug mode. Use port 8000 instead, dont background, status msgs
-l logfile : logfile to use
.item
width: 190px
position: absolute
.item:before
content: ''
width: 15px
height: 15px
@include border-radius(15px)
background: darken(white, 10%)
position: absolute
@dannvix
dannvix / bezier-curve.rb
Created December 24, 2012 12:42
simply draw Bezier curve and display, with RMagick
#!/usr/bin/env ruby
require 'RMagick'
include Magick
def tpow (t, pow_a, pow_b)
(t ** pow_a) * ((1 - t) ** pow_b)
end
# Bezier curve parameters
@dannvix
dannvix / PresentationMode.vim
Created April 21, 2012 12:52
toggle between working mode and presentation mode (for projection demo)
" toggle between working mode and presentation mode
function! PresentationModeOn()
set background=light
colorscheme github
set guifont=Monaco\ for\ Powerline:h28.00
endfunction
function! PresentationModeOff()
set background=dark