Skip to content

Instantly share code, notes, and snippets.

Avatar
😸
use code::latest ;

GAURAV gauravssnl

😸
use code::latest ;
View GitHub Profile
@gauravssnl
gauravssnl / redirect-follower.py
Created Aug 19, 2022 — forked from FiloSottile/redirect-follower.py
Script to follow HTTP redirects and print the resulting URL - a.k.a. URL un-shortener
View redirect-follower.py
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import sys
import urllib2
# This script uses HEAD requests (with fallback in case of 405)
# to follow the redirect path up to the real URL
# (c) 2012 Filippo Valsorda - FiloSottile
# Released under the GPL license
@gauravssnl
gauravssnl / HEAD-request.py
Created Aug 19, 2022 — forked from FiloSottile/HEAD-request.py
How to send a HEAD HTTP request in Python with urllib2
View HEAD-request.py
import urllib2
class HeadRequest(urllib2.Request):
def get_method(self):
return "HEAD"
class HEADRedirectHandler(urllib2.HTTPRedirectHandler):
"""
Subclass the HTTPRedirectHandler to make it use our
HeadRequest also on the redirected URL
@gauravssnl
gauravssnl / example.py
Created Aug 19, 2022 — forked from FiloSottile/example.py
Python function to check a RSA signature
View example.py
# http://stuvel.eu/files/python-rsa-doc
# You can `pip install rsa`
import rsa
### KEY GENERATION ###
### Run once, on your dev environment
### Store the private key in a secure place; add the pubkey to your program
(pubkey, privkey) = rsa.newkeys(1024)
View combinations.go
func combinations(n, m int, f func([]int)) {
// For each combination of m elements out of n
// call the function f passing a list of m integers in 0-n
// without repetitions
// TODO: switch to iterative algo
s := make([]int, m)
last := m - 1
var rc func(int, int)
rc = func(i, next int) {
@gauravssnl
gauravssnl / fizzbuzz.c
Created Aug 19, 2022 — forked from grantslatton/fizzbuzz.c
FizzBuzz solved using only bit twiddling. It essentially uses two deterministic finite automata for divisibility testing.
View fizzbuzz.c
#include <stdio.h>
int f0(unsigned int x) { return x? (x&(1<<31)? f1(x<<1) : f0(x<<1)) : 1; }
int f1(unsigned int x) { return x? (x&(1<<31)? f3(x<<1) : f2(x<<1)) : 0; }
int f2(unsigned int x) { return x? (x&(1<<31)? f0(x<<1) : f4(x<<1)) : 0; }
int f3(unsigned int x) { return x? (x&(1<<31)? f2(x<<1) : f1(x<<1)) : 0; }
int f4(unsigned int x) { return x? (x&(1<<31)? f4(x<<1) : f3(x<<1)) : 0; }
int t0(unsigned int x) { return x? (x&(1<<31)? t1(x<<1) : t0(x<<1)) : 1; }
int t1(unsigned int x) { return x? (x&(1<<31)? t0(x<<1) : t2(x<<1)) : 0; }
int t2(unsigned int x) { return x? (x&(1<<31)? t2(x<<1) : t1(x<<1)) : 0; }
View hngen.py
import urllib2
import re
import sys
from collections import defaultdict
from random import random
"""
PLEASE DO NOT RUN THIS QUOTED CODE FOR THE SAKE OF daemonology's SERVER, IT IS
NOT MY SERVER AND I FEEL BAD FOR ABUSING IT. JUST GET THE RESULTS OF THE
CRAWL HERE: http://pastebin.com/raw.php?i=nqpsnTtW AND SAVE THEM TO "archive.txt"
View HookHandler.py
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import BaseHTTPServer
import sys
import time
import urlparse
import json
@gauravssnl
gauravssnl / 32.asm
Created Aug 19, 2022 — forked from FiloSottile/32.asm
NASM Hello World for x86 and x86_64 Intel Mac OS X (get yourself an updated nasm with brew)
View 32.asm
; /usr/local/bin/nasm -f macho 32.asm && ld -macosx_version_min 10.7.0 -o 32 32.o && ./32
global start
section .text
start:
push dword msg.len
push dword msg
push dword 1
mov eax, 4
@gauravssnl
gauravssnl / unchroot.c
Created Aug 19, 2022 — forked from FiloSottile/unchroot.c
Code for my article about chroot jail escaping
View unchroot.c
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
int main() {
int dir_fd, x;
setuid(0);
mkdir(".42", 0755);
dir_fd = open(".", O_RDONLY);
chroot(".42");
View gist:dccb80ebadafedafaf73e784571acaca
➜ ~ openssl s_client -servername filippo.io -connect filosottile.github.io:443
CONNECTED(00000003)
depth=1 /C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert SHA2 High Assurance Server CA
verify error:num=20:unable to get local issuer certificate
verify return:0
---
Certificate chain
0 s:/C=US/L=San Francisco/ST=California/O=Fastly, Inc./CN=www.github.com
i:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert SHA2 High Assurance Server CA
1 s:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert SHA2 High Assurance Server CA