RSSAmplifier

Blog

blog.farhan.codes

Recent content on blog.farhan.codes

blog.farhan.codesRSS feed ↗41 posts

Latest posts

Container Primitives - Linux Namespaces

Container technology revolutionized software development and deployment, enabling unprecedented levels of efficiency, scalability, and consistency across computing environments. They allow for greater server density by avoiding rerunning a resource hungry second operating system within a virtual machine. And while Docker leaders the pack, there are numerous other implementations that all conform…

BSD WiFi Buffer Management

FreeBSD (and all systems using net80211) utilize memory buffers to receive, manipulate and process network traffic. These buffers
are pre-allocated during attachment, due to the performance cost associated with dynamic allocation, and utilize a single-linked
 queue(3) structure. 
 Devices utilize two buffer queues, Rx and Tx. The underlying structure is often the same. 
 Receive…

Power Management During Driver Development Environment

You can use Power Per Port Switch (PPPS) functionality to power-cycle a USB device during driver development. 
 Introduction to the Problem 
 To reduce my hardware footprint, I typically work on device driver development in a VM running on the same multi-use personal system that houses my notes, files, picture backup, etc. This works fine for general development if the kernel crashes often…

Debugging a running FreeBSD kernel in a VM using kgdb

Using KGDB Remote Debugging for FreeBSD VMs 
 This guide explains how to debug a running FreeBSD kernel in a VM using kgdb . The default ddb debugger has decent functionality, but unless you somehow know dynamic memory addresses, those capabilities are effectively unusable. Conversely, kdb offers a more robust interface and set of features. 
 While there is a handbook section on kgdb , it…

Sarf Generator

I’m making available a Arabic word conjugator tool I wrote in TypeScript. It is located here https://sarf.farhan.codes . Aside from the basics, it takes into account some foundational rules of تعللات (special conjugation of certain letters) 
 There is some stuff its missing, such as repeating letters or edge-cases, but its a good general tool that I use myself when I’m confused. It…

Benchmarking Base32 vs Base64

This is a very rudimentary benchmark of Base32 vs Base64 performance in Golang. This should also serve as an example of Golang’s benchmarking toolchain. Conclusion: Base64 is faster. 
 This code works by creating 1000 test strings, then performing Base32 and Base64 conversions. Timing is done by Go’s built-in benchmarking tooling, which is part of the testing framework. Here is the…

Let IRC Die

For the sake of progress, let IRC die! 
 IRC was great, but its continued usage is a relic of an older internet, when storage was expensive and servers were expensive. At this stage, communities should migrate off of IRC to slack-like solutions like Mattermost or Matrix. 
 IRC served as a workhorse for communication, but it has failed to adapt to modern demands. In particular: 
 
…

Simple dtrace use-case

Very small example of using dtrace , mostly for me to refernece in the future. 
 As I port this wifi card, I am running into a situation where ifconfig is
reporting an error that I do not understand. From previous reading, I know that
 ifconfig interfaces with the kernel through ioctl . Driver code initially
handles ioctl requests by implementing the ic->ic_ioctl handler. 
 To…

My FreeBSD Development Environment

I’m writing this primarily for myself, but also for others to reference and improve upon. 
 I run FreeBSD CURRENT in a VM. I use a VM for the inevitable situation where it crashes. I prefer to use Qemu on KVM, almost exclusively because of the ease of using the graphical virt-manager over ssh, and the ease of rebooting. 
 FreeBSD cannot do crash dumps to VT disks (vtdb0) so I make…

Rebuilt This Blog

I rebuilt this blog after a few months of having it down. 
 Long story short, I ran the blog off of WordPress and self-hosted on my personal server for years. When I moved into a house and migrated off my personal server, I somehow lost the wp_content.sql file, and only that file, somewhere in the mix. An accidental deletion? Who knows. So all posts died. Bummer. Fortunately, I was able to…

Unexpected IPv6 Behavior on Linux

