Exemplo n.º 1
0
        // Create an implant object and return it
        public static ImplantServiceSocket CreateImplant(string socketId, dynamic socket)
        {
            // generating a random identifier for the socket
            if (socketId == null)
            {
                socketId = RandomStringGenerator(20);
            }

            // creating the client object for the socket
            ImplantServiceSocket implant = new ImplantServiceSocket(socketId, socket);

            // setting the log file for the client socket session
            implant.SetLogFile(new LogFile(socketId));

            // adding the implant socket session to the sockets
            Program.implantSockets.TryAdd(socketId, implant);

            return(implant);
        }
Exemplo n.º 2
0
        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();
        }