From bcedbdbb7dfebef1e120ac8412e47b69f8b08b70 Mon Sep 17 00:00:00 2001 From: Matjaz Mesnjak Date: Fri, 7 Jan 2022 22:20:22 +0100 Subject: [PATCH] Initial commit. --- index.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 12 ++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 index.js create mode 100644 package.json diff --git a/index.js b/index.js new file mode 100644 index 0000000..93340a7 --- /dev/null +++ b/index.js @@ -0,0 +1,48 @@ +const net = require('net'); + +var request = []; +var requestSize = 0; + +const server = new net.createServer(function(c) { + //console.log('Server Connected'); + c.on('end', function() { + //console.log('Server Disconnected'); + request.slice(0); + requestSize = 0; + }); + c.on('data', function(data) { + console.log(data.toString()); + if(data.toString().startsWith('OPTIONS')) { + console.log('Sending options ...'); + c.write(`ICAP/1.0 200 OK\r\nMethods: REQMOD, RESPMOD\r\nOptions-TTL: 3600\r\nEncapsulated: null-body=0\r\nMax-Connections: 400\r\nPreview: 1024\r\nService: McAfee Web Gateway 7.8.0 build 24353\r\nISTag: "00000951-14.42.54-00008767"\r\nAllow: 204\r\n\r\n`); + c.end(); + } + if(data.length > requestSize) { + console.log('tu smo'); + request = data; + requestSize = data.length; + } + if(data.toString().endsWith('0\r\n\r\n')) { + console.log('Request Complete!'); + var lines = request.toString().split('\r\n'); + lines.forEach((line, index) => { + console.log(index.toString() + ': ' + line); + }); + if(lines[0].startsWith('RESPMOD')) { + console.log('Sending response'); + c.write(`ICAP/1.0 204\r\nICAP/1.0 204 No Content\r\nServer: Deep Discovery Analyzer 6.8 Build 1165\r\nISTag: "12.300.1011"\r\nX-Response-Desc: URL: No risk rating from WRS; FILE: No risk rating from VA\r\nDate: Thu, 16 Apr 2020 07:32:30 GMT\r\n\r\n`); + c.end(); + } + //c.end(); + } else { + console.log('Request not yet complete'); + } + }); + c.on('error', function(error) { + console.log(error); + }); +}); + +server.listen(1344, function() { + console.log('Server Bound'); +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..daf7aef --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "name": "avscan", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "start": "node index.js" + }, + "author": "", + "license": "ISC" +}