Linux has some strange default IPv6 behavior. Here are a few things I noticed… 
 You can bind to a port on an IPv4 address while all of your tools will report that the port is on IPv6. For example, if your host is 198.51.100.1, you can bind to ::FFFF:198.51.100.1 and all state-checking tools like netstat, ss or lsof will report the listener as on an IPv6-port. You can do this in netcat with nc…

Capturing Input/Output of Another Process in C

In my travels in C programming, I periodically need to run another process and redirect its standard output back to the first process. While it is straight forward to perform, it is not always obvious. This article will explain the process of how this is done in three sections. 
 
 High Level Overview 
 Explanation of each line 
 Code Sample 
 
 High Level Overview 
…

Avoiding Redundancy with Function Pointers

I am currently writing OpenGit, a BSD-licensed re-implementation of Linus Torvald’s Git (lower-cased going forward). This frequently involves reviewing git’s source code to understand how it works under the hood. One of the things I consistently encounter is git performing similar and sizable tasks in multiple different ways and places, resulting in redundancy and a higher maintenance cost. 
…

Generating a "vanity" PGP Key ID Signature

Here’s a quick bash script I used to generated a “vanity” PGP key with the last two bytes (four characters) set to FFFF. &#xA; #!/usr/bin/env bash&#xA; &#xA; while :&#xA; do &#xA; gpg --debug-quick-random -q --batch --gen-key << EOF&#xA; Key-Type: RSA&#xA; Key-Length: 2048&#xA; Name-Email: user@domain&#xA; Name-Real: Real Name&#xA; Passphrase: yourverylongpassphrasegoeshere&#xA; EOF &#xA; &#xA; if…

Passing by Reference, C&#39;s Garbage Collection

The C programming language has no built-in garbage-collection mechanism – and it very likely never will. This can (and does) lead to memory leaks by even the best programmers. It is also an imputes for the Rust language. However, depending on your use-case, it is still possible to structure your code to use the stack as a sort of zero-cost “garbage collector”. &#xA; Lets jump directly into the…

SHA1 on FreeBSD Snippet

I needed some code that produces SHA1 digests for a project I am working on. I hunted through the FreeBSD’s sha1(1) code and produced this minimal snippet. Hopefully this helps someone else in the future.

Including optimized-out kernel symbols in dtrace on FreeBSD

Warning: This is a hack that involves modifying the build scripts. tldr; modify /usr/src/sys/conf/kern.pre.mk to change all references of -O2 to -O0. &#xA; Have you ever had dtrace(1) on FreeBSD fail to list a probe that should exist in the kernel? This is because Clang will optimize-out some functions. The result is ctfconvert(1) will not generate debugging symbols that dtrace(1) uses to identify…

Linux maintains bugs, The real reason ifconfig on Linux is deprecated

In my third installment of FreeBSD vs Linux, I will discuss underlying reasons for why Linux moved away from ifconfig(8) to ip(8). &#xA; In the past, when people said, “Linux is a kernel, not an operating system”, I knew that was true but I always thought it was a rather pedantic criticism. Of course no one runs just the Linux kernel, you run a distribution of Linux. But after reviewing userland…

fsync(2) on FreeBSD vs Linux

Even with our modern technology, hard-disk operations tend to be the slowest and most painful part of any modern system. As such, modern operations implement buffering mechanism. In this schema, when an application calls write(2), rather than immediately performing physical disk operations, the operating stores data in a kernel buffer. When the buffer exceeds a certain amount or the when an…

Tracing ifconfig commands from userspace to device driver

I am currently working on expanding FreeBSD’s rtwn(4) wireless device driver. I have the basics down, such as initialization, powering on and off, loading the firmware, etc, and am now trying to fill in specific ifconfig(8) methods. This requires having an in depth knowledge of how ifconfig(8) commands pass are ultimately delivered to the driver. I could not find concise documentation that…

That time I Reverse-Engineered the Motorola CBEP Protocol

This is the tale of how I reverse-engineered a Motorola CPS radio protocol to make it work on Linux. While this may have been of questionable legality and thus lost interest in the project, I learned a lot on how to reverse engineer. I’m writing this entry more than a year after I initially did this, so I may be a little rusty on the details, but this is the gist of it.

