init fragmentation
Calculated the intended message length of HyBi-10 frame Commented out socket recv buffer Added onError to demonstration
This commit is contained in:
parent
d9283d9593
commit
021a185753
@ -53,6 +53,10 @@ class Chat implements SocketObserver {
|
||||
public function onClose(SocketInterface $conn) {
|
||||
$this->_clients->detach($conn);
|
||||
}
|
||||
|
||||
public function onError(SocketInterface $conn, \Exception $e) {
|
||||
return $this->_factory->newCommand('CloseConnection', $conn);
|
||||
}
|
||||
}
|
||||
|
||||
// Run the server application through the WebSocket protocol
|
||||
|
@ -96,12 +96,25 @@ class HyBi10 implements VersionInterface {
|
||||
}
|
||||
|
||||
if($payloadLength === 126) {
|
||||
$msg_len = bindec(sprintf('%08b', ord($data[2])) . sprintf('%08b', ord($data[3])));
|
||||
$mask = substr($data, 4, 4);
|
||||
$payloadOffset = 8;
|
||||
} elseif($payloadLength === 127) {
|
||||
$msg_len = bindec(
|
||||
sprintf('%08b', ord($data[2]))
|
||||
. sprintf('%08b', ord($data[3]))
|
||||
. sprintf('%08b', ord($data[4]))
|
||||
. sprintf('%08b', ord($data[5]))
|
||||
. sprintf('%08b', ord($data[6]))
|
||||
. sprintf('%08b', ord($data[7]))
|
||||
. sprintf('%08b', ord($data[8]))
|
||||
. sprintf('%08b', ord($data[9]))
|
||||
);
|
||||
|
||||
$mask = substr($data, 10, 4);
|
||||
$payloadOffset = 14;
|
||||
} else {
|
||||
$msg_len = $payloadLength;
|
||||
$mask = substr($data, 2, 4);
|
||||
$payloadOffset = 6;
|
||||
}
|
||||
|
@ -105,11 +105,14 @@ class Server implements SocketObserver, \IteratorAggregate {
|
||||
// This idea works* but...
|
||||
// 1) A single DDOS attack will block the entire application (I think)
|
||||
// 2) What if the last message in the frame is equal to $recv_bytes? Would loop until another msg is sent
|
||||
// 3) This failed...an intermediary can set their buffer lower and this still propagates a fragment
|
||||
// Need to 1) proc_open the recv() calls. 2) ???
|
||||
/*
|
||||
while ($bytes === $recv_bytes) {
|
||||
$bytes = $conn->recv($buf, $recv_bytes, 0);
|
||||
$data .= $buf;
|
||||
}
|
||||
*/
|
||||
|
||||
$res = $this->onRecv($conn, $data);
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user