0

I have captured some packages with wireshark and i want to resend them with my own software, written in python. I am using socket programming but I'm new to python so maybe this is a stupid question.

My software is doing its 3-way handshake as it should, and sends a packet with my information. But the thing is, it is not the right information it sends.

This is what I do:

MESSAGE = 0x13EC
s.send(MESSAGE)

I want the packet to contain the hex value 13EC, but it is sending it as a string right now, like "0x13EC". If I put it like this...

MESSAGE = '13EC'

...it's just sending zeros.

Can somebody please tell me what I am doing wrong?

Thanks in advance,

Bartel

BTW, I am using python 3.6.2.

0

1 Answer 1

1

When writing MESSAGE = 0x13EC you're essentially creating a integer with the value of 5100. But the socket can't send integers (to my knowledge).

Instead what you want to do is send byte data in the shape of \x13 and \xEC.
To do this, you can simply do:

MESSAGE = b'\x13\xEC'
s.send(MESSAGE)

And that should do it.
Or you can use struct to pack the data.

from struct import pack
VALUE = 0x13EC # 5100
MESSAGE = pack('H', VALUE) # 5100 -> b'\x13\xEC'
s.send(MESSAGE) # b'\x13\xEC'
Sign up to request clarification or add additional context in comments.

2 Comments

thanks a lot, did the job for at least a big part! But I have just one orther problem now, if I put a lot of data in it, the bits are shifted or in any other way different than expected. Is there a limit on how much data you can put in it?
@gamma_spec by it you mean pack()? If so, yes you need to combine multiple pack('H', 5100) + pack('Q', 5) for instance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.