Migrating from FreeNAS to FreeBSD

I love FreeNAS. Its awesome, well built, well-supported. But as my needs increased, I wanted to use my FreeNAS box for more than the basics. In particular, I was moving towards a single host to run as a: &#xA; &#xA; Family NAS server &#xA; Development server &#xA; IRC client &#xA; VM server &#xA; Web server &#xA; Email Server &#xA; Git Server &#xA; Home Firewall &#xA; Home IPv6 gateway &#xA; IPv6…

FreeBSD kernel Makefile variables SRCTOP and SYSDIR

I am currently writing a FreeBSD device driver and find myself lugging around the entire src. As you can imagine, this is quite large, especially if you are using any sort of version tracking system. So following the example here , I extracted out: &#xA; /usr/src/sys/modules/rtwn/&#xA;/usr/src/sys/dev/rtwn/&#xA; into &#xA;…

Switched from Ubuntu-based to Fedora

tl;dr: Fedora’s debugging packages work, Ubuntu’s are out of date. &#xA; Linux = Linux = Linux, whether Arch or Slackware or Ubuntu or OpenSUSE or Linux from scratch as I once did (before there were instructions!). Unless and until the kernel forks and someone decides to modify the syscall table, they all use the same basic syscalls, they typically share the same basic libraries and core…

Custom Kernel Modules for Chromebook

Note: I wrote this about a year and a half ago, but I refer to it all the time. Hopefully the instructions have not changed too much! Enjoy! &#xA; I recently purchased a Chromebook. It’s great, it symbolizes the direction the PC market should head – inexpensive, low-powered ARM processor, defense in depth resistance to malware and simple for non-technical users. And with crouton, it functions…

Draw this shape without picking up your pen

For many years, while in a meeting or in a moment of free time, I have tried to draw this shape without picking up my pen or drawing over the same two points twice. &#xA; At best I would get 1 line away, but never completed the shape. &#xA; I wanted to know if it was even possible. So I wrote some python code to try every possible combination. &#xA; But, the code is below.

FreeBSD and Linux Remote Dual Booting

The following is a quick and dirty guide on how to setup remote dual booting for FreeBSD (12.0-CURRENT) and Linux (Ubuntu 16.04). Granted, this method is slightly a hack, but it works and suits my needs. &#xA; * Why remote dual-booting? I am currently developing a FreeBSD kernel module for a PCIe card. The device is supported on Linux and I am using the Linux implementation as documentation. As…

My Python3 Programming Environment

UPDATE: I have since started using a very good vimrc . I recommend it over mine listed below. My only modification is that I removed all line numbers, eww. &#xA; I ssh into a FreeBSD jail with everything setup. &#xA; The Jail runs on code.mydomainname.com, which has an internet-routable IPv6 address – and IPv4 behind a NAT, (boo!) &#xA; I have a virtualenv already built-out. (more about my pip…

Hotspot Hijacking & Password Capturing

There are two types of penetration testers in the industry. &#xA; Those who identify risk and vulnerabilities beyond a simple Nexpose/Nessus/Qualys scan. And those who want to “win”. &#xA; The job of the “winner” is to get DA on their client’s network. Great! But once they’ve gotten it, they show off. Look how much information I can get with the DA account! I can get access to these databases and…

Easytether running on ARMv7l Chromebook

Easytether is a proprietary application, so you can’t just apt-get it on a chroot’ed crouton environment. Additionally, I am not running an x86 or x64 CPU, so most of these packages will not work. &#xA; Crouton mostly comes for Debian, so I downloaded the Ubuntu package. I installed the package ‘alien’. Then unzipped the deb file as follows: &#xA; alien easytether_0.8.5-1_armhf.deb&#xA; This will…

Differences between Mint and Ubuntu

I looked into the differences between Mint and Ubuntu to see which was best for me. I watched tons of videos, reviews, comparisons, ran them both for months, etc. Here’s what I learned… &#xA; They’re the same damn thing. No really, they are identical. The only differences are what software comes pre-installed and some user interface prettiness. Otherwise, no difference in the underlying system at…

