xerusmsp / msp-py

A minimalistic and fast Python handler for requests to the MSP API.
Do What The F*ck You Want To Public License
14 stars 13 forks source link

error checksum for request with ByteArray #5

Closed Twace closed 1 year ago

Twace commented 1 year ago

Unauthorized response by making request with method that has ByteArray

n.b. you can download Gateway.aspx here or upload an photo in MovieStarPlanet and right click on the request on Charles then save Request

from msp import invoke_method, get_session_id
from pyamf import remoting

f = open("Gateway.aspx","rb")
data_amf_bytes = f.read()

amf_body_decoded =  (remoting.decode(data_amf_bytes)["/1"].body)

code, resp = invoke_method(
        "fr",
        "MovieStarPlanet.WebService.ImageUpload.AMFImageUpload.UploadImageWithSnapshot",
        amf_body_decoded ,
        get_session_id()
    )
print(code,resp)

ErrorFault level=error code='Server.Processing' description='Unauthorized'

Also, the checksum isn't the same than the original request

from msp import calculate_checksum

print("Original checksum:",(remoting.decode(data_amf_bytes).headers)['id'])
print("Calculated checksum:",calculate_checksum(amf_body_decoded))

I think issue is due to the calculation of checksum of pyamf.amf3.ByteArray object

The request works if I change checksum by the one in the scraped request

hatns commented 1 year ago

sending pure bytes over py3amf sends them as a string. In order to send a bytearray, use:

hexadecimal_bytes_string = "FFEEDDCCBBAA99887766554433221100"
_bytes = binascii.unhexlify(hexadecimal_bytes_string)
bytearr = amf3.ByteArray(_bytes)

checksum has to be fixed, but its a start. This is the only way of sending a byte array i have found that does it properly AND preserves the state of the data