implement overrides

This commit is contained in:
JJTech0130 2023-04-07 10:33:03 -04:00
parent b17ae3f6f6
commit d30c397300
No known key found for this signature in database
GPG key ID: 23C92EBCCF8F93D6
3 changed files with 40 additions and 17 deletions

View file

@ -12,6 +12,7 @@ def _serialize_payload(id: int, fields: list[(int, bytes)]) -> bytes:
payload = b"" payload = b""
for fid, value in fields: for fid, value in fields:
if fid is not None:
payload += _serialize_field(fid, value) payload += _serialize_field(fid, value)
return id.to_bytes() + len(payload).to_bytes(4, "big") + payload return id.to_bytes() + len(payload).to_bytes(4, "big") + payload

View file

@ -93,10 +93,11 @@ def _p_filter(prefix, fields: list[tuple[int, bytes]]):
if len(paused) > 100: if len(paused) > 100:
paused = paused[:100] + "..." paused = paused[:100] + "..."
# (Token: {token.decode()}) # (Token: {token.decode()})
print(f"{bcolors.OKGREEN}{prefix}{bcolors.ENDC}: {bcolors.OKCYAN}Filter{bcolors.ENDC} {bcolors.WARNING}Enabled:{bcolors.ENDC} {enabled} {bcolors.FAIL}Ignored:{bcolors.ENDC} {ignored} {bcolors.OKBLUE}Oppertunistic:{bcolors.ENDC} {oppertunistic} {bcolors.OKGREEN}Paused:{bcolors.ENDC} {paused}") print(f"{bcolors.OKGREEN}{prefix}{bcolors.ENDC}: {bcolors.OKCYAN}Filter{bcolors.ENDC} {bcolors.WARNING}Enabled{bcolors.ENDC}: {enabled} {bcolors.FAIL}Ignored{bcolors.ENDC}: {ignored} {bcolors.OKBLUE}Oppertunistic{bcolors.ENDC}: {oppertunistic} {bcolors.OKGREEN}Paused{bcolors.ENDC}: {paused}")
import apns
def pretty_print_payload(prefix, payload: tuple[int, list[tuple[int, bytes]]]): def pretty_print_payload(prefix, payload: tuple[int, list[tuple[int, bytes]]]) -> bytes | None:
id = payload[0] id = payload[0]
if id == 9: if id == 9:
@ -104,10 +105,24 @@ def pretty_print_payload(prefix, payload: tuple[int, list[tuple[int, bytes]]]):
elif id == 8: elif id == 8:
token_str = "" token_str = ""
if _get_field(payload[1], 3): if _get_field(payload[1], 3):
token_str = f"New token: {b64encode(_get_field(payload[1], 3)).decode()}" token_str = f"{bcolors.WARNING}Token{bcolors.ENDC}: {b64encode(_get_field(payload[1], 3)).decode()}"
print(f"{bcolors.OKGREEN}{prefix}{bcolors.ENDC}: {bcolors.OKCYAN}Connected{bcolors.ENDC} {token_str}") print(f"{bcolors.OKGREEN}{prefix}{bcolors.ENDC}: {bcolors.OKCYAN}Connected{bcolors.ENDC} {token_str} {bcolors.OKBLUE}{_get_field(payload[1], 1).hex()}{bcolors.ENDC}")
elif id == 7: elif id == 7:
print(f"{bcolors.OKGREEN}{prefix}{bcolors.ENDC}: {bcolors.OKCYAN}Connect Request{bcolors.ENDC}") print(f"{bcolors.OKGREEN}{prefix}{bcolors.ENDC}: {bcolors.OKCYAN}Connect Request{bcolors.ENDC}", end="")
if _get_field(payload[1], 1):
print(f" {bcolors.WARNING}Token{bcolors.ENDC}: {b64encode(_get_field(payload[1], 1)).decode()}", end="")
if _get_field(payload[1], 0x0c):
print(f" {bcolors.OKBLUE}SIGNED{bcolors.ENDC}", end="")
print()
for i in range(len(payload[1])):
if payload[1][i][0] == 1:
pass
#payload[1][i] = (None, None)
#payload[1][i] = (1, b64decode("D3MtN3e18QE8rve3n92wp+CwK7u/bWk/5WjQUOBN640="))
out = apns._serialize_payload(payload[0], payload[1])
return out
elif id == 0xc: elif id == 0xc:
print(f"{bcolors.OKGREEN}{prefix}{bcolors.ENDC}: {bcolors.OKCYAN}Keep Alive{bcolors.ENDC}") print(f"{bcolors.OKGREEN}{prefix}{bcolors.ENDC}: {bcolors.OKCYAN}Keep Alive{bcolors.ENDC}")
elif id == 0xd: elif id == 0xd:
@ -126,7 +141,7 @@ def pretty_print_payload(prefix, payload: tuple[int, list[tuple[int, bytes]]]):
else: else:
print(f"{bcolors.OKGREEN}{prefix}{bcolors.ENDC}: {bcolors.OKCYAN}Notification{bcolors.ENDC}") print(f"{bcolors.OKGREEN}{prefix}{bcolors.ENDC}: {bcolors.OKCYAN}Notification{bcolors.ENDC}")
elif id == 0xb: elif id == 0xb:
print(f"{bcolors.OKGREEN}{prefix}{bcolors.ENDC}: {bcolors.OKCYAN}Notification Ack{bcolors.ENDC}") print(f"{bcolors.OKGREEN}{prefix}{bcolors.ENDC}: {bcolors.OKCYAN}Notification Ack{bcolors.ENDC} {bcolors.OKBLUE}{_get_field(payload[1], 8).hex()}{bcolors.ENDC}")
else: else:
print(prefix, f"Payload ID: {hex(payload[0])}") print(prefix, f"Payload ID: {hex(payload[0])}")
for field in payload[1]: for field in payload[1]:

View file

@ -37,6 +37,7 @@ import printer
def proxy(conn1: tlslite.TLSConnection, conn2: tlslite.TLSConnection, prefix: str = ""): def proxy(conn1: tlslite.TLSConnection, conn2: tlslite.TLSConnection, prefix: str = ""):
try:
while True: while True:
# Read data from the first connection # Read data from the first connection
data = conn1.read() data = conn1.read()
@ -44,11 +45,17 @@ def proxy(conn1: tlslite.TLSConnection, conn2: tlslite.TLSConnection, prefix: st
if not data: if not data:
break break
override = printer.pretty_print_payload(prefix, apns._deserialize_payload_from_buffer(data))
if override is not None:
data = override
print("OVERRIDE: ", end="")
printer.pretty_print_payload(prefix, apns._deserialize_payload_from_buffer(data)) printer.pretty_print_payload(prefix, apns._deserialize_payload_from_buffer(data))
#print(prefix, data) #print(prefix, data)
# Write the data to the second connection # Write the data to the second connection
conn2.write(data) conn2.write(data)
except Exception as e:
pass # Probably a connection closed error
print("Connection closed") print("Connection closed")
# Close the connections # Close the connections
conn1.close() conn1.close()