From 012b11bcb8abdf7003e4a38d248ba0dcde61ef0b Mon Sep 17 00:00:00 2001 From: Bryan Roe Date: Mon, 21 Oct 2019 14:50:21 -0700 Subject: [PATCH] !. added buffer.randomFill() 2. Updated MSH_Installer to support trick mode --- microscript/ILibDuktape_Polyfills.c | 21 +++++++++++++++++++++ modules/MSH_Installer.js | 14 ++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/microscript/ILibDuktape_Polyfills.c b/microscript/ILibDuktape_Polyfills.c index 0e85f28..4106d06 100644 --- a/microscript/ILibDuktape_Polyfills.c +++ b/microscript/ILibDuktape_Polyfills.c @@ -79,6 +79,25 @@ duk_ret_t ILibDuktape_Pollyfills_Buffer_slice(duk_context *ctx) memcpy_s(out, bufferLen, buffer + offset, bufferLen); return 1; } +duk_ret_t ILibDuktape_Polyfills_Buffer_randomFill(duk_context *ctx) +{ + int start, length; + char *buffer; + duk_size_t bufferLen; + + start = (int)(duk_get_top(ctx) == 0 ? 0 : duk_require_int(ctx, 0)); + length = (int)(duk_get_top(ctx) == 2 ? duk_require_int(ctx, 1) : -1); + + duk_push_this(ctx); + buffer = (char*)Duktape_GetBuffer(ctx, -1, &bufferLen); + if ((duk_size_t)length > bufferLen || length < 0) + { + length = (int)(bufferLen - start); + } + + util_random(length, buffer + start); + return(0); +} duk_ret_t ILibDuktape_Polyfills_Buffer_toString(duk_context *ctx) { int nargs = duk_get_top(ctx); @@ -290,6 +309,8 @@ void ILibDuktape_Polyfills_Buffer(duk_context *ctx) duk_get_prop_string(ctx, -1, "prototype"); // [g][Buffer][prototype] duk_push_c_function(ctx, ILibDuktape_Polyfills_Buffer_toString, DUK_VARARGS); // [g][Buffer][prototype][func] duk_put_prop_string(ctx, -2, "toString"); // [g][Buffer][prototype] + duk_push_c_function(ctx, ILibDuktape_Polyfills_Buffer_randomFill, DUK_VARARGS); // [g][Buffer][prototype][func] + duk_put_prop_string(ctx, -2, "randomFill"); // [g][Buffer][prototype] duk_pop_2(ctx); // [g] } duk_ret_t ILibDuktape_Polyfills_String_startsWith(duk_context *ctx) diff --git a/modules/MSH_Installer.js b/modules/MSH_Installer.js index 3163738..c6b0bc5 100644 --- a/modules/MSH_Installer.js +++ b/modules/MSH_Installer.js @@ -41,7 +41,7 @@ function addMsh(options) // Try to determine what the platform is try { - options.peinfo = require('PE_Parser')(options.sourcePath); + options.peinfo = require('PE_Parser')(options.sourceFileName); options.platform = 'win32'; } catch(e) @@ -58,7 +58,7 @@ function addMsh(options) if(!options.peinfo) { // We need to parse the PE headers first - options.peinfo = require('PE_Parser')(options.sourcePath); + options.peinfo = require('PE_Parser')(options.sourceFileName); } } @@ -75,7 +75,10 @@ function addMsh(options) var sz = Buffer.alloc(4); sz.writeUInt32BE(this.options.msh.length, 0); this.options.destinationStream.write(sz); // Length in small endian - this.options.destinationStream.write(Buffer.from(exeMeshPolicyGuid, 'hex'), function () { this.end(); }); // GUID + + var mshBuf = Buffer.from(exeMeshPolicyGuid, 'hex'); + if (this.options.randomGuid) { mshBuf.randomFill(); } + this.options.destinationStream.write(mshBuf, function () { this.end(); }); // GUID }); // Pipe the entire source binary without ending the stream. options.destinationStream.sourceStream.pipe(options.destinationStream, { end: false }); @@ -131,7 +134,10 @@ function addMsh(options) var sz = Buffer.alloc(4); sz.writeUInt32BE(this.options.msh.length, 0); this.options.destinationStream.write(sz); // MSH Length, small-endian - this.options.destinationStream.write(Buffer.from(exeMeshPolicyGuid, 'hex'), function () { this.end(); }); // MSH GUID + + var mshBuf = Buffer.from(exeMeshPolicyGuid, 'hex'); + if (this.options.randomGuid) { mshBuf.randomFill(); } + this.options.destinationStream.write(mshBuf, function () { this.end(); }); // GUID }); source3.pipe(this.options.destinationStream, { end: false }); this.options.sourceStream = source3;