1

So I am very new to networking and I was using the Python Socket library to connect to a server that is suposed to giveme time from the server.

Here is the code used.

import socket
import requests
import urllib3

Headers = {
    'Host':'iqoption.com',
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:73.0) Gecko/20100101 Firefox/73.0',
    'Accept' : '*/*',
'Accept-Encoding': 'gzip, deflate',
'Sec-WebSocket-Version' : '13',
'Origin' : 'https://iqoption.com',
 'Sec-WebSocket-Key': 'iExBWv1j6sC12qD+QPQ==',
'Connection' : 'keep-alive, Upgrade',
'Upgrade': 'websocket'


}
proxies = {"http": "http://127.0.0.1:8080", "https": "http://127.0.0.1:8080"}
urllib3.disable_warnings()

r = requests.get('https://iqoption.com/echo/websocket', stream=True,headers = Headers, proxies=proxies, verify=False)
s = socket.fromfd(r.raw.fileno(), socket.AF_INET, socket.SOCK_STREAM)
data = "ds"
bytes = s.recv(6000)
print(bytes)

This is the response expected

{"name":"timeSync","msg":1582082211799}

But i get all this code in the console

b'\x17\x03\x03\x00A\x00\x00\x00\x00\x00\x00\x00\x02\xd2D[\xac\xece\x97\xe4\x01\x83\x9c"\x9d\x89[=\xd6\xa5\x96\x9a"A\x16\x8b(\xc5+\xaf5X\xf7\xb2\x1ai\xd2\x03\x90\x17\n\xa9h\xc7\xc3\xab\xf4jm\xaf\xdf\xa3\x80j\xb5I\x06p~'

I decided to do a purpsuite check to see what was happening

And I received exactly the information I needed, I will put a capture

Screenshot of intercepted data in burpsuite

But I do not understand why when you pass the information to python, print these strange numbers

Python cosole screenshot

I'm really lost in this problem, I hope someone finds a solution :))

newuser434
  • 23
  • 2
  • It seems like you are trying to establish communication using `websocket`, which the built-in `socket` module would not be suited for out of the box (as it operates at a much lower level). You may wish to [refer to this thread](https://stackoverflow.com/questions/3142705/is-there-a-websocket-client-implemented-for-python) on how you might want to use websocket in Python instead. – metatoaster Feb 19 '20 at 03:33
  • 1
    I have no idea what you are trying to do. Why do you want to work with the raw socket? This socket will be TLS (encrypted) and `b'\x17\x03\x03\...` is the encrypted TLS record. Even if you would not use TLS the raw socket still has the websockets framing. If you need a websocket connection please use a websocket library and don't try to invent your own, see https://stackoverflow.com/questions/3142705/is-there-a-websocket-client-implemented-for-python – Steffen Ullrich Feb 19 '20 at 06:27

0 Answers0