-
Notifications
You must be signed in to change notification settings - Fork 4
/
MainForm.cs
364 lines (321 loc) · 13.7 KB
/
MainForm.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
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
using System;
using System.ComponentModel;
using System.Collections;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Net;
namespace Verda
{
public partial class MainForm : Form
{
private string argConfig;
private string argRange;
private string arguments;
private int debugcounter = 1;
private string nextliner;
public string chosenPreset;
private string verdaVersion;
private string verdaVersionAdditional = ("Delayed Apologies");
private string NmapLocation;
private string availVersion;
WebClient client = new WebClient();
private bool waitForBrute;
DirectoryInfo reportsDir;
NmapWorker nmap;
NmapReceiver _nmapReceiver;
NmapAnalyzer _nmapAnalyzer;
ContextMenu contextMenu = new System.Windows.Forms.ContextMenu();
MenuItem menuItem = new MenuItem("Copy");
public MainForm()
{
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e)
{
//версию в шапку
Version version = Assembly.GetEntryAssembly().GetName().Version;
verdaVersion = version.Major + "." + version.Minor + "." + (version.Build - 5677) + "." + (version.Revision / 86);
this.Text = "Verda " + verdaVersion + " " + verdaVersionAdditional;
//список пресетов
ArrayList Presets = new ArrayList();
Presets.Add(new Preset("http-title", "http-title"));
Presets.Add(new Preset("Camera(Normal)", "Webcam"));
Presets.Add(new Preset("Camera(Fastest)", "Webcam-fast"));
Presets.Add(new Preset("Camera(Alternative)", "Webcam-advanced"));
Presets.Add(new Preset("Custom args", "custom"));
presetComboBox.DataSource = Presets;
presetComboBox.DisplayMember = "DisplayName";
presetComboBox.ValueMember = "ShortName";
try
{
availVersion = client.DownloadString("http://verda-dl.zz.mu/version");
availVersion = availVersion.Remove(availVersion.Length - 1);
if (availVersion == verdaVersion)
{
updateLabel.Text = "you are using the latest version";
updateLabel.ForeColor = Color.Green;
}
else
{
updateLabel.Text = "update is available:" + availVersion;
updateLabel.ForeColor = Color.Red;
}
}
catch (Exception)
{
updateLabel.Text = "verda-dl.zz.mu unreachable?";
updateLabel.ForeColor = Color.Red;
}
//восстановление сессии
if (File.Exists("restore"))
{
using (StreamReader resread = new StreamReader(File.Open("restore", FileMode.Open)))
{
presetComboBox.SelectedValue = resread.ReadLine();
presetRangeBox.Text = resread.ReadLine();
NmapLocation = resread.ReadLine();
resread.Close();
}
}
else
{
presetComboBox.SelectedValue = "Webcam-fast";
presetRangeBox.Text = "-iR 10000";
}
//обеспечение контекстного меню
menuItem.Click += new EventHandler(CopyAction);
contextMenu.MenuItems.Add(menuItem);
resultsBox.ContextMenu = contextMenu;
//outputBox.ContextMenu = contextMenu;
//пишем в Version
System.IO.StreamWriter verwrite = new System.IO.StreamWriter("version");
verwrite.WriteLine(verdaVersion);
verwrite.Close();
//ищем Nmap
locateNmap();
}
private void locateNmap()
{
if (File.Exists(NmapLocation))
{
labelAboutNmap.Text = "Path to nmap.exe set as " + NmapLocation;
}
else
if (File.Exists("C:/Program Files (x86)/Nmap/nmap.exe"))
{
NmapLocation = "C:/Program Files (x86)/Nmap/nmap.exe";
labelAboutNmap.Text = "Path to nmap.exe automatically set as " + NmapLocation;
}
else
if (File.Exists("C:/Program Files/Nmap/nmap.exe"))
{
NmapLocation = "C:/Program Files/Nmap/nmap.exe";
labelAboutNmap.Text = "Path to nmap.exe automatically set as " + NmapLocation;
}
else
if (File.Exists("nmap/nmap.exe"))
{
NmapLocation = "nmap/nmap.exe";
labelAboutNmap.Text = "Path to nmap.exe automatically set as " + NmapLocation;
}
else
{
MessageBox.Show("nmap.exe not found. Install NMAP or set path to nmap.exe in settings", "nmap.exe not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
labelAboutNmap.Text = "nmap.exe not found!";
}
}
public void OnScanEnd()
{
if (Program.CamTargets <= 0)
{
waitForBrute = false;
sendButton.Enabled = true;
cancelScanButton.Enabled = false;
this.BackColor = Color.GhostWhite;
debugPost("Verda has finished.");
busyPic.Image = null;
statsLabel.Text = "Verda has finished.";
busyPic.Image = null;
optionsTabControl.Enabled = true;
resultsPost(Times.TimeReport() + "Scan completed. Found:" + _nmapAnalyzer.resultCounter + System.Environment.NewLine);
reportTimer.Enabled = false;
System.IO.StreamWriter report = new System.IO.StreamWriter(reportsDir + "/nmap.txt");
report.Write(outputBox.Text);
report.Close();
report = new System.IO.StreamWriter(reportsDir + "/Verda.txt");
report.Write("Verda version " + verdaVersion + System.Environment.NewLine + resultsBox.Text);
report.Close();
}
else
{
statsLabel.Text = "NMAP has finished, waiting for brute to finish...";
waitForBrute = true;
}
}
private void sendButton_Click(object sender, EventArgs e)
{
statsLabel.Text = "trying to launch...";
debugPost("Trying to launch...");
Program.CamTargets = 0;
System.IO.StreamWriter reswrite = new System.IO.StreamWriter("restore");
reswrite.WriteLine(presetComboBox.SelectedValue);
reswrite.WriteLine(presetRangeBox.Text);
reswrite.WriteLine(NmapLocation);
reswrite.Close();
sendButton.Enabled = false;
optionsTabControl.SelectedIndex = 0;
waitForBrute = false;
scanLaunch();
}
private void scanLaunch()
{
if (File.Exists(NmapLocation))
{
reportsDir = new DirectoryInfo("reports/" + "Verda-report-" + Times.DateFolderName());
reportsDir.Create();
outputBox.Text = null;
resultsBox.Text = null;
reportTimer.Enabled = true;
outputBox.AppendText("Command: " + arguments + System.Environment.NewLine);
argConfig = null;
argRange = null;
generateArguments();
resultsPost(DateTime.Now.ToString("[HH:mm:ss] ") + "Scan started. Target: " + argRange + " , Preset: " + chosenPreset + System.Environment.NewLine);
optionsTabControl.Enabled = false;
inputBox.Text = arguments;
cancelScanButton.Enabled = true;
nmap = new NmapWorker();
_nmapReceiver = new NmapReceiver();
_nmapAnalyzer = new NmapAnalyzer();
_nmapAnalyzer.mode = chosenPreset;
nmap.Received += _nmapReceiver.OnReceive;
nmap.Received += _nmapAnalyzer.Parse;
nmap.Ended += OnScanEnd;
nmap.NmapRun(arguments, NmapLocation);
debugPost("Scan started.");
busyPic.Image = Verda.Properties.Resources.gif_loading;
statsLabel.Text = "Scan started.";
this.BackColor = Color.Lavender;
}
else
MessageBox.Show("nmap.exe not found. Install NMAP or set path to nmap.exe in settings", "nmap.exe not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private void generateArguments()
{
chosenPreset = presetComboBox.SelectedValue.ToString();
argRange = presetRangeBox.Text;
if (chosenPreset == "http-title") { argConfig = "-T5 -n -Pn -p 80,443 --open --script http-title --stats-every 5s"; }
if (chosenPreset == "Webcam") { argConfig = "-T3 -n -Pn -p 80,8080 --open --script http-title --stats-every 5s"; }
if (chosenPreset == "Webcam-fast") { argConfig = "-T5 -n -Pn -p 80,8080 --open --script http-title --stats-every 5s"; }
if (chosenPreset == "Webcam-advanced") { argConfig = "-T5 -n -Pn -p 80,82,83,1010,1614,2000,4002,5000,5900,8003,8028,8080,8081,8082,8888,12122 --open --stats-every 5s"; }
if (chosenPreset == "custom") { argConfig = customArgTextBox.Text + " "; }
arguments = argConfig + " " + argRange;
}
private void debugPost(string message)
{
if (debugBox.Text == "") { nextliner = null; } else { nextliner = "\r\n"; }
debugBox.AppendText(nextliner + debugcounter + ": " + message);
debugcounter += 1;
}
private void resultsPost(string message)
{
resultsBox.AppendText(message);
}
private void statsPost(string message)
{
statsLabel.Text = message;
}
public delegate void RTResultsPost(string message);
public delegate void RTStatsPost(string message);
private void debugBox_TextChanged(object sender, EventArgs e)
{
debugBox.Select(debugBox.Text.Length, 0);
debugBox.ScrollToCaret();
}
private void cancelScanButton_Click(object sender, EventArgs e)
{
Process[] nmaps = Process.GetProcessesByName("nmap");
if (nmaps.Length > 0)
{
foreach (Process nmap in nmaps)
{
nmap.Kill();
}
}
debugPost("Force stop.");
resultsPost(DateTime.Now.ToString("[HH:mm:ss] ") + "Force stop." + System.Environment.NewLine);
}
void CopyAction(object sender, EventArgs e)
{
Clipboard.SetText(resultsBox.SelectedText);
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
Process[] nmaps = Process.GetProcessesByName("nmap");
if (nmaps.Length > 0)
{
foreach (Process nmap in nmaps)
{
nmap.Kill();
}
}
}
private void resultsBox_LinkClicked(object sender, LinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(e.LinkText);
}
private void presetComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
generateArguments();
inputBox.Text = arguments;
}
private void presetRangeBox_TextChanged(object sender, EventArgs e)
{
generateArguments();
inputBox.Text = arguments;
}
private void customArgTextBox_TextChanged(object sender, EventArgs e)
{
generateArguments();
inputBox.Text = arguments;
}
private void reportTimer_Tick(object sender, EventArgs e)
{
System.IO.StreamWriter report = new System.IO.StreamWriter(reportsDir + "/nmap.txt");
report.Write(outputBox.Text);
report.Close();
report = new System.IO.StreamWriter(reportsDir + "/Verda.txt");
report.Write("Verda version " + verdaVersion + verdaVersionAdditional + System.Environment.NewLine + resultsBox.Text);
report.Close();
}
private void nmapPath_Click(object sender, EventArgs e)
{
NmapLocationDialog.ShowDialog();
}
private void NmapLocationDialog_FileOk(object sender, CancelEventArgs e)
{
NmapLocation = NmapLocationDialog.FileName;
labelAboutNmap.Text = "Path to nmap.exe manually set as " + NmapLocation;
System.IO.StreamWriter reswrite = new System.IO.StreamWriter("restore");
reswrite.WriteLine(presetComboBox.SelectedValue);
reswrite.WriteLine(presetRangeBox.Text);
reswrite.WriteLine(NmapLocation);
reswrite.Close();
}
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{
Application.Exit();
}
private void camBruteTimer_Tick(object sender, EventArgs e)
{
camTargetsLabel.Text = Program.CamTargets.ToString();
if (waitForBrute == true && Program.CamTargets <= 0)
OnScanEnd();
}
}
}