Advertisement
anuisud1

Pipes

Mar 26th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.06 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.IO.Pipes;
  4. using System.Runtime.InteropServices;
  5. using System.Threading;
  6. using System.Windows.Forms;
  7.  
  8. namespace Test_Exploit
  9. {
  10.     class Pipes
  11.     {
  12.         public static string luapipename = "TestExploit";
  13.  
  14.         [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  15.         [return: MarshalAs(UnmanagedType.Bool)]
  16.         private static extern bool WaitNamedPipe(string name, int timeout);
  17.  
  18.         public static bool NamedPipeExist(string pipeName)
  19.         {
  20.             bool result;
  21.             try
  22.             {
  23.                 int timeout = 0;
  24.                 if (!WaitNamedPipe(Path.GetFullPath(string.Format("\\\\\\\\.\\\\pipe\\\\{0}", pipeName)), timeout))
  25.                 {
  26.                     int lastWin32Error = Marshal.GetLastWin32Error();
  27.                     if (lastWin32Error == 0)
  28.                     {
  29.                         result = false;
  30.                         return result;
  31.                     }
  32.                     if (lastWin32Error == 2)
  33.                     {
  34.                         result = false;
  35.                         return result;
  36.                     }
  37.                 }
  38.                 result = true;
  39.             }
  40.             catch (Exception)
  41.             {
  42.                 result = false;
  43.             }
  44.             return result;
  45.         }
  46.  
  47.         public static void LuaPipe(string script)
  48.         {
  49.             if (NamedPipeExist(luapipename))
  50.             {
  51.                 new Thread(() =>
  52.                 {
  53.                     try
  54.                     {
  55.                         using (NamedPipeClientStream namedPipeClientStream = new NamedPipeClientStream(".", luapipename, PipeDirection.Out))
  56.                         {
  57.                             namedPipeClientStream.Connect();
  58.                             using (StreamWriter streamWriter = new StreamWriter(namedPipeClientStream, System.Text.Encoding.Default, 999999))//changed buffer to max 1mb since default buffer is 1kb
  59.                             {
  60.                                 streamWriter.Write(script);
  61.                                 streamWriter.Dispose();
  62.                             }
  63.                             namedPipeClientStream.Dispose();
  64.                         }
  65.                     }
  66.                     catch (IOException)
  67.                     {
  68.                         MessageBox.Show("Error occured connecting to the pipe.", "Connection Failed!", MessageBoxButtons.OK, MessageBoxIcon.Hand);
  69.                     }
  70.                     catch (Exception ex)
  71.                     {
  72.                         MessageBox.Show(ex.Message.ToString());
  73.                     }
  74.                 }).Start();
  75.             }
  76.             else
  77.             {
  78.                 MessageBox.Show("Inject " + "TestExploit.dll" + " before Using this!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  79.                 return;
  80.             }
  81.         }
  82.  
  83.         internal static void NamedPipeExist()
  84.         {
  85.             throw new NotImplementedException();
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement