forked from kirm/sip.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kirm#124 from garronej/master
Fixing vunerability to flood with statefull connections.
- Loading branch information
Showing
10 changed files
with
251 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,9 @@ | |
"homepage": "http://github.com/kirm/sip.js", | ||
"author": "Kirill Mikhailov <[email protected]>", | ||
"main": "sip", | ||
"scripts": { | ||
"test": "./node_modules/.bin/coffee test/runtests.coffee" | ||
}, | ||
"directories": { | ||
"lib": "", | ||
"example": "./examples", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"use strict"; | ||
/* | ||
Compute .json | ||
This script will parse the raw sip messages *.dat that are present | ||
in this directory and export the result in a file *.json. | ||
Note that an empty file .json has to be present in the dir. | ||
Be careful, check that the .json generated match the value | ||
that is actually expected. | ||
*/ | ||
|
||
let fs= require("fs"); | ||
let path = require("path"); | ||
let sip = require("../../"); | ||
|
||
let encoding= "binary"; | ||
|
||
let files = fs.readdirSync(__dirname); | ||
|
||
let names = []; | ||
|
||
for (let file of files) { | ||
|
||
if (path.extname(file) !== ".json") continue; | ||
|
||
names.push(path.basename(file, ".json")); | ||
|
||
} | ||
|
||
for (let name of names) { | ||
|
||
console.log(`${name}.dat => sip.parse => ${name}.json`); | ||
|
||
let dat = fs.readFileSync( | ||
path.join(__dirname, `${name}.dat`), | ||
encoding | ||
); | ||
|
||
let json = JSON.stringify(sip.parse(dat), null, 2); | ||
|
||
fs.writeFileSync( | ||
path.join(__dirname, `${name}.json`), | ||
json, | ||
{ "encoding": encoding } | ||
); | ||
|
||
} | ||
|
||
console.log("DONE"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,7 @@ | |
"uri": "sip:[email protected]", | ||
"params": { | ||
"newparam": "newvalue", | ||
"secondparam": null, | ||
"q": "0.33" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
"use strict"; | ||
|
||
let sip = require("../"); | ||
let fs = require("fs"); | ||
let path= require("path"); | ||
|
||
function handleKeepAlive(success) { | ||
|
||
let isSuccess= false; | ||
|
||
let rawMessageAsBinaryString= fs.readFileSync(path.join(__dirname, "messages", "baddate.dat"), "binary"); | ||
|
||
let streamParser = sip.makeStreamParser( | ||
function (sipPacket) { | ||
|
||
isSuccess= true; | ||
|
||
console.log("ok test handleKeepAlive"); | ||
|
||
success(); | ||
|
||
} | ||
); | ||
|
||
for( let i=0; i<20000; i++) | ||
streamParser("\r\n"); | ||
|
||
streamParser(rawMessageAsBinaryString); | ||
|
||
console.assert(isSuccess, "Message has not been parsed"); | ||
|
||
} | ||
|
||
function flood(success) { | ||
|
||
let isSuccess= false; | ||
|
||
let onMessage= function(sipPacket){ | ||
|
||
console.assert(false, "Message should not have been parsed"); | ||
|
||
}; | ||
|
||
let onFlood= function(){ | ||
|
||
isSuccess= true; | ||
|
||
console.log("ok test flood"); | ||
|
||
success(); | ||
|
||
} | ||
|
||
let maxBytesHeaders= 6048; | ||
|
||
let streamParser = sip.makeStreamParser(onMessage, onFlood, maxBytesHeaders); | ||
|
||
let floodData= ""; | ||
|
||
for (let i = 0; i < maxBytesHeaders; i++){ | ||
|
||
floodData+= "x"; | ||
|
||
} | ||
|
||
streamParser(floodData); | ||
|
||
streamParser("OVERFLOW!"); | ||
|
||
console.assert(isSuccess, "We have been buffering flood data"); | ||
|
||
} | ||
|
||
function payloadFlood(success) { | ||
|
||
let isSuccess = false; | ||
|
||
let split = fs | ||
.readFileSync( | ||
path.join(__dirname, "messages", "baddate.dat"), | ||
"binary" | ||
) | ||
.split("\r\n"); | ||
|
||
for (let i = 0; i <= split.length; i++) | ||
if (split[i].match(/^Content-Length:\ ([0-9]+)$/)) { | ||
split[i] = split[i].replace(/[0-9]+/, "999999999999"); | ||
break; | ||
} | ||
|
||
|
||
let rawMessageAsBinaryString = split.join("\r\n"); | ||
|
||
let onMessage= function(sipPacket){ | ||
|
||
console.assert(false, "Message should not have been parsed"); | ||
|
||
}; | ||
|
||
let onFlood= function(){ | ||
|
||
isSuccess= true; | ||
|
||
console.log("ok test payloadFlood"); | ||
|
||
success(); | ||
|
||
} | ||
|
||
let streamParser = sip.makeStreamParser(onMessage, onFlood); | ||
|
||
streamParser(rawMessageAsBinaryString); | ||
|
||
for( let i=0; i<100000; i++) | ||
streamParser("FLOOD"); | ||
|
||
console.assert(isSuccess, "Payload Flood attack!"); | ||
|
||
} | ||
|
||
|
||
exports.tests= [ handleKeepAlive, flood, payloadFlood ]; |