public void RegisterLinkedImplantInfo(dynamic linkObj) { foreach (JProperty i in linkObj) { // define the linked child object ImplantServiceSocket linkedChild; // use the socketID sent by the parent link string socketId = i.Name; // if linked socket is not in the list create a new one if (!linkedChildren.ContainsKey(i.Name)) { // creating the child object for the implant socket linkedChild = ImplantManagement.CreateImplant(socketId, webSocket); } else { linkedChild = linkedChildren[i.Name]; } // adding the child object to the linkedChildren linkedChildren.TryAdd(socketId, linkedChild); // set the proto sent by the parent link linkedChild.link_uri = linkObj[i.Name].link_uri; // adding the parent information to the linked socket linkedChild.linkedParent = webSocketId; // adding the IP information to the linked socket linkedChild.implantIP = linkObj[i.Name].implantIP; // update link dates and status using data from the parent //linkedChild.dateConnected = linkObj[i.Name].dateConnected; //linkedChild.dateDisconnected = linkObj[i.Name].dateDisconnected; linkedChild.implantStatus = linkObj[i.Name].status; // print debug for each session received. Console.WriteLine("Implant linking for {0} is done.", linkedChild.webSocketId); } // remember to reset the menu Program.petaconsole.ResetMenu(); }
public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHostingEnvironment env, ILoggerFactory loggerFactory) { // Use this for the static files to serve app.UseStaticFiles(); app.UseStaticFiles(new StaticFileOptions() { FileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider( Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot/tools")), RequestPath = new PathString("/tools"), ServeUnknownFileTypes = true }); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } var webSocketOptions = new WebSocketOptions() { // Keepalive may be important for some detections KeepAliveInterval = TimeSpan.FromSeconds(120), ReceiveBufferSize = receiveChunkSize }; app.UseWebSockets(webSocketOptions); app.Use(async(context, next) => { if (context.Request.Path == "/ws") { if (context.WebSockets.IsWebSocketRequest) { // tasking var completion = new TaskCompletionSource <object>(); // getting the socket var socket = await context.WebSockets.AcceptWebSocketAsync(); // handling the implant, adding direct route while creating the object ImplantServiceSocket implant = ImplantManagement.CreateImplant(null, socket); // set the IP implant.implantIP = context.Connection.RemoteIpAddress.ToString(); // set the socket link URI string headuri = "ws://"; if (context.Request.IsHttps) { headuri = "wss://"; } implant.link_uri = headuri + context.Connection.LocalIpAddress + ":" + context.Connection.LocalPort + context.Request.Path; Program.petaconsole.ResetMenu(); // start receiving and sending async await Task.WhenAll(implant.Receive(), implant.Send()); await completion.Task; } else { context.Response.StatusCode = 400; } } else { await next(); } }); app.UseFileServer(); }