Skip to content

Instantly share code, notes, and snippets.

@nmiglio
nmiglio / port_fwd.txt
Last active October 30, 2020 14:15
Set up port forwarding (TCP) on win10
To port forward 127.0.0.1:3340 to 192.168.0.10:80 in Windows 10:
Launch an Administrator Command Prompt.
netsh interface portproxy add v4tov4 listenaddress=127.0.0.1 listenport=3340 connectaddress=192.168.0.10 connectport=80
Check that the port is not already used:
netstat -na|find "3340"
To display a list of all active TCP port forwarding rules on Windows, run the command:
netsh interface portproxy show all
@nmiglio
nmiglio / decrypt_mode_7.py
Last active February 18, 2020 10:47
decryption of AES-128 CBC with IV=0 and ephimeral key (OMS telegrams MODE 7)
from Crypto.Hash import CMAC
from Crypto.Cipher import AES
init_vector = bytearray(16) # IV=0
aes_key_str = "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
full_tg_str = "B346FA121028000001068C00DB900F002C25030000008298D056148A8B757AE100900710EB64AF75C4FC415400EF598690C50CA2494E0AE679FE25D3BC322881E6EEFF4C34618226A68DA5E9D33DD9DC45C72D8BA8170C6D13551CE15E1FC67AF1D642F1EE51E886A6C242C3FB9CCC0B60F7DAFF0E62E27BF5FD1A7FACD16C0975ED870A7D119F1F87BBC06B201D1509A01088402FE9A3DFD985DD6FB178236A6DED2DEE4FA81867003CEFAFA24B1727F2786812"
stripped_tg = full_tg_str[72:] # strip plain data
# build ephimeral key
from inspect import getmembers
def print_com_members(obj, obj_name="placeholder_name"):
"""Print members of given COM object"""
try:
fields = list(obj._prop_map_get_.keys())
except AttributeError:
print("Object has no attribute '_prop_map_get_'")
print("Check if the initial COM object was created with"
@nmiglio
nmiglio / CRC_CCITT.py
Last active May 23, 2019 15:40
Python script to evaluate CRC16 CCITT (0xffff)
# Computation of CRC16 CCITT (0xFFFC)
# The input parameter for crc16Eval() is a hexString obtained from a bytearray bytes values
# The function returns a string with the hexadecimal value, an int with the low byte value
# and an int with the high byte value of the crc.
#
# hexArray = bytearray(b'\xe8\x8a\x04\r\x00W\x8b')
# hexString = = "".join(map(chr, hexArray))
# (crcHexStr, crcHighByte, crcLowByte) = crc16Eval(hexString)
class CRC_CCITT:
@nmiglio
nmiglio / gist:1fcb5e3cbe7c8feebb2a19b2bae2bb38
Created August 7, 2018 14:25
fix for TWRP bootloop after updating Lineage OS on Nexus4 (mako)
TWRP->Advanced->Terminal
dd if=/dev/zero of=/dev/block/platform/msm_sdcc.1/by-name/misc count=1 bs=32