mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-06 00:13:33 +00:00
1. Fixed error case of Resolve()
2. Added 'resolve' support 3. Added new testharnass interface 4. Added clipboard support for PAC/Autoproxy helper 5. Added autoproxy sandbox
This commit is contained in:
@@ -5192,9 +5192,28 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char **
|
||||
{
|
||||
ILibIPAddressMonitor_Create(agentHost->chain, MeshAgent_AgentMode_IPAddressChanged_Handler, agentHost);
|
||||
}
|
||||
MeshServer_Connect(agentHost);
|
||||
if (agentHost->localdebugmode == 0) { MeshServer_Connect(agentHost); }
|
||||
else
|
||||
{
|
||||
int CoreModuleLen = ILibSimpleDataStore_Get(agentHost->masterDb, "CoreModule", NULL, 0);
|
||||
if (CoreModuleLen > 4)
|
||||
{
|
||||
// There is a core module, launch it now.
|
||||
CoreModule = (char*)ILibMemory_Allocate(CoreModuleLen, 0, NULL, NULL);
|
||||
ILibSimpleDataStore_Get(agentHost->masterDb, "CoreModule", CoreModule, CoreModuleLen);
|
||||
|
||||
if (ILibDuktape_ScriptContainer_CompileJavaScriptEx(agentHost->meshCoreCtx, CoreModule + 4, CoreModuleLen - 4, "CoreModule.js", 13) != 0 ||
|
||||
ILibDuktape_ScriptContainer_ExecuteByteCode(agentHost->meshCoreCtx) != 0)
|
||||
{
|
||||
ILibRemoteLogging_printf(ILibChainGetLogger(agentHost->chain), ILibRemoteLogging_Modules_Microstack_Generic | ILibRemoteLogging_Modules_ConsolePrint,
|
||||
ILibRemoteLogging_Flags_VerbosityLevel_1, "Error Executing MeshCore: %s", duk_safe_to_string(agentHost->meshCoreCtx, -1));
|
||||
}
|
||||
duk_pop(agentHost->meshCoreCtx);
|
||||
free(CoreModule);
|
||||
}
|
||||
|
||||
duk_peval_string_noresult(agentHost->meshCoreCtx, "console.log('Agent running in Local Debug Mode');require('MeshAgent').emit('Connected',1);");
|
||||
}
|
||||
// We are acting as a mesh agent
|
||||
if (((ILibSimpleDataStore_Get(agentHost->masterDb, "MeshServer", ILibScratchPad, sizeof(ILibScratchPad))) > 5) && (memcmp(ILibScratchPad, "local", 5) == 0))
|
||||
{
|
||||
@@ -5555,7 +5574,14 @@ void MeshAgent_ScriptMode(MeshAgentHostContainer *agentHost, int argc, char **ar
|
||||
else if (strncmp(argv[i], "--script-connect", 16) == 0)
|
||||
{
|
||||
// Connect to MeshCentral
|
||||
connectAgent = 1;
|
||||
if (strnlen(argv[i], 19) == 18 && strcmp(argv[i] + 16, "=2") == 0)
|
||||
{
|
||||
connectAgent = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
connectAgent = 1;
|
||||
}
|
||||
if (agentHost->masterDb == NULL)
|
||||
{
|
||||
agentHost->masterDb = ILibSimpleDataStore_Create(MeshAgent_MakeAbsolutePath(agentHost->exePath, ".db"));
|
||||
@@ -5688,6 +5714,7 @@ void MeshAgent_ScriptMode(MeshAgentHostContainer *agentHost, int argc, char **ar
|
||||
// If in agent mode, setup the chain to be a mesh agent
|
||||
if (connectAgent != 0)
|
||||
{
|
||||
agentHost->localdebugmode = (connectAgent == 2);
|
||||
if (MeshAgent_AgentMode(agentHost, argc, argv, 0) == 0)
|
||||
{
|
||||
ILibStopChain(agentHost->chain); // Agent Error, stop the chain
|
||||
|
||||
@@ -211,6 +211,7 @@ typedef struct MeshAgentHostContainer
|
||||
int jsDebugPort;
|
||||
int coreDumpEnabled;
|
||||
int localConsentMask;
|
||||
int localdebugmode;
|
||||
|
||||
char agentHash[UTIL_SHA384_HASHSIZE];
|
||||
char serverHash[UTIL_SHA384_HASHSIZE];
|
||||
|
||||
@@ -4946,7 +4946,12 @@ duk_ret_t ILibDuktape_http_generateNonce(duk_context *ctx)
|
||||
return(ILibDuktape_Error(ctx, "Specified length is too long. Please Specify a value < %llu", (uint64_t)sizeof(ILibScratchPad)));
|
||||
}
|
||||
}
|
||||
|
||||
duk_ret_t ILibDuktape_http_resolve(duk_context *ctx)
|
||||
{
|
||||
duk_push_sprintf(ctx, "resolve('%s');", duk_require_string(ctx, 0));
|
||||
duk_eval(ctx);
|
||||
return(1);
|
||||
}
|
||||
void ILibDuktape_HttpStream_http_PUSH(duk_context *ctx, void *chain)
|
||||
{
|
||||
duk_push_object(ctx); // [http]
|
||||
@@ -4959,6 +4964,7 @@ void ILibDuktape_HttpStream_http_PUSH(duk_context *ctx, void *chain)
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "parseUri", ILibDuktape_httpStream_parseUri, 1);
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "webSocketStream", ILibDuktape_httpStream_webSocketStream_new, DUK_VARARGS);
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "generateNonce", ILibDuktape_http_generateNonce, 1);
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "resolve", ILibDuktape_http_resolve, 1);
|
||||
|
||||
// HTTP Global Agent
|
||||
duk_push_c_function(ctx, ILibDuktape_HttpStream_Agent_new, DUK_VARARGS); // [http][newAgent]
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -2692,6 +2692,118 @@ void ILibDuktape_Polyfills_promise_wait(duk_context *ctx)
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "wait", ILibDuktape_Polyfills_promise_wait_impl, DUK_VARARGS);
|
||||
duk_pop(ctx); // ...
|
||||
}
|
||||
duk_ret_t ILibDuktape_PAC_Impl(duk_context *ctx)
|
||||
{
|
||||
duk_push_current_function(ctx);
|
||||
duk_context *ex = (duk_context*)Duktape_GetPointerProperty(ctx, -1, "embedded");
|
||||
char *fqdn = Duktape_GetStringPropertyValue(ctx, -1, "fqdn", "127.0.0.2");
|
||||
char *url = (char*)duk_require_string(ctx, 0);
|
||||
char *addr;
|
||||
unsigned short port;
|
||||
char *path;
|
||||
|
||||
duk_push_sprintf(ex, "function myIpAddress() { return('%s'); }", fqdn);
|
||||
duk_eval_noresult(ex);
|
||||
|
||||
ILibParseUri(url, &addr, &port, &path, NULL);
|
||||
duk_push_sprintf(ex, "FindProxyForURL('%s', '%s');", url, addr);
|
||||
if (duk_peval(ex) != 0)
|
||||
{
|
||||
sprintf_s(ILibScratchPad, sizeof(ILibScratchPad), duk_safe_to_string(ex, -1));
|
||||
duk_pop(ex);
|
||||
return(ILibDuktape_Error(ctx, "Error: %s", ILibScratchPad));
|
||||
}
|
||||
duk_push_sprintf(ctx, "%s", duk_get_string(ex, -1));
|
||||
duk_pop(ex);
|
||||
duk_string_split(ctx, -1, " "); // [str][array]
|
||||
duk_array_shift(ctx, -1); // [str][array][type]
|
||||
if (strcasecmp("DIRECT", (char*)duk_get_string(ctx, -1)) == 0)
|
||||
{
|
||||
duk_push_null(ctx);
|
||||
}
|
||||
else
|
||||
{
|
||||
duk_array_pop(ctx, -2);
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
duk_ret_t ILibDuktape_PAC_MyIPAddress(duk_context *ctx)
|
||||
{
|
||||
duk_push_string(ctx, "172.16.2.5");
|
||||
return(1);
|
||||
}
|
||||
|
||||
extern duk_ret_t ILibDuktape_Polyfills_resolve(duk_context *ctx);
|
||||
extern void ILibDuktape_Polyfills_String(duk_context *ctx);
|
||||
extern duk_ret_t ILibDuktape_Polyfills_ipv4From(duk_context *ctx);
|
||||
|
||||
duk_ret_t ILibDuktape_PAC_Create(duk_context *ctx)
|
||||
{
|
||||
duk_size_t wpadLen;
|
||||
char *wpad = (char*)duk_get_lstring(ctx, 0, &wpadLen);
|
||||
duk_context *ex = ILibDuktape_ScriptContainer_InitializeJavaScriptEngine_minimal();
|
||||
|
||||
if (ILibDuktape_ScriptContainer_CompileJavaScriptEx(ex, wpad, (int)wpadLen, "wpad.js", 7) != 0 ||
|
||||
ILibDuktape_ScriptContainer_ExecuteByteCode(ex) != 0)
|
||||
{
|
||||
char *err = (char*)duk_safe_to_string(ex, -1);
|
||||
sprintf_s(ILibScratchPad, sizeof(ILibScratchPad), "%s", err);
|
||||
duk_destroy_heap(ex);
|
||||
return(ILibDuktape_Error(ctx, "Error in WPAD: %s", ILibScratchPad));
|
||||
}
|
||||
duk_pop(ex);
|
||||
|
||||
duk_push_global_object(ex);
|
||||
ILibDuktape_Polyfills_String(ex);
|
||||
ILibDuktape_CreateInstanceMethod(ex, "resolve", ILibDuktape_Polyfills_resolve, 1);
|
||||
ILibDuktape_CreateInstanceMethod(ex, "_ipv4From", ILibDuktape_Polyfills_ipv4From, 1);
|
||||
duk_pop(ex);
|
||||
|
||||
char *pac = NULL;
|
||||
pac[ILibBase64Decode("LyoNCkNvcHlyaWdodCAyMDIxIEludGVsIENvcnBvcmF0aW9uDQpAYXV0aG9yIEJyeWFuIFJvZQ0KDQpMaWNlbnNlZCB1bmRlciB0aGUgQXBhY2hlIExpY2Vuc2UsIFZlcnNpb24gMi4wICh0aGUgIkxpY2Vuc2UiKTsNCnlvdSBtYXkgbm90IHVzZSB0aGlzIGZpbGUgZXhjZXB0IGluIGNvbXBsaWFuY2Ugd2l0aCB0aGUgTGljZW5zZS4NCllvdSBtYXkgb2J0YWluIGEgY29weSBvZiB0aGUgTGljZW5zZSBhdA0KDQogICAgaHR0cDovL3d3dy5hcGFjaGUub3JnL2xpY2Vuc2VzL0xJQ0VOU0UtMi4wDQoNClVubGVzcyByZXF1aXJlZCBieSBhcHBsaWNhYmxlIGxhdyBvciBhZ3JlZWQgdG8gaW4gd3JpdGluZywgc29mdHdhcmUNCmRpc3RyaWJ1dGVkIHVuZGVyIHRoZSBMaWNlbnNlIGlzIGRpc3RyaWJ1dGVkIG9uIGFuICJBUyBJUyIgQkFTSVMsDQpXSVRIT1VUIFdBUlJBTlRJRVMgT1IgQ09ORElUSU9OUyBPRiBBTlkgS0lORCwgZWl0aGVyIGV4cHJlc3Mgb3IgaW1wbGllZC4NClNlZSB0aGUgTGljZW5zZSBmb3IgdGhlIHNwZWNpZmljIGxhbmd1YWdlIGdvdmVybmluZyBwZXJtaXNzaW9ucyBhbmQNCmxpbWl0YXRpb25zIHVuZGVyIHRoZSBMaWNlbnNlLg0KKi8NCg0KDQoNCi8vIEV2YWx1YXRlcyBob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vZiBkb3RzKSBpbiB0aGUgaG9zdG5hbWUNCmZ1bmN0aW9uIGRuc0RvbWFpbkxldmVscyhob3N0KQ0Kew0KICAgIHJldHVybiAoaG9zdC5zcGxpdCgnLicpLmxlbmd0aCAtIDEpOw0KfQ0KDQoNCmZ1bmN0aW9uIHdlZWtkYXlSYW5nZShzdGFydCwgZW5kKQ0Kew0KDQp9DQpmdW5jdGlvbiBkYXRlUmFuZ2Uoc3RhcnQsIGVuZCkNCnsNCg0KfQ0KZnVuY3Rpb24gdGltZVJhbmdlKHN0YXJ0LCBlbmQpDQp7DQoNCn0NCg0KZnVuY3Rpb24gYWxlcnQobXNnKQ0Kew0KDQp9DQoNCg==", 3356, &pac)] = 0;
|
||||
duk_peval_string_noresult(ex, pac);
|
||||
free(pac);
|
||||
|
||||
duk_push_c_function(ctx, ILibDuktape_PAC_Impl, 1);
|
||||
duk_push_pointer(ctx, ex);
|
||||
duk_put_prop_string(ctx, -2, "embedded");
|
||||
|
||||
char fqdn[] = "(function getFqdnInterface()\
|
||||
{\
|
||||
var interfaces = require('os').networkInterfaces();\
|
||||
for (var i in interfaces)\
|
||||
{\
|
||||
for (var j in interfaces[i])\
|
||||
{\
|
||||
if (interfaces[i][j].fqdn != '' && interfaces[i][j].family == 'IPv4' && interfaces[i][j].status != 'down')\
|
||||
{\
|
||||
return (interfaces[i][j].address);\
|
||||
}\
|
||||
}\
|
||||
}\
|
||||
return ('127.0.0.1');\
|
||||
})();";
|
||||
|
||||
duk_eval_string(ctx, fqdn); // [func][fqdn]
|
||||
duk_put_prop_string(ctx, -2, "fqdn");
|
||||
|
||||
return(1);
|
||||
}
|
||||
duk_ret_t ILibDuktape_PAC_Find(duk_context *ctx)
|
||||
{
|
||||
duk_eval_string(ctx, "resolve('wpad');");
|
||||
}
|
||||
void ILibDuktape_PAC_PUSH(duk_context *ctx, void *chain)
|
||||
{
|
||||
duk_push_object(ctx);
|
||||
ILibDuktape_WriteID(ctx, "PAC");
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "Create", ILibDuktape_PAC_Create, 1);
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "Find", ILibDuktape_PAC_Find, 0);
|
||||
}
|
||||
void ILibDuktape_PAC_Init(duk_context *ctx)
|
||||
{
|
||||
ILibDuktape_ModSearch_AddHandler(ctx, "PAC", ILibDuktape_PAC_PUSH);
|
||||
}
|
||||
|
||||
duk_context *ILibDuktape_ScriptContainer_InitializeJavaScriptEngineEx3(duk_context *ctx, SCRIPT_ENGINE_SECURITY_FLAGS securityFlags, unsigned int executionTimeout, void *chain, char **argList, ILibSimpleDataStore *db, char *exePath, ILibProcessPipe_Manager pipeManager, ILibDuktape_HelperEvent exitHandler, void *exitUser)
|
||||
{
|
||||
@@ -2755,6 +2867,7 @@ duk_context *ILibDuktape_ScriptContainer_InitializeJavaScriptEngineEx3(duk_conte
|
||||
ILibDuktape_MemoryStream_Init(ctx); // Add MemoryStream support
|
||||
ILibDuktape_NetworkMonitor_Init(ctx);
|
||||
ILibDuktape_CompressedStream_init(ctx);
|
||||
ILibDuktape_PAC_Init(ctx);
|
||||
|
||||
if (exitHandler != NULL) { ILibDuktape_Helper_AddHeapFinalizer(ctx, exitHandler, exitUser); }
|
||||
|
||||
|
||||
@@ -10684,10 +10684,10 @@ int ILibResolveEx3(char* hostname, char *service, struct sockaddr_in6* addr6, in
|
||||
if (hname != NULL) { MultiByteToWideChar(CP_UTF8, 0, (LPCCH)hostname, -1, (LPWSTR)hname, (int)hnameLen); }
|
||||
if (svc != NULL) { MultiByteToWideChar(CP_UTF8, 0, (LPCCH)service, -1, (LPWSTR)svc, (int)svcLen); }
|
||||
r = GetAddrInfoW(hname, svc, &hints, &result);
|
||||
if (r != 0) { if (result != NULL) { FreeAddrInfoW(result); } return r; }
|
||||
if (r != 0) { if (result != NULL) { FreeAddrInfoW(result); } return 0; }
|
||||
#else
|
||||
r = getaddrinfo(hostname, service, &hints, &result);
|
||||
if (r != 0) { if (result != NULL) { freeaddrinfo(result); } return r; }
|
||||
if (r != 0) { if (result != NULL) { freeaddrinfo(result); } return 0; }
|
||||
#endif
|
||||
|
||||
if (result == NULL) return -1;
|
||||
@@ -10729,7 +10729,7 @@ int ILibResolveEx3(char* hostname, char *service, struct sockaddr_in6* addr6, in
|
||||
int ILibResolveEx2(char* hostname, unsigned short port, struct sockaddr_in6* addr6, int count)
|
||||
{
|
||||
char service[16];
|
||||
if (sprintf_s(service, sizeof(service), "%u", port) <= 0) { return 1; }
|
||||
if (sprintf_s(service, sizeof(service), "%u", port) <= 0) { return 0; }
|
||||
return(ILibResolveEx3(hostname, service, addr6, count));
|
||||
}
|
||||
|
||||
|
||||
@@ -86,6 +86,15 @@ function nativeAddCompressedModule(name)
|
||||
}
|
||||
module.exports(ret);
|
||||
}
|
||||
function nativeBase64(name)
|
||||
{
|
||||
var value = Buffer.from(getJSModule(name)).toString('base64');
|
||||
var ret = "char *" + name + " = NULL;\n";
|
||||
ret += (name + '[ILibBase64Decode("' + value + '", ' + value.length + ', &' + name + ')] = 0;\n');
|
||||
ret += ('duk_peval_string_noresult(ex, ' + name + ');\n');
|
||||
ret += ('free(' + name + ');\n');
|
||||
module.exports(ret);
|
||||
}
|
||||
function nativeAddModule(name,single)
|
||||
{
|
||||
var value = getJSModule(name);
|
||||
@@ -654,5 +663,6 @@ switch(process.platform)
|
||||
}
|
||||
module.exports.nativeAddModule = nativeAddModule;
|
||||
module.exports.nativeAddCompressedModule = nativeAddCompressedModule;
|
||||
module.exports.nativeBase64 = nativeBase64;
|
||||
module.exports.dispatchWrite = dispatchWrite;
|
||||
module.exports.dispatchRead = dispatchRead;
|
||||
110
modules/pac.js
Normal file
110
modules/pac.js
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
Copyright 2021 Intel Corporation
|
||||
@author Bryan Roe
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
// Evaluates hostnames and returns true if hostnames match
|
||||
function dnsDomainIs(target, host)
|
||||
{
|
||||
if(!host.startsWith('.'))
|
||||
{
|
||||
host = '.' + host;
|
||||
}
|
||||
return (target.toLowerCase().endsWith(host.toLowerCase()));
|
||||
}
|
||||
|
||||
// match hostname or URL to a specified shell expression, returns true if matched
|
||||
function shExpMatch(host, exp)
|
||||
{
|
||||
exp = exp.split('.').join('\\.');
|
||||
exp = exp.split('?').join('.');
|
||||
exp = exp.split('*').join('.*');
|
||||
exp = '^' + exp + '$';
|
||||
return (host.search(exp) >= 0);
|
||||
}
|
||||
|
||||
// evaluates the IP address of a hostname, and if within a specified subnet returns true
|
||||
function isInNet(target, address, mask)
|
||||
{
|
||||
try
|
||||
{
|
||||
var destAddr = resolve(target)._integers[0];
|
||||
var maskAddr = resolve(mask)._integers[0];
|
||||
return (_ipv4From(destAddr & maskAddr) == address);
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
|
||||
// resolve host name to address
|
||||
function dnsResolve(host)
|
||||
{
|
||||
var result = resolve(host);
|
||||
if(result.length == 0)
|
||||
{
|
||||
return ('');
|
||||
}
|
||||
else
|
||||
{
|
||||
return (result[0]);
|
||||
}
|
||||
}
|
||||
|
||||
// return true if the hostname contains no dots
|
||||
function isPlainHostName(host)
|
||||
{
|
||||
return (host.indexOf('.') < 0);
|
||||
}
|
||||
|
||||
// evaluate hostname and return true IFF exact match
|
||||
function localHostOrDomainIs(target, host)
|
||||
{
|
||||
return (dnsResolve(target) == host);
|
||||
}
|
||||
|
||||
// return true if resolve is successful
|
||||
function isResolvable(host)
|
||||
{
|
||||
return (resolve(host).length > 0);
|
||||
}
|
||||
|
||||
// returns the number of DNS domain levels (number of dots) in the hostname
|
||||
function dnsDomainLevels(host)
|
||||
{
|
||||
return (host.split('.').length - 1);
|
||||
}
|
||||
|
||||
|
||||
function weekdayRange(start, end)
|
||||
{
|
||||
|
||||
}
|
||||
function dateRange(start, end)
|
||||
{
|
||||
|
||||
}
|
||||
function timeRange(start, end)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
function alert(msg)
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user