Skip to content

Commit

Permalink
6.2.0 adds click random link in email, and deny list
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-dupdyke committed Sep 9, 2022
1 parent ffcdd80 commit 7e32765
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 38 deletions.
3 changes: 3 additions & 0 deletions src/Ghosts.Client/Ghosts.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
<Reference Include="FileHelpers, Version=3.4.1.0, Culture=neutral, PublicKeyToken=3e0c08d59cc3d657, processorArchitecture=MSIL">
<HintPath>..\packages\FileHelpers.3.4.1\lib\net45\FileHelpers.dll</HintPath>
</Reference>
<Reference Include="HtmlAgilityPack, Version=1.11.45.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a, processorArchitecture=MSIL">
<HintPath>..\packages\HtmlAgilityPack.1.11.45\lib\Net45\HtmlAgilityPack.dll</HintPath>
</Reference>
<Reference Include="Interop.ProfMan">
<HintPath>lib\Interop.ProfMan.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
Expand Down
45 changes: 45 additions & 0 deletions src/Ghosts.Client/Handlers/Outlook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using System.Linq;
using System.Reflection;
using System.Threading;
using Ghosts.Domain.Code.Helpers;
using NetOffice.ExcelApi.Enums;
using Exception = System.Exception;
using MAPIFolder = Microsoft.Office.Interop.Outlook.MAPIFolder;

Expand Down Expand Up @@ -132,6 +134,19 @@ public void ExecuteEvents(TimelineHandler handler)
Log.Error(e);
}
break;
case "CLICKRANDOMLINK":
try
{
if (ClickRandomLink(timelineEvent))
{
Report(handler.HandlerType.ToString(), timelineEvent.Command, string.Join(",", timelineEvent.CommandArgs));
}
}
catch (Exception e)
{
Log.Error(e);
}
break;
}

if (timelineEvent.DelayAfter > 0)
Expand All @@ -147,6 +162,36 @@ public void ExecuteEvents(TimelineHandler handler)
}
}

private bool ClickRandomLink(TimelineEvent timelineEvent)
{
try
{
var folderItemsRaw = _folderInbox.Items;
var folderItems = new List<MailItem>();
foreach (MailItem folderItem in folderItemsRaw)
{
folderItems.Add(folderItem);
}

var filteredEmails = folderItems.Where(x => x.BodyFormat == OlBodyFormat.olFormatHTML && x.HTMLBody.Contains("<a href="));
var mailItem = filteredEmails.PickRandom();

//check deny list
var list = DenyListManager.ScrubList(mailItem.HTMLBody.GetHrefUrls());
if (list.Any())
{
list.PickRandom().OpenUrl();
}
}
catch (Exception e)
{
Log.Error(e);
return false;
}

return true;
}

private bool Navigate(IEnumerable<object> config)
{
var hasErrors = true;
Expand Down
6 changes: 3 additions & 3 deletions src/Ghosts.Client/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("6.1.0.0")]
[assembly: AssemblyInformationalVersion("6.1.0.0")]
[assembly: AssemblyFileVersion("6.1.30.0")]
[assembly: AssemblyVersion("6.2.0.0")]
[assembly: AssemblyInformationalVersion("6.2.0.0")]
[assembly: AssemblyFileVersion("6.2.0.0")]
72 changes: 42 additions & 30 deletions src/Ghosts.Client/Sample Timelines/Outlook.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,27 @@
"DelayAfter": 900000,
"DelayBefore": 0
},
{
"Command": "reply",
"CommandArgs": [
"CurrentUser",
"All - reply to all",
"All",
"All",
"Parent - format is 'RE: <original message/>'",
"Random+Parent - format is reply then original message",
"Parent - format of original message",
""
],
"DelayAfter": 900000,
"DelayBefore": 0
}
{
"Command": "reply",
"CommandArgs": [
"CurrentUser",
"All - reply to all",
"All",
"All",
"Parent - format is 'RE: <original message/>'",
"Random+Parent - format is reply then original message",
"Parent - format of original message",
""
],
"DelayAfter": 900000,
"DelayBefore": 0
},
{
"Command": "clickrandomlink",
"CommandArgs": [],
"DelayAfter": 900000,
"DelayBefore": 0
}
]
},
{
Expand All @@ -61,21 +67,27 @@
"DelayAfter": 900000,
"DelayBefore": 0
},
{
"Command": "reply",
"CommandArgs": [
"CurrentUser",
"All",
"All",
"All",
"Parent",
"Parent+Random",
"Parent",
""
],
"DelayAfter": 900000,
"DelayBefore": 0
}
{
"Command": "reply",
"CommandArgs": [
"CurrentUser",
"All",
"All",
"All",
"Parent",
"Parent+Random",
"Parent",
""
],
"DelayAfter": 900000,
"DelayBefore": 0
},
{
"Command": "clickrandomlink",
"CommandArgs": [],
"DelayAfter": 900000,
"DelayBefore": 0
}
]
}
]
Expand Down
1 change: 1 addition & 0 deletions src/Ghosts.Client/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<package id="DotNetCore.NPOI.OpenXml4Net" version="1.2.2" targetFramework="net461" />
<package id="DotNetCore.NPOI.OpenXmlFormats" version="1.2.2" targetFramework="net461" />
<package id="FileHelpers" version="3.4.1" targetFramework="net461" />
<package id="HtmlAgilityPack" version="1.11.45" targetFramework="net461" />
<package id="Microsoft.AspNetCore.Authentication.Abstractions" version="2.2.0" targetFramework="net461" />
<package id="Microsoft.AspNetCore.Authentication.Core" version="2.2.0" targetFramework="net461" />
<package id="Microsoft.AspNetCore.Authorization" version="3.1.3" targetFramework="net461" />
Expand Down
2 changes: 2 additions & 0 deletions src/Ghosts.Domain/Code/ApplicationDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public static class ConfigurationFiles
public static string Health => Clean(Path + "health.json");
public static string Timeline => Clean(Path + "timeline.json");

public static string DenyList => Clean(Path + "denylist.txt");

public static string EmailContent(string raw) => Determine(raw, "email-content.csv");
public static string EmailReply(string raw) => Determine(raw, "email-reply.csv");
public static string EmailDomain(string raw) => Determine(raw, "emails-domain.json");
Expand Down
49 changes: 49 additions & 0 deletions src/Ghosts.Domain/Code/DenyListManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2017 Carnegie Mellon University. All Rights Reserved. See LICENSE.md file for terms.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Ghosts.Domain.Code.Helpers;
using NLog;

namespace Ghosts.Domain.Code
{
public static class DenyListManager
{
private static readonly Logger _log = LogManager.GetCurrentClassLogger();

public static IEnumerable<string> Load()
{
try
{
return File.ReadAllLines(ApplicationDetails.ConfigurationFiles.DenyList);
}
catch (Exception e)
{
_log.Trace(e);
return new List<string>();
}
}

public static bool IsInList(string item)
{
var list = Load();
return list.Any(x => x.StartsWith(item.GetUriHost(), StringComparison.InvariantCultureIgnoreCase));
}

public static IEnumerable<string> ScrubList(IEnumerable<string> list)
{
var denyList = Load();
var filteredList = new List<string>();
foreach (var item in list)
{
if (!denyList.Any(x => x.StartsWith(item.GetUriHost(), StringComparison.InvariantCultureIgnoreCase)))
{
filteredList.Add(item);
}
}
return filteredList;
}
}
}
43 changes: 43 additions & 0 deletions src/Ghosts.Domain/Code/Helpers/UriExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright 2017 Carnegie Mellon University. All Rights Reserved. See LICENSE.md file for terms.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using HtmlAgilityPack;

namespace Ghosts.Domain.Code.Helpers
{
Expand All @@ -11,5 +15,44 @@ public static string GetDomain(this Uri uri)
var a = uri.Host.Split('.');
return a.GetUpperBound(0) < 2 ? uri.Host : $"{a[a.GetUpperBound(0) - 1]}.{a[a.GetUpperBound(0)]}";
}

public static string GetUriHost(this string uriString)
{
try
{
if (!uriString.Contains(Uri.SchemeDelimiter))
{
uriString = string.Concat(Uri.UriSchemeHttp, Uri.SchemeDelimiter, uriString);
}
return new Uri(uriString).Host;
}
catch (Exception e)
{
Console.WriteLine(e);
return uriString;
}
}

public static IEnumerable<string> GetHrefUrls(this string input)
{
var doc = new HtmlDocument();
doc.LoadHtml(input);

return doc.DocumentNode.SelectNodes("//a[@href]")//this xpath selects all anchor tags
.Select(p => p.Attributes["href"].Value);
}

//TODO:clean this up
public static void OpenUrl(this string url)
{
try
{
Process.Start(url);
}
catch
{
//ignore
}
}
}
}
3 changes: 3 additions & 0 deletions src/Ghosts.Domain/config/denylist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
herein_lies_the_format_of_the_deny_list.org
we_can_deny_entire_domains.com
or_some_subnet.of_some_domain.net
10 changes: 5 additions & 5 deletions src/Ghosts.Domain/ghosts.domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@

<ItemGroup>
<PackageReference Include="DotNetCore.NPOI" Version="1.2.3" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.45" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NLog" Version="5.0.1" />
<PackageReference Include="NLog" Version="5.0.4" />
<PackageReference Include="System.ComponentModel" Version="4.3.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
<Folder Include="config\" />
</ItemGroup>

<ItemGroup>
<None Update="config\denylist.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="config\user-agents\android.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down

0 comments on commit 7e32765

Please sign in to comment.