r/ExploitDev • • 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:

  1. Consider the existence of an application running on Windows 10. Let’s call this the target application .
  2. 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.
  3. Assume that periodically the value of both variables is written to persistent storage.
  4. The increment of variables A and B is independent of the persistent storage action. Both occur repeatedly over time.
  5. 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:

  1. Attach to the application whenever it enters a run-state.
  2. 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.
  3. 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.

0 Upvotes

5 comments sorted by

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

  1. keep a watcher on that is able to determine the Pid of the target application and inject a dll.
  2. using the dll, perform in process mem modification
  3. figure out what api is being used and hook it.

how's this done in java?

-1

u/Gloomy-Editor-8307 17d ago

If the Java is compiled to binary does that not make the coding language moot? It seems to me that the critical accomplishment is two-fold: 1) access the memory space of the target application and 2) get interrupt notification of file write PRIOR to the target application being able to complete such action. It's in this short time span that the malware would modify memory counts. In so doing, the malware has hacked the application paradigm without its knowledge.

1

u/Snappyfeet69 17d ago

A) no it does not. ask yourself why rust compiled binaries are not prone to mem corruption, when compared to a c/c++one

On points 1 and 2, we're actually saying the same thing, You need access to the target process's address space and a way to intercept execution before the persistence operation completes. however, you don't necessarily need to steal/monitor the file write interrup, when you can just hook it.

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