Skip to content

Instantly share code, notes, and snippets.

View khanzf's full-sized avatar

Farhan Khan khanzf

View GitHub Profile
#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:
@khanzf
khanzf / tap_function.d
Last active November 12, 2017 02:44
Dtrace and Systemtap scripts used to see what happens between functions
#!/usr/sbin/dtrace -qs
/*
* Run with sudo ./tap_function.d -q
*/
dtrace:::BEGIN
{
self->start = 0;
printf("Start on\t%s\n", "r92c_scan_start");
@khanzf
khanzf / rom.c
Last active November 11, 2017 06:27
rtl8188ee rom breakdown
#include <stdint.h>
#include <stdio.h>
#define IEEE80211_ADDR_LEN 6
uint8_t rom[] = {
0x29, 0x81, 0x0, 0x6c, 0xb, 0x0, 0x0, 0x0,
0x0, 0xc, 0x40, 0x0, 0x10, 0x0, 0x0, 0x0,
0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x2c, 0x2b,
0x2a, 0x29, 0x29, 0x2, 0xff, 0xff, 0xff, 0xff,
@khanzf
khanzf / ioctls.c
Created November 8, 2017 19:04
Ugly code prints network ioctl values for tracing the kernel
// Compile as follows:
// cc -Wno-everything ioctls.c -o ~/ioctls && echo Wow it actually compiled!
#include <net/if.h>
#include <sys/types.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <net/if_var.h>
#include <netinet/in.h>
@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 / 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],
# 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