varmqtt=require('mqtt-packet')varopts={protocolVersion:4}// default is 4. Usually, opts is a connect packet
functionfuzz(buf){varparser=mqtt.parser(opts)// 这个包自己产生的异常都会通过这个函数调用
parser.on('error',function(error){})parser.parse(buf)}module.exports={fuzz};
varmqtt=require('mqtt-packet')varobject={cmd:'publish',retain:false,qos:0,dup:false,length:10,topic:'test',payload:'test'// Can also be a Buffer
}varopts={protocolVersion:4}// default is 4. Usually, opts is a connect packet
console.log(mqtt.generate(object))// 写入文件的方法
varfs=require('fs')fs.writeFile("test.txt",mqtt.generate(object),"binary",function(err){});
用mqtt-packet仓库说明里的mqtt object格式生成更多样本后得到了16个样本.
运行后
jsfuzz fuzz2.js test_corpus/
可以看到路径数从50提高了67 并且在67个路径上爆出了一个错误
文本版
1
2
3
4
5
6
7
8
9
10
11
RangeError [ERR_BUFFER_OUT_OF_BOUNDS]: Attempt to write outside buffer bounds
at boundsError (internal/buffer.js:70:11)
at Buffer.readUInt8 (internal/buffer.js:238:5)
at BufferList.<computed> [as readUInt8] (/home/bluebird/fuzz/jsfuzz/node_modules/bl/bl.js:1:33980)
at Parser._parseByte (/home/bluebird/fuzz/jsfuzz/node_modules/mqtt-packet/parser.js:1:71555)
at Parser._parseProperties (/home/bluebird/fuzz/jsfuzz/node_modules/mqtt-packet/parser.js:1:72858)
at Parser._parseConnect (/home/bluebird/fuzz/jsfuzz/node_modules/mqtt-packet/parser.js:1:55778)
at Parser._parsePayload (/home/bluebird/fuzz/jsfuzz/node_modules/mqtt-packet/parser.js:1:51576)
at Parser.parse (/home/bluebird/fuzz/jsfuzz/node_modules/mqtt-packet/parser.js:1:49930)
at Worker.fuzz [as fn] (/home/bluebird/fuzz/jsfuzz/fuzz2.js:1:1523)
at process.<anonymous> (/usr/local/lib/node_modules/jsfuzz/build/src/worker.js:63:30)