Adding Arbitrary XML to python-docx

I am thankful to the developers of python-docx, they did a great job, especially since OpenXML is beyond confusing. However, I have two respectful criticisms: Python-docx lacks several key features and though it is properly written…its really confusing to follow the code. &#xA; Its just a few steps. Identify the entry-point, create a new tag, and append it to the document. &#xA; from…

Convert Docx to Markdown

I needed to convert a Docx file to Markdown, but Pandoc kept giving me this obnoxious error: &#xA; $ pandoc test.docx -o test.md&#xA;pandoc: Cannot decode byte '\xae': Data.Text.Encoding.Fusion.streamUtf8: Invalid UTF-8 stream&#xA; However, you can use the tool unoconv to make an intermediary step to convert first to HTML and then to Markdown. &#xA; $ unoconv --stdout -f html test.docx | pandoc -f…

Duplicate a Django modelformset_factory Form

I created a formset_factory and wanted to have a simple “click me to add another form”. This seemed like a routine task, but the solutions I found online were unnecessarily complicated or required me to install a separate Django app, which I had no intention of doing. &#xA; So I created my own… &#xA; The only pre-requirement that this needs besides standard Django is jQuery . &#xA; So here is a…

Custom Django Fixture Imports

I needed to convert an XML document into a customize Django model with modifications to the based on programmable logic. Converting it to my model’s fixture would take too long and be unnecessary work, so I instead opted to manually convert the data. &#xA; I figured I could just import the Django model object, as is follows: &#xA; from tester.models import Control&#xA; a = Control()&#xA; However,…

Hotspot Hijacking & Password Capturing

Unless you know enough about security to know what’s going on behind the scenes, Wifi is beyond insecure. Even with SSL as an attempt to secure a web connection, your connection is still fundamentally insecure. This is an explanation of how someone would capture passwords and other variables sent over an SSL connection that uses Wifi. In essence, its a Man in the Middle (MiM) attack over Wifi that…

Old Chat Framework in C

During my high school years, I used to be part of an “underground” IRC server. We would talk about security-related topics and the latest exploits, usually about some Unix variant. Even though no one would really care about our late-night computer conversations, I thought it best that we chat over an encrypted medium, and considering that I knew nothing about how SSL could serve to transparently…

Simple Economics of the IPv6 Transition

The vast majority of the Internet currently operates on Internet Protocol Version 4 (IPv4), a 32-bit addressing system which theoretically allows for 4,294,967,295 (2^32-1) unique IP addresses. Though this may seem like an inexhaustible supply of addresses, current figures estimate less than 10% of it remains. The remaining address space would be far less had it not been for the deployment of…

About

Hi! I’m Farhan. As the sub-title says, this is my personal and professional technical blog. It is designed to showcase my contributions to the IT sector. &#xA; I’m a tech enthusiast, both for business and pleasure. I work professionally in IT Security and Penetration Testing and I am particularly interested in low-level programming, systems design, radio, IPv6 (check this site’s IPv6 address :),…

Current and Future Projects

Here is a list of current and future projects I would like to work on: &#xA; Current &#xA; &#xA; Porting the OpenBSD athn driver to FreeBSD, tracked in D45821 . &#xA; i3e_driver , a software implementation of FreeBSD&rsquo;s net80211 stack. &#xA; &#xA; Future (no guarantees) &#xA; &#xA; Implementing RTL8188GU (0x0BDA:0xB711) in FreeBSD. In theory, this should just be implementing a subset of…

Open Source Contributions

A brief list of my open-source contributions. &#xA; &#xA; Fix psutil.virtual_memory() type mismatch for NetBSD – NetBSD had a minor UTF-8 bug and would crash on NetBSD. I just changed the quotes and set a string type to binary. &#xA; Modified wetty to support FreeBSD – Wetty was using a Linuxism when referencing file paths, so I generalized it to utilize /usr/bin/env. &#xA; Updated Firefox’s…