Skip to content

Instantly share code, notes, and snippets.

@aroly
Created October 31, 2021 07:59
Show Gist options
  • Save aroly/a504a0f6018ca5844d7b9b12c6de24f8 to your computer and use it in GitHub Desktop.
Save aroly/a504a0f6018ca5844d7b9b12c6de24f8 to your computer and use it in GitHub Desktop.
Hackvertor - AMF tags
import string, struct
def encode(string, xml=False):
string = string.encode('utf-8')
if xml:
const = '\x0f' # AMF0 XML document
size = struct.pack("!L", len(string)) # Size on 4 bytes
else:
const = '' # AMF0 URI
size = struct.pack("!H", len(string)) # Size on 2 bytes
return const + size + string
def build_amf_packet(svc, xml_str):
# Message
array_with_one_entry = '\x0a' + '\x00\x00\x00\x01' # AMF0 Array
msg = array_with_one_entry + encode(xml_str, xml=True)
# Body
target_uri = encode(svc) # Target URI
response_uri = encode('foobar') # Response URI
sz_msg = struct.pack("!L", len(msg))
body = target_uri + response_uri + sz_msg + msg
# Packet
version = '\x00\x03' # Version
headers = '\x00\x00' # No headers
bodies = '\x00\x01' + body # One body
packet = version + headers + bodies
return packet
output = build_amf_packet("foo",input)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment