How Websockets work and what is websockets in html5

how to maintain a websocket connection between pages, how to block websockets what are websockets used for how many websocket connections per server pdf free download
Prof.SteveBarros Profile Pic
Prof.SteveBarros,United Kingdom,Teacher
Published Date:28-07-2017
Your Website URL(Optional)
Comment
Behold the Bidirectional Browser Yay The WebSocket Protocol enables two-way communication between a client running untrusted code in a controlled environment to a remote host that has opted-in to communications from that code. Hmm... Uh oh - RFC 6455 BLACK HAT USA 2012 3 3Wonky Workarounds Forcing persistence on a non-persistent protocol with long- polling, cometd, etc. ...often at the server’s expense of one thread/request ...while dealing with the browser’s per-domain connection limit ...and trying to figure out a magic polling frequency ...just to know when the server has some data ready. BLACK HAT USA 2012 4 4Speak to Me § Simple structure for transporting bytes: RFC 6455 § WebSockets API describes the JavaScript interface receive with websocket.onmessage() − send with websocket.send() − transfer a String, Blob, ArrayBuffer − § Tunnel arbitrary data JSON, XML, HTML − images, video, sound − another protocol − BLACK HAT USA 2012 5 5WebSockets Emulation § web-socket-js The power of Flash’s raw sockets with the benefits(?) of Flash’s security § sockjs-client Pure JavaScript, choose your poison: long-polling, XHR, etc. § Forcing HTML5 on a non-HTML5 browser BLACK HAT USA 2012 7 7WS = Works Superior § Starts with an HTTP handshake Transparent to proxies (well, it’s supposed to be) − § “ping” / “pong” frames for keep-alive § Data frames don’t have HTTP overhead No headers, cookies, authentication − § Data frames don’t have HTTP security No headers, cookies, authentication − BLACK HAT USA 2012 8 8Handshake Challenge GET /?encoding=text HTTP/1.1 Host: echo.websocket.org User-Agent: ... Connection: Upgrade Sec-WebSocket-Version: 13 Origin: http://www.websocket.org Sec-WebSocket-Key: CjYoQD+BXC718rj3aiExxw== BLACK HAT USA 2012 9 9Handshake Response HTTP/1.1 101 Switching Protocols Upgrade: WebSocket Connection: Upgrade Sec-WebSocket-Accept: c4RVZSknSoEHizZu6BKl3v +xUuI= then the data frames begin BLACK HAT USA 2012 10 10Us and Them Sec-WebSocket-Key: base64(16 random bytes) Sec-WebSocket-Accept: base64(SHA1(challenge + GUID) § Must finish the handshake before opening another connection to the same origin § Success proves the endpoint speaks WebSocket − Does not prove identity or trust BLACK HAT USA 2012 11 11Some Origin Policies § Handshake includes Origin header § User Agent should not establish plaintext WebSocket (ws:) from “secure” resource (https:) § User Agent should minimize details for certain kinds of connection failures “host/port scanning” − Still doesn’t affect timing analysis − § Web Workers might use WebSocket objects BLACK HAT USA 2012 12 12WebSocket JavaScript Object function(evt) ... BLACK HAT USA 2012 13 13Data Frame Details 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+ FRRR opcodeM Payload len Extended payload length ISSS (4) A (7) (16/64) NVVV S (if payload len==126/127) 123 K +-+-+-+-+-+-+-+ - - - - - - - - - - - - - - - + Extended payload length continued, if payload len == 127 + - - - - - - - - - - - - - - - +-+ Masking-key, if MASK set to 1 +-+-+ Masking-key (continued) Payload Data + - - - - - - - - - - - - - - - + : Payload Data continued ... : + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + Payload Data continued ... +-+ BLACK HAT USA 2012 14 1400 18 0a 01 32 aa 00 26 b0 f5 42 68 08 00 Ethernet dst 00:18:0a:01:32:aa src 00:26:b0:f5:42:68 type 0x800 IP version 4L ihl 5L tos 0x0 len 95 id 57452 45 00 flags DF 00 5f e0 6c 40 00 40 06 66 8a 0a ab 5a 2c ae 81 frag 0L e0 49 ttl 64 proto tcp chksum 0x668a src 10.171.90.44 dst 174.129.224.73 options TCP Masking Data sport 63784 dport http f9 28 00 50 fb 51 8d 7f ea d5 21 21 80 18 seq 4216425855 82 18 fa c2 00 00 01 01 08 0a c5 4f 2d e2 61 52 ack 3939836193 72 98 dataofs 8L § 32-bit pseudo-random value, XOR byte by byte reserved 0L flags PA § Prevent the browser from being leveraged for cross- window 33304 chksum 0xfac2 urgptr 0 protocol attacks, cache poisoning options (’NOP’, None), (’... WebSocket flags FIN opcode text frame 81 a5 bd cc ef e0 e9 a4 8a 99 9a be 8a c0 mask flag 1L de a3 82 89 d3 ab cf 94 d2 ec 88 85 c9 ec 96 8f length 37L c8 e0 cf a2 dc be 8d 81 cf ad c1 ce 93 mask 0xbdccefe0 frame data ’\xe9\xa4\x8a\x99\... bd cc ef e0 bd cc ef e0 bd ... e9 a4 8a 99 9a be 8a c0 de ... T h e y ‘ r e c BLACK HAT USA 2012 15 15Variable Lengths Decimal Length (7 bits) Variable Length (16- or 64-bit) 1 1 0 0 0 0 0 0 n/a 128 0 1 1 1 1 1 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 65535 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 65536 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 . . . 264 - 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 . . . 1 1 1 1 1 1 1 1 19 1 1 0 0 1 0 0 n/a 19 0 1 1 1 1 1 1 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 19 1 1 1 1 1 1 1 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 . . . BLACK HAT USA 2012 16 16Scapy Dissection class WebSocket(Packet): name = "WebSocket" fields_desc = FlagsField("flags", 0, 4, "RSV3", "RSV2", "RSV1", "FIN"), BitEnumField("opcode", 0, 4, _ws_opcode_names), BitField("mask_flag", 0, 1), BitField("length", 0, 7), ConditionalField(BitField("length16", None, 16), lambda pkt:pkt.length == 126), ConditionalField(BitField("length64", None, 64), lambda pkt:pkt.length == 127), ConditionalField(XIntField("mask", 0), lambda pkt:pkt.mask_flag == 1), StrLenField("frame_data", None, length_from=lambda pkt:(pkt.length64 if pkt.length64 else pkt.length16 if pkt.length16 else pkt.length)) BLACK HAT USA 2012 17 17Data Frame Security Features 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+ insert your protocol here +-+ crickets +-+ It is pitch dark. + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + You are likely to be eaten by a grue. +-+ BLACK HAT USA 2012 18 18What makes them interesting Hacking with WebSockets 19WebSockets in the Wild § Micro-SCADA § Web apps § Cool games § Mobile apps BLACK HAT USA 2012 20 20Embedded Devices WebSocket server with PIC microcontroller allows control of electronics on the board from the browser 4 port HDMI switch controlled by embedded I/O controller with WebSocket server running in embedded linux kernel BLACK HAT USA 2012 21 21Other places h"p://labsocket.com/example.html BLACK HAT USA 2012 22 22Current implementations Others RFC 6455 libwebsockets Tufão apache-websocket pywebsocket WebSocket-Node JavaScript BLACK HAT USA 2012 23 23

Advise: Why You Wasting Money in Costly SEO Tools, Use World's Best Free SEO Tool Ubersuggest.