-
Notifications
You must be signed in to change notification settings - Fork 16
/
SwordphishObject.cs
executable file
·96 lines (71 loc) · 3.57 KB
/
SwordphishObject.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
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Text;
using System;
using System.Security.Authentication;
namespace NotifySecurity
{
static class SwordphishObject
{
static string SwordphishURL = Properties.Settings.Default.SwordphishURL;
static string URLrequest = SwordphishURL + "/result/report/ID";
static string SworphishHeader = Properties.Settings.Default.SwordPhishHeader;
static string WebExpID = SworphishHeader + @": \[[0-9a-z-]+\]";
static string WebExpPrefix = SworphishHeader + @": [";
static string WebExpSuffix = @"]";
public static string NoHeaderFound = "no header found";
public static string AnswerFromSwordphish = "Answer from wordphish server: ";
public static string NoAnswerFromSwordphish = "NO ANSWER from Swordphish server";
public static string MsgIfSwordphishDetected= "\n\nWell done, you've well identified our fake mail generated for the phishing campain !";
public static string SetHeaderIDtoURL(string headers)
{
var pattern = WebExpID;
var regex = new Regex(pattern);
var match = regex.Match(headers);
foreach (var group in match.Groups)
{
if(group.ToString().Trim()!=string.Empty)
{
//we got the ID : fill in the URL
string sURL = URLrequest
.Replace(@"/ID", string.Concat(@"/" + group.ToString()))
.Replace(WebExpPrefix, string.Empty)
.Replace(WebExpSuffix, string.Empty);
return sURL;
}
}
return NoHeaderFound;
}
public const SslProtocols _strTls12 = (SslProtocols)0x00000C00;
public const SecurityProtocolType Tls12 = (SecurityProtocolType)_strTls12;
public static string SendNotification(string sURL)
{
ServicePointManager.SecurityProtocol = Tls12;
string strToWriteNOK = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString() + ":" + NoAnswerFromSwordphish + "\n(" + sURL + ")";
try
{
string html = string.Empty;
var request = (HttpWebRequest)WebRequest.Create(sURL);
var response = (HttpWebResponse)request.GetResponse();
html = new StreamReader(response.GetResponseStream()).ReadToEnd();
IWebProxy defaultProxy = WebRequest.DefaultWebProxy;
if (defaultProxy != null)
{
defaultProxy.Credentials = CredentialCache.DefaultCredentials; }
WebClient client = new WebClient();
client.Proxy = defaultProxy;
html = client.DownloadString(sURL);
string strAnswerFromSwordphish = html;
string strToWriteOK = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString() + ":" + AnswerFromSwordphish + strAnswerFromSwordphish;
return strAnswerFromSwordphish;
}
catch (System.Exception exc)
{
strToWriteNOK = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString() + ":" + "\n(" + sURL + ")\n" + exc.ToString();
}
return NoAnswerFromSwordphish;
}
}
}