You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/README.md
+58-19Lines changed: 58 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ to inform computer users, Software Engineers, Cybersecurity Analysts, and others
7
7
multiple vulnerabilities to create a sophisticated piece of malware, and my explanation on how to prevent these vulnerabilities._
8
8
9
9
## Summary
10
-
This project is a remote access Trojan-ransomware that uses both TCP and UDP sockets for communication.
10
+
This project is a remote access Trojan-Ransomware that uses both TCP and UDP sockets for communication.
11
11
The payload is inside of a DLL that impersonates Microsoft's
12
12
legitimate "mlang.dll" to bypass UAC and escalate privileges when paired with
13
13
a System32 mock directory alongside DLL hijacking.
@@ -35,25 +35,27 @@ alongside client and server RSA public keys.
35
35
36
36
This write-up explains my experience making this project.
37
37
38
-
During this project, I finally decided to document my experience. This includes the triumphs, roadblocks, ideas I thought of,
38
+
During this project, I decided to document my experience. This includes the triumphs, roadblocks, ideas I thought of,
39
39
and more that happened during the creation of this project.
40
40
41
41
## Backstory
42
-
Before I started this project, [I had previously made a chat room entirely implemented in C for Linux for my Computer Engineering Technology class final](https://github.com/provrb/AMS),
43
-
a basic reverse shell written in C++ for Windows, I also have been programming in C and C++ while also using the Windows API for over 2 years.
42
+
Before I started this project,
43
+
[I had previously made a chat room entirely implemented in C for Linux for my Computer Engineering Technology class final](https://github.com/provrb/AMS);
44
+
a basic reverse shell written in C++ for Windows.
45
+
I also have been programming in C and C++ while also using the Windows API for over 2 years.
44
46
45
-
As you can infer, I went into this project with a good understanding of POSIX threads and sockets and the WinSock API.
47
+
As you may infer, I went into this project with a good understanding of POSIX threads and sockets and the WinSock API.
46
48
However, the basic reverse shell I wrote in a month wouldn't even pass an anti-virus heuristic analysis. After researching
47
49
the behaviour of anti-viruses, I understood how viruses could evade anti-virus software. One of these was the use of function
48
50
pointers, and this is why they will be prevalent throughout the code instead of making direct WinSock API calls. Furthermore,
49
51
undocumented Windows API functions that invoke syscalls are also used to further evade detection.
50
52
51
-
With all this information, I wanted to construct a sophisticated piece of malware for educational purposes and, of course, for fun.
52
-
I thought simple ransomware would be pretty boring and easy to crack. I did like the idea of ransomware
53
-
but I also liked the idea of a RAT. So I compromised by creating a RAT which could also invoke a Ransomware attack, among other
54
-
functions for Windows.
53
+
With all this information, I wanted to construct a sophisticated piece of malware for educational purposes
54
+
unlike my previous projects.
55
+
I preferred the idea of ransomware but also the idea of a RAT.
56
+
So I compromised. A RAT to invoke a Ransomware attack with rootkit capabilities and privilege escalation.
55
57
56
-
### My first roadblock
58
+
### My First Roadblock
57
59
Still thinking about this idea of sophisticated ransomware, I realized I hadn't worked with much cryptography, [apart from 'web hacker',
58
60
another project on my GitHub where I decrypted Chrome and Firefox cookies](https://github.com/provrb/web-hacker), passwords, history, etc, using AES, Base64, and managing SQL
59
61
Databases. The idea of encrypting files with a key that couldn't be reverse-engineered stumped me until I researched further into cryptography about RSA encryption.
@@ -64,7 +66,7 @@ Symmetrical cryptography algorithms work to generate a key of a set size that ca
64
66
work to generate a pair of keys, one 'private' and one 'public' where the public key is used to encrypt data and the private key is used to decrypt encrypted data.
65
67
However, RSA encryption does have limitations when it comes to this scenario, and that is the size of the data to encrypt cannot be bigger
66
68
than the key size in bytes. For example, RSA 1024 bit keys can only encrypt 128 bytes of data at a time.
67
-
Since my Packets are 8kb in size, RSA won't work to encrypt them, so a much more complicated scheme is required.
69
+
Since my packets are 8kb in size, RSA won't work to encrypt them, so a much more complicated scheme is required.
68
70
69
71
An RSA key pair is generated when the server starts, these will be the encryption keys for the session. An AES key is
70
72
generated each time a client connects on the server. On the client, another RSA key pair is generated. Once connected,
@@ -82,16 +84,16 @@ While this discussion is purely hypothetical, the described mechanism demonstrat
82
84
Such encryption schemes are widely applicable for secure data protection but also highlight the potential misuse of cryptography, as seen in ransomware scenarios.
83
85
84
86
## File format
85
-
After brainstorming and thinking about all these methods, I proposed myself with the question; Which file format would I want to approach this project with?
86
-
A regular old EXE? An ISO file? Maybe even a .SYS file. As the days went on with this idea in my head, I started digging deeper into how DLLs work,
87
+
After brainstorming and thinking about all these methods, I proposed myself with the question: Which file format would I want to approach this project with?
88
+
A regular EXE? An ISO file? Maybe even a .SYS file. I started digging deeper into how DLLs work,
87
89
how to write one in C++, and how can they be used for malicious intent. That is when I discovered a vulnerability that involved DLLs and System32.
88
90
Both are fascinating subjects, which ultimately influenced my decision to include the payload in a DLL.
89
91
90
92
## DLL Hijacking
91
93
DLL hijacking is a vulnerability where an application loads a malicious DLL rather than the intended DLL and thus
92
94
can execute malicious code in the background while everything appears normal to the user.
93
95
94
-
Now why does this work is the question.
96
+
Now the question is why does this work?
95
97
96
98
When an application loads a DLL, Windows searches four different regions in this order to find a DLL matching the requested name:
Interestingly, Windows treats this fake System32 directory just like the real Windows folder!
122
124
Once you make that mock directory, look in your new Windows folder, it will also contain every single folder and file that's in the real Windows folder.
123
125
124
-
You can't even make a text document in that folder or delete it from File Explorer, you must use PowerShell again. To
126
+
You can't make a text document in that folder or delete it from File Explorer, you must use PowerShell again. To
125
127
get a better understanding, I recommend that you try it for yourself, it will help when trying to
126
128
wrap your head around this information.
127
129
@@ -156,8 +158,8 @@ left was to compare function names to the export I wanted. By iterating over the
156
158
I can check the array of all the export names to my desired function, once I found the function I wanted, I would just
157
159
return the absolute address of the function.
158
160
159
-
After a couple of these functions, it would be a breeze to load functions I need without polluting or even adding them
160
-
to my imports table, which is one way to attempt to evade AVs. Afterwards, I got started on trying to elevate my permissions even more.
161
+
After a couple of these functions, loading functions would be convenient as I wouldn't need to pollute my namespace or import table,
162
+
which is one way to attempt to evade AVs. Afterwards, I got started on trying to elevate my permissions even more.
161
163
162
164
## SYSTEM Permissions
163
165
In Windows, there is a built-in account known as SYSTEM or LocalSystem. This account is used by the operating system and
@@ -197,7 +199,7 @@ function to obtain a SYSTEM token. You may see where this is going.
197
199
198
200
Rather than being an actual running process like winlogon.exe, TrustedInstaller is embedded into Windows as a service and thus has to be started.
199
201
To start any Windows process, we first need to obtain a handle for the Windows service control manager, a special process responsible for starting and stopping.
200
-
Windows processes, so we can start and stop Windows processes! After, we need to obtain another handle for the service by opening it with the SC manager.
202
+
Windows processes, so we can start and stop Windows processes. After, we need to obtain another handle for the service by opening it with the SC manager.
201
203
Though, we do not know if this service is running, or pending start or a stop, so we must query the status of the service. Once the service is running, we can take the
202
204
process ID of that service, and run it through CreateProcessAccessToken to return a security token in the context of the provided process, in this case, the Trusted
203
205
Installer service.
@@ -207,5 +209,42 @@ with winlogon.exe. Using the handle of the security token, I can run and manipul
207
209
implemented in the Windows operating system. Meaning this has the potential to become a User-Mode root kit as we have persistence, privilege, and stealth.
208
210
209
211
## How could this malware be avoided; as you-the user?
210
-
212
+
Overall, there is no silver-bullet for ransomware, rootkits, or RATs. However, there are some steps you can take to prevent these types of malware from infecting your computer.
213
+
214
+
1. Update software regularly
215
+
- One of the main methods of remaining safe is to keep your computer up-to-date.
216
+
This includes updating your operating system, software, and drivers.
217
+
While this is not totally convienant, this can prevent against malware that take advantage of known vulnerabilities in these
218
+
pieces of software, which can be detrimental to your computer or a network.
219
+
2. Use a good antivirus program.
220
+
- Although the idea of whether or not an anti-virus program can be useful is a controversial topic
221
+
they can help protect your computer from known malware, especially as the average user.
222
+
223
+
3. Be careful browsing the internet
224
+
- Only download files from trusted sources and be wary of files from unknown sources.
225
+
Downloading unknown files is a leading cause to compromised networks and computers.
226
+
4. Be careful when clicking on links
227
+
- A popular method to compromise networks when a malware cannot directly be downloaded is through phishing and social engineering.
228
+
Social engineering is the act of manipulating people into performing actions or divulging confidential information.
229
+
This can be paired with phishing, where a user is tricked into clicking on a malicious link.
230
+
To prevent against this, make sure you know the sender of the email and the link you are clicking on and
231
+
100% sure of its legitimacy.
232
+
233
+
Although these steps can help prevent malware from infecting your computer, it is important to remember that no method is foolproof.
234
+
Sometimes theres nothing we can do, for example if a zero-day exploit is abused malware may be able to spread without any
235
+
user interaction. It is important you try your best to prevent malware from infecting your computer.
236
+
211
237
## Conclusion, what I learned
238
+
From this project, I learned a lot about the Windows operating system, the Windows API, and how to exploit vulnerabilities in the Windows operating system.
239
+
I learned how to use undocumented syscalls to elevate my permissions to SYSTEM and TrustedInstaller, and how to use DLL hijacking to bypass UAC.
240
+
I also learned how to use hybrid encryption to securely encrypt files and data, and improved my understanding on sockets.
241
+
242
+
Most importantly, through this project I was able to think like a threat actor. To know a threat-actor is to be a
243
+
good threat-hunter. I'm able to understand how to prevent exploitation of vulnerabilities.
244
+
From a more-cybersecurity oriented perspective, this would be a great experience
245
+
I can refer to when blue-teaming, rather than red-teaming.
246
+
247
+
This project was incredibly fun to create and I hope you enjoyed reading my first write-up.
248
+
I hope to make more projects similar to this as well as projects to go against threat-actors.
0 commit comments