Skip to content

Instantly share code, notes, and snippets.

@typcn
Created April 30, 2016 01:46
Show Gist options
  • Save typcn/b6f4391a118bcaa7ee34a40216868422 to your computer and use it in GitHub Desktop.
Save typcn/b6f4391a118bcaa7ee34a40216868422 to your computer and use it in GitHub Desktop.
Extract HTTP body in Wireshark TCP Stream to files
var fs = require('fs');
var bsplit = require('buffer-split');
var p1 = fs.readFileSync('./part1');
write(p1);
function write(px) {
var pkts = bsplit(px,new Buffer('GET '));
for (var i = 1; i < pkts.length; i++) {
var dta = bsplit(pkts[i], new Buffer('\r\n\r\n'));
var url = bsplit(dta[0], new Buffer(' HTTP/1.1'))[0];
var path = url.toString();
ensureDirectoryExistence(path);
var data = dta[2];
fs.writeFileSync(path,data);
}
}
function ensureDirectoryExistence(filePath) {
var path = require('path');
var dirname = path.dirname(filePath);
if (directoryExists(dirname)) {
return true;
}
ensureDirectoryExistence(dirname);
fs.mkdirSync(dirname);
}
function directoryExists(path) {
try {
return fs.statSync(path).isDirectory();
}
catch (err) {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment