-
Notifications
You must be signed in to change notification settings - Fork 0
/
Home.aspx.cs
168 lines (132 loc) · 5.51 KB
/
Home.aspx.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
using MalwareDoctor_Online_Scanner;
using System;
using System.Configuration;
using System.IO;
using System.Web.UI.WebControls;
public partial class Home : System.Web.UI.Page
{
string uploadPath = ConfigurationManager.AppSettings["UploadPath"];
protected void Page_Load(object sender, EventArgs e)
{
lblBrowse.Text = "Browse a file to scan it. We delete files after analysis.";
btnScan.Text = "Scan";
lblVT.Visible = false;
lblVX.Visible = false;
linkVXres.Visible = false;
lblResults.Visible = false;
btnDetails.Visible = false;
lbtnNewScan.Visible = false;
pageBody.Attributes.Add("bgcolor", "#C2C2C2");
}
public void UnhideControls()
{
lblVT.Visible = true;
lblVX.Visible = true;
linkVXres.Visible = true;
lblResults.Visible = true;
btnDetails.Visible = true;
lbtnNewScan.Visible = true;
btnScan.Visible = false;
lblBrowse.Visible = false;
FileUpload.Visible = false;
}
public void MakeTableHeaderVisible()
{
TableHeaderCell headerTableCellEngine = new TableHeaderCell();
TableHeaderCell headerTableCellVerdict = new TableHeaderCell();
TableHeaderCell headerTableCellDetection = new TableHeaderCell();
headerTableCellEngine.Text = "Engine";
headerTableCellVerdict.Text = "Verdict";
headerTableCellDetection.Text = "Detection";
TableHeaderRow headerRow = new TableHeaderRow();
headerRow.Cells.Add(headerTableCellEngine);
headerRow.Cells.Add(headerTableCellVerdict);
headerRow.Cells.Add(headerTableCellDetection);
TableVT.Rows.Add(headerRow);
}
protected void btnScan_Click(object sender, EventArgs e)
{
if (FileUpload.HasFile)
{
try
{
//string filename = Path.GetFileName(FileUpload.FileName);
string tempFilename = Path.GetFileName(FileUpload.FileName);
string filename = Path.GetRandomFileName();
FileUpload.SaveAs(Server.MapPath(uploadPath) + filename);
FileManager mgr = new FileManager(Server.MapPath(uploadPath) + filename);
//start vt
if (mgr.VT[0].Contains("Unknown"))
{
lblVT.Text += "Unknown. The file is most likely new, and currently being analyzed.";
}
else if (mgr.VT[0].Contains("Error"))
{
lblVT.Text += "Error. Most likely bad API key or public API key limitation.";
}
else
{
int engineCount = 0;
int detectionCount = 0;
MakeTableHeaderVisible();
foreach (string line in mgr.VT)
{
if (String.IsNullOrEmpty(line) == false)
{
engineCount = engineCount + 1;
}
if (line.Contains("True") == true)
{
detectionCount = detectionCount + 1;
}
string[] detectionInfo;
detectionInfo = line.Split(new char[] { '*' });
var cellEngine = new TableCell();
var cellVerdict = new TableCell();
var cellDetection = new TableCell();
var row = new TableRow();
cellEngine.Text = detectionInfo[0];
if (detectionInfo[1] == "True")
{
cellVerdict.Text = "Infected";
}
else if (detectionInfo[1] == "False")
{
cellVerdict.Text = "Clean";
}
cellDetection.Text = detectionInfo[2];
row.Cells.Add(cellEngine);
row.Cells.Add(cellVerdict);
row.Cells.Add(cellDetection);
TableVT.Rows.Add(row);
}
lblVT.Text = lblVT.Text + detectionCount.ToString() + "/" + engineCount.ToString();
}
//end vt
if (mgr.VXVaultDB.Contains("Not present"))
{
linkVXres.NavigateUrl = String.Empty;
linkVXres.Target = String.Empty;
linkVXres.Text = mgr.VXVaultDB;
}
else
{
linkVXres.NavigateUrl = mgr.VXVaultDB;
linkVXres.Target = "_blank";
linkVXres.Text = "Present in DB, click for details!";
}
lblResults.Text = "Results for " + tempFilename + " (MD5:" + mgr.MD5 + ")";
UnhideControls();
if (lblVT.Text.Contains("Unknown")|| lblVT.Text.Contains("Error"))
{
btnDetails.Visible = false;
}
File.Delete(Server.MapPath(uploadPath) + filename);
}
catch (Exception ex)
{
lblResults.Text = ex.Message;
}
}
}
}