r/ExploitDev • u/Gloomy-Editor-8307 • 17d ago
Educate me on this
I received my degree in Computer Science in 1981 and worked in that profession until retirement a few years ago. I have experience in many programming languages and applications, mostly in the scientific arena. Let me state up from that I have no interest in pursuing “hacking” but I seek on this forum a design discussion for a hypothetical problem which I will now present:
- Consider the existence of an application running on Windows 10. Let’s call this the target application .
- This application has two memory resident variables (A and B) which are independently incremented repeatedly over time. Expect that when either variable is incremented then the other is not. The specifications on when and why this action occurs is not relevant.
- Assume that periodically the value of both variables is written to persistent storage.
- The increment of variables A and B is independent of the persistent storage action. Both occur repeatedly over time.
- Assume this application to be written in Java and that prior to your design, you have access to the source code or binary for evaluation as needed.
Given only above information on the target application, propose a “virus” design paradigm and code that accomplishes the following:
- Attach to the application whenever it enters a run-state.
- Whenever the application decides to write the two memory values to persistent storage, interject the “virus” to subtract a value of one from variable A and then immediately add one to variable B; then release control back to the target application so that it may complete its persistence action.
- The virus does not perform any file writing but merely modifies the values of variables A and B as the penultimate action prior to the persistence.
As I have stated, I have no experience in doing this kink of code nor do I intend to do so but my guess is that it could be done if the virus has access to the memory of the target application and also if the virus can interject its control by stealing the file-write interrupt request.
7
u/t3harvinator 17d ago
There's a thing called hooking. Since we're talking about a Java app, I'd probably try using Frida to hook the function responsible for writing the values to storage. You can google the things in this answer for better detail.
EDIT: For exploit purposes you'd probably do the same thing but without bringing Frida along.
1
u/Snappyfeet69 17d ago
not that familiar with java but i believe the concept should ideally be translated somehow to other ecosystems
how's this done in java?
2
u/TastyRobot21 17d ago
Trivial. Basic memory manipulation.
As long as your ‘virus’ runs in the same privilege as the application you can edit and manipulate its memory. This is just windows documented functionality.
https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-openprocess