Skip to content

Instantly share code, notes, and snippets.

View pocc's full-sized avatar
🏠
Working from home

Ross Jacobs pocc

🏠
Working from home
View GitHub Profile
@pocc
pocc / dl_livecap.sh
Last active March 2, 2021 16:35
Live capture a Chrome or Firefox pcap/ng download as it is downloading
#!/usr/bin/env bash
# This script will detect if there are any new partial download files
# And launch wire/tshark to read them as a live capture.
DL_DIR="$HOME/Downloads"
SHARK_CMD="wireshark -k -i -"
# SHARK_CMD="tshark -r -"
function DL_PARTIALS {
# Partial names: Chrome=$file.crdownload, Firefox=$file.part, Safari=$file.download, Edge=$file.RaNd0mStr.partial
find "$DL_DIR" -maxdepth 1 | perl -ne 'print /(.*pcapng\.(part|crdownload|download|[a-zA-Z0-9]+\.partial))/'
@pocc
pocc / wsutils.py
Created March 18, 2019 15:35
Wrapper for wireshark utils (like pyshark for tshark)
"""
Pcap class to more easily interact with pcaps
When in doubt, aim for simplicity of requests API
Like pyshark, but for the wireshark utilities
"""
import os
import subprocess as sp
import re
import pprint
import tempfile
@pocc
pocc / png_to_webp.sh
Last active November 9, 2023 14:03
Convert all png images to webp recursively
#!/usr/bin/env bash
# This script will get a list of all jpg and png files recursively
# and convert them all in place to webp files.
# cwebp options for max compression: `-m 6 -q 100 -z 9`
shopt -s globstar
for image in $PWD/**/*.png; do
echo "File is $image"
outfile=${image::-4}.webp
echo "outfile is $outfile"
@pocc
pocc / derive.jl
Created March 2, 2019 19:45
Derive the provided function for x or for a specific value
# Evaluate a derivative of a single-variable function
# Assume last argument is value/var and all others are function
# Example:
# $ julia derive.jl x^2 + x + 1 1
# > derivative at 1:
# > 2.999999999960656
# $ julia derive.jl x^2 + x + 1 x
# > derivative:
# > 2 * 1 * x ^ (2 - 1) + 1
using Calculus
@pocc
pocc / compare_hash_tables.ps1
Created February 1, 2019 22:37
Compare Powershell hash tables recursively
# Compare Powershell hash tables using a helper function.
# Usage:
# PS> Import-Module ./compare_hash_tables.ps1
# PS> $hash1 = @{'1'='2'; '3'=@(@{'5'='8'; 'a'='b'},'7', 'c'); 'd'=@('e')}
# PS> $hash2 = @{'1'='1'; '3'=@(@{'5'='9'},'6'); 'd'=@('e','f')}
# PS> Compare-Hashes $hash1 $hash2
#
# : hash['3'] : list[0] : hash['5'] : <->
# -> Expected '8'
# -> Actually '9'
@pocc
pocc / meraki_api_generate.py
Created January 25, 2019 23:54
Automatically generate a Python Meraki API module from the Mearki API website
# -*- coding: utf-8 -*-
"""Generator for Meraki API python module"""
import requests
import json
import re
api_key = ''
base_url = 'https://api.meraki.com/api/v0/'
# Should work for get
function_text = """\ndef {0}({1}):
@pocc
pocc / mbms_crc_example.c
Created January 1, 2019 06:19
This function will compute the CRC of a hexstring
// Using code from http://www.sunshine2k.de/articles/coding/crc/understanding_crc.html#ch5
// Using MBMS header bits from the pcap in wireshark bug#14875
// Expected output is 52 (0x34), which is the correct answer
#include <stdio.h>
int main(){
const int generator = 0x2f;
int crc = 0; /* start with 0 so first byte can be 'xored' in */
// 0x10043b000000000000 aligned to 6 bits (from pcap)
@pocc
pocc / nextstep.py
Created December 28, 2018 01:09
Recursive way to create troubleshooting trees, with examples
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""This program aims to provide tools to troubleshoot better
NOTE: Default option is yes to continue troubleshooting. No is for steps if
user has not done due diligence.
Assuming that categories only need to be chosen at the beginning and from
then on we can employ binary questions
"""
@pocc
pocc / filter_combine.sh
Created December 11, 2018 06:18
Apply a Display Filter to multiple files and merge the packets into one file
#!/bin/bash
# In response to https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=14418
# First arg is filter, all other args are files
# Usage: ./filter_combine.sh 'icmp' file1.pcap file2.pcap file3.pcap
# Outputs `combined.pcapng`
FILTER=$1
FILES=${@:2}
i=0
TEMP_FILES=()
@pocc
pocc / install_wireshark.sh
Last active December 10, 2018 03:56
Install Wireshark from source on Ubuntu 16.04
# Built with Mint 17.3 based on Ubuntu 16.04
# Based on https://www.wireshark.org/docs/wsdg_html_chunked/ChSrcBuildFirstTime.html#_building_on_unix
# With additional library installations found via trial and error
# Install bcg729 (which is not installed by default)
curl -L -O https://github.com/~/1.0.4.tar.gz
tar xvzf 1.0.4.tar.gz
cd bcg729-1.0.4
cmake
make