Skip to content

Instantly share code, notes, and snippets.

View khanzf's full-sized avatar

Farhan Khan khanzf

View GitHub Profile
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <machine/cpufunc.h>
int main() {
/* Opening /dev/io grants the process permission to use outb/inb
instructions on FreeBSD x86/amd64 systems. */
int fd = open("/dev/io", O_RDWR);
if (fd == -1) {
@khanzf
khanzf / userframe.c
Created April 4, 2025 21:17
Create a beacon frame in userspace
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#define IEEE80211_ADDR_LEN 6
#define IEEE80211_ELEMID_SSID 0
#define IEEE80211_ELEMID_RATES 1
# 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
@khanzf
khanzf / Makefile
Created August 25, 2017 04:26
FreeBSD taskqueue(9) example
SRCS=taskqueue_example.c
KMOD=taskqueue_example
.include <bsd.kmod.mk>
@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"
#include <sys/stat.h>
#include <stdio.h>
#include <stdint.h>
int main() {
printf("struct stat: %lu\n", sizeof(struct stat));
printf("struct stat->st_dev %lu\n", sizeof(unsigned long));
printf("struct stat->ctime_nsec: %lu\n", sizeof(unsigned long));
printf("unsigned long: %lu\n", sizeof(unsigned long));
printf("uint64_t: %lu\n", sizeof(uint64_t));
@khanzf
khanzf / shatest.c
Last active October 3, 2018 04:15
SHA1 on BSD
// Compiled on BSD with cc shatest.c -o shatest -lmd
#include <sys/types.h>
#include <string.h>
#include <stdio.h>
#include <sha.h>
#define HEX_DIGEST_LENGTH 257
int
@khanzf
khanzf / wifi_channel.d
Created July 3, 2018 07:03
dtrace to check wifi channel
#!/usr/sbin/dtrace -qs
/*
* Run with sudo ./tap_function.d -q
*/
struct ieee80211_channel {
uint32_t ic_flags; /* see below */
uint16_t ic_freq; /* primary centre frequency in MHz */
uint8_t ic_ieee; /* IEEE channel number */
#!/usr/bin/env python3
'''
Recursively downloads Debian/Ubuntu/Kali packages and all associated dependencies
By: Farhan Khan (Farhan_Khan@McAfee.com) (khanzf@gmail.com)
You MUST run this on the same distribution AND version of the target system.
This only downloads the latest version of the package available within the
target distribution.
Download a single package: