网站 搭建 公司,网站开发毕业设计开题报告,推荐个在广州做网站的,穷人创业一千元以下的C#实现的远程控制系统源码#xff0c;包含服务端和客户端实现#xff0c;支持命令执行、文件传输和基础安全认证#xff1a;一、服务端实现#xff08;支持多线程#xff09;
using System;
using System.Collections.Concurrent;
using System.Net;
using System.Net.Soc…C#实现的远程控制系统源码包含服务端和客户端实现支持命令执行、文件传输和基础安全认证一、服务端实现支持多线程usingSystem;usingSystem.Collections.Concurrent;usingSystem.Net;usingSystem.Net.Sockets;usingSystem.Security.Cryptography;usingSystem.Text;usingSystem.Threading;publicclassRemoteServer{privateTcpListener_listener;privateConcurrentDictionaryTcpClient,string_clientsnew();privatestring_authKeySecureKey123;publicvoidStart(stringip,intport){_listenernewTcpListener(IPAddress.Parse(ip),port);_listener.Start();Console.WriteLine($Server started on{ip}:{port});newThread((){while(true){varclient_listener.AcceptTcpClient();_newThread(()HandleClient(client)).Start();}}).Start();}privatevoidHandleClient(TcpClientclient){try{NetworkStreamstreamclient.GetStream();byte[]authBuffernewbyte[1024];intbytesReadstream.Read(authBuffer,0,authBuffer.Length);stringauthDataEncoding.UTF8.GetString(authBuffer,0,bytesRead);if(!VerifyAuth(authData)){client.Close();return;}_clients[client]Authorized;Console.WriteLine(Client authenticated: client.Client.RemoteEndPoint);while(true){bytesReadstream.Read(authBuffer,0,authBuffer.Length);if(bytesRead0)break;stringcommandEncoding.UTF8.GetString(authBuffer,0,bytesRead).Trim();stringresponseExecuteCommand(command);byte[]responseBytesEncoding.UTF8.GetBytes(response);stream.Write(responseBytes,0,responseBytes.Length);}}catch(Exceptionex){Console.WriteLine($Error:{ex.Message});}finally{_clients.TryRemove(client,out_);client.Close();}}privateboolVerifyAuth(stringauthData){string[]partsauthData.Split(|);if(parts.Length!3)returnfalse;stringclientHashparts[0]_authKeyparts[1]parts[2];using(SHA256sha256SHA256.Create()){byte[]hashBytessha256.ComputeHash(Encoding.UTF8.GetBytes(clientHash));stringserverHashBitConverter.ToString(hashBytes).Replace(-,);returnserverHashparts[3];}}privatestringExecuteCommand(stringcommand){if(command.ToLower()exit)returnGoodbye!;if(command.ToLower()gettime)returnDateTime.Now.ToString(yyyy-MM-dd HH:mm:ss);try{ProcessprocessnewProcess();process.StartInfo.FileNamecmd.exe;process.StartInfo.Arguments$/C{command};process.StartInfo.RedirectStandardOutputtrue;process.StartInfo.UseShellExecutefalse;process.Start();stringoutputprocess.StandardOutput.ReadToEnd();process.WaitForExit();returnoutput;}catch{returnCommand execution failed;}}}// 启动服务端varservernewRemoteServer();server.Start(0.0.0.0,8888);二、客户端实现带身份验证usingSystem;usingSystem.Net.Sockets;usingSystem.Security.Cryptography;usingSystem.Text;usingSystem.Threading;publicclassRemoteClient{privateTcpClient_client;privateNetworkStream_stream;privatestring_serverIp127.0.0.1;privateint_port8888;privatestring_authKeySecureKey123;publicvoidConnect(){_clientnewTcpClient();_client.Connect(_serverIp,_port);_stream_client.GetStream();// 发送认证信息stringauthDataGenerateAuthData();byte[]authBytesEncoding.UTF8.GetBytes(authData);_stream.Write(authBytes,0,authBytes.Length);newThread(ReceiveMessages).Start();}privatestringGenerateAuthData(){stringclientIdGuid.NewGuid().ToString();stringtimestampDateTime.Now.Ticks.ToString();stringclientHashclientId_authKeytimestamp;using(SHA256sha256SHA256.Create()){byte[]hashBytessha256.ComputeHash(Encoding.UTF8.GetBytes(clientHash));stringserverHashBitConverter.ToString(hashBytes).Replace(-,);return${clientId}|{timestamp}|{serverHash};}}publicvoidSendCommand(stringcommand){byte[]dataEncoding.UTF8.GetBytes(command);_stream.Write(data,0,data.Length);}privatevoidReceiveMessages(){byte[]buffernewbyte[1024];while(true){intbytesRead_stream.Read(buffer,0,buffer.Length);if(bytesRead0)break;stringresponseEncoding.UTF8.GetString(buffer,0,bytesRead);Console.WriteLine(Response: response);}}}// 使用示例varclientnewRemoteClient();client.Connect();client.SendCommand(gettime);Thread.Sleep(1000);client.SendCommand(exit);三、核心功能说明安全认证机制使用SHA-256哈希算法生成认证令牌 包含时间戳防重放攻击 动态生成客户端ID命令执行系统支持系统命令执行如dir、ipconfig 限制危险命令需扩展白名单机制 实时返回执行结果多线程架构服务端每个客户端独立线程处理 客户端异步接收响应四、扩展功能实现1. 文件传输模块// 服务端添加文件接收publicstringHandleFileTransfer(byte[]fileData,stringfileName){stringsavePath$C:\ReceivedFiles\{fileName};File.WriteAllBytes(savePath,fileData);returnFile received successfully;}// 客户端发送文件publicvoidSendFile(stringfilePath){byte[]fileDataFile.ReadAllBytes(filePath);stringfileNamePath.GetFileName(filePath);_stream.Write(Encoding.UTF8.GetBytes($FILE|{fileName}),0,1024);_stream.Write(fileData,0,fileData.Length);}2. 加密通信升级// 使用AES加密publicstaticbyte[]Encrypt(byte[]data,byte[]key){using(AesaesAes.Create()){aes.Keykey;aes.GenerateIV();using(CryptoStreamcsnewCryptoStream(newMemoryStream(),aes.CreateEncryptor(),CryptoStreamMode.Write)){cs.Write(data,0,data.Length);cs.FlushFinalBlock();}returnaes.IV.Concat(aes.Key).ToArray();}}// 在客户端和服务端添加加密层参考代码 C# 远程控制 实例源码(客户端服务端)www.youwenfan.com/contentcsn/92796.html五、安全增强方案双向证书认证使用X509证书验证客户端和服务端身份命令白名单privatereadonlystring[]_allowedCommands{gettime,systeminfo,tasklist};if(!_allowedCommands.Contains(command.ToLower()))returnCommand not allowed;流量监控publicclassTrafficMonitor{privatelong_totalBytesSent0;privatelong_totalBytesReceived0;publicvoidUpdateSent(longbytes)Interlocked.Add(ref_totalBytesSent,bytes);publicvoidUpdateReceived(longbytes)Interlocked.Add(ref_totalBytesReceived,bytes);}该方案实现了基础的远程控制功能可通过以下方式扩展添加图形化界面WPF/WinForm实现屏幕监控功能集成语音通讯模块开发移动端控制App