Skip to content

Instantly share code, notes, and snippets.

View khanzf's full-sized avatar

Farhan Khan khanzf

View GitHub Profile
@khanzf
khanzf / multisocket.c
Last active September 14, 2015 01:31
Multiserv
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <sys/socket.h>
@khanzf
khanzf / widget.html
Created September 14, 2015 04:41
Two Select Lists Widget
<!--
* Copyright 2003-2007 Farhan Khan
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
-->
<html>
<head>
# IPv4 with CIDR
re.match('^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(/(3[0-2]|2[0-9]|1[0-9]|[0-9]))?$', '192.0.2.0/24')
# IPv6 with CIDR
re.match('^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))(\/((1(1[0-9]|2[0-8]))|([0-9][0-9])|([0-9])))?$', '2001:DB8::/128')
# Host Name
re.match('^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Z
#!/usr/bin/python3
# Utilizing strong ciphers, TLSv1.2, strong everything
# Basically binds to your IPv6 Interfaces
# Change AF_INET6 to AF_INET for IPv4
import socket, ssl
ciphers = 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:AES256-GCM-SHA384:AES256-SHA256:AES256-SHA:ECDHE-RSA-AES256-GCM-SHA384'
@khanzf
khanzf / daemon.py
Created March 7, 2016 20:46
Fork-Based Daemon Process
# Basic skeleton of Daemon Fork-based daemon service
#
# It will accept a new socket connection, then trigger execute_cmd(). You
# can create a global variable to keep track of the child processes if you
# need to. This approach is sub-optimal, it should use select/poll on the
# accept() function, but this is python not C with a Posix interface. I am
# having the child process just do a simple "/bin/ls" as a proof of concept.
#
# Farhan Khan (khanzf@gmail.com)
AUTHENTICATION_BACKENDS = (
'django_auth_ldap.backend.LDAPBackend',
'django.contrib.auth.backends.ModelBackend',
)
import ldap
from django_auth_ldap.config import LDAPSearch, NestedActiveDirectoryGroupType
# Binding and connection options
AUTH_LDAP_SERVER_URI = "ldap://192.168.1.13"
[farhan@offmail ~]$ objdump -D -b binary -mi386 file
file: file format binary
Disassembly of section .data:
0000000000000000 <.data>:
0: e8 00 00 66 83 call 0x83660005
5: ec in (%dx),%al
6: 04 66 add $0x66,%al
# Just a little bit of code to prove to myself that I could actually write in assembly
# To run this, do:
# as code.s -o code.o ; ld code.o -o code ; ./code
# If you want to debug, run it with strace: strace ./code
# Setup a netcat listener on port 31337
# How to do a syscall: http://cs.lmu.edu/~ray/notes/linuxsyscalls/
# List of syscalls: https://filippo.io/linux-syscall-table/
.data
@khanzf
khanzf / draw.py
Last active March 30, 2017 21:29
Draw shape without picking up pen
#!/usr/bin/env python3
import copy
import sys
lines = {
1:[2,3],
2:[1,3,4,6,7],
3:[1,2,5,6,7],
4:[2,5,6,7],
@khanzf
khanzf / Makefile
Created August 25, 2017 04:26
FreeBSD taskqueue(9) example
SRCS=taskqueue_example.c
KMOD=taskqueue_example
.include <bsd.kmod.mk>