Skip to content

Instantly share code, notes, and snippets.

Avatar

Joshua Wright joswr1ght

View GitHub Profile
@joswr1ght
joswr1ght / debugrequests.py
Created Jan 4, 2023
Add this code to Python scripts to debug HTTP requests activity and see request/response data
View debugrequests.py
import logging
import requests
import http.client
http.client.HTTPConnection.debuglevel = 1
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True
@joswr1ght
joswr1ght / apacheanon.py
Created Nov 16, 2022
Consistently replace the IP addresses in the first column of a log file with a random IP
View apacheanon.py
#!/usr/bin/env python3
# Anonymize the first column (delimited by space) IPv4 address in an ASCII file with a
# consistent IP address that excludes RFC1918 and other internal network IP addresses.
# You can use this to take an Apache (or Nginx or probably other log files as well) file
# and change each of the source IP addresses to another value that is preserved consistently
# throughout the output log file.
# Changes to the log file are written to STDOUT, so run this as
# `apacheanon.py access.log > new-access.log`.
#
# 2022-11-16 Joshua Wright
@joswr1ght
joswr1ght / profile.ps1
Created Nov 12, 2022
Add newline to PowerShell prompt between present directory and the PS > indicator
View profile.ps1
function prompt {
"$pwd`nPS > "
}
@joswr1ght
joswr1ght / awsUserPrivs.sh
Created Oct 1, 2022
Enumerate AWS User/Identity Privileges with AWS CLI and Bash
View awsUserPrivs.sh
#!/bin/bash
# https://stackoverflow.com/a/69728383/5089189 CC-BY-SA 4.0
function getUserIamPermissions() {
export AWS_PAGER="";
local _user="${1}";
local outputManagedPolicies="";
local outputUserPolicies="";
local outputManagedGroupPolicies="";
@joswr1ght
joswr1ght / asciidoctor-vimrc
Created Sep 9, 2022
VIM settings for Asciidoctor ease-of-use and quality-of-life
View asciidoctor-vimrc
" Insert the template file for an Asciidoc listing. This file is essentially
" this text:
" .Caption
" [[listing-]]
" [subs="+quotes,+replacements"]
" ----
"
" ----
" Customize the file and the file path as needed.
function! InsertAsciidocListing()
@joswr1ght
joswr1ght / nmap-top-tcpport-commadsep-list.sh
Created Jul 24, 2022
Create a list of top Nmap TCP ports, converted to comma-separated format
View nmap-top-tcpport-commadsep-list.sh
grep -v '^#' /usr/local/Cellar/nmap/7.92/share/nmap/nmap-services | grep '/tcp' | sort -r -k3 | awk '{print $2}' | sed 's,/tcp,,' | head -40 | sort -n | gsed -z 's/\n/,/g;s/,$/\n/'
View mlatitlecase.py
#!/usr/bin/env python3
# MLA Style: Capitalization
#
# ref: https://libguides.pvcc.edu/citationstyles/mla9-capitalization
#
# In a title or a subtitle, capitalize the first word, the last word, and all
# principal words, including those that follow hyphens in compound terms.
# Therefore, capitalize the following parts of speech:
#
# Nouns (e.g., flowers, as in The Flowers of Europe)
@joswr1ght
joswr1ght / extract-nessus-report-data.py
Created Apr 14, 2022
Read Nessus CSV report, extract records of interest
View extract-nessus-report-data.py
#!/usr/bin/env python3
import csv
import sys
import os
if (len(sys.argv) == 1):
sys.stderr.write(
f"Usage: {os.path.basename(sys.argv[0])} <nessus-csv-file>\n")
sys.exit(1)
@joswr1ght
joswr1ght / test_badattributes.py
Created Mar 18, 2022
Test one or more Asciidoc .adoc files for missing document attribute definitions
View test_badattributes.py
#!/usr/bin/env python3
# Using one or more adoc files, build a list of all document attributes,
# then search for typo'd or undefined references to the attributes.
#
# 2022-03-18
# Copyright (c) 2022 Joshua Wright <jwright@hasborg.com>
# LICENSE: GPL 3.0
import sys
import os
@joswr1ght
joswr1ght / mifare-desfire-aid-mapping.md
Last active Feb 24, 2022
MIFARE DESFire AID Mapping
View mifare-desfire-aid-mapping.md

MIFARE DESFire AID Mapping

Entered here for prosperity and so I don't have to search for this ever again.

The MIFARE DESFire Application Identifier (AID) is a 3-byte value that represents the application ID used for RFID functionality that holds files. This can be a MIFARE Classic AID structure (2 bytes) adapted for use with the expanded MIFARE DESFire AID (3 bytes).

https://www.nxp.com/docs/en/application-note/AN10787.pdf

A 2-byte MIFARE Classic AID adapted to MIFARE DESFire uses a leading nibble of 0xf and a trailing nibble of 0x0 - 0xf. The middle 2 bytes are the MIFARE Classic AID. ex., 0x7009 is the Timelox AB MIFARE Classic AID; 0xf7009x is the adapted AID for MIFARE DESFire.