pyrebox icon indicating copy to clipboard operation
pyrebox copied to clipboard

The data I recorded in the memory callback is abnormal

Open Waterman178 opened this issue 4 years ago • 11 comments

image image image image

As shown in the picture above,i modified your code. I inserted my read-write record function in the deliver_callback function of the callbacks.cpp file. I only record the read-write information in the range of 0xffea4cff and 0xffea4d25. When the instruction is fetched, it will also enter the read-write callback, and instructions such as call and ret that will modify the memory will not enter the callback function at all. I want to know how to filter out the "fetch memory" situation, in addition, I need to consider the call, ret modify the memory situation. guest os:win7x64 host os:debian 64bit in vmware

Waterman178 avatar Jun 28 '20 00:06 Waterman178

I tested the tracing of kernel instructions yesterday.It's completely abnormal.For example, the push instruction, it will not record.This problem has troubled me for five days, I don't know how to solve it, I hope someone can help

Waterman178 avatar Jul 01 '20 13:07 Waterman178

Hi,

I would need to see all your code, or at least, all the code needed to reproduce the problem.

Thanks,

xabiugarte avatar Jul 01 '20 13:07 xabiugarte

Ok, thanks, I will package the source code and send it to your mailbox later

Waterman178 avatar Jul 01 '20 13:07 Waterman178

I patiently debugged for another day, and finally found the cause of the problem, I will look at it again, maybe I can solve this problem.

Waterman178 avatar Jul 02 '20 13:07 Waterman178

The problem is basically solved, but when the CPU fetch the code will also enter the read and write callback, tested it with your test script, the same result.As picture above, it will read 0x470 from 0xffea4cff in advance.How should it be filtered out?

Waterman178 avatar Jul 05 '20 05:07 Waterman178

Hi,

I would need to see all your code, or at least, all the code needed to reproduce the problem.

Thanks,

I have packaged it to your mailbox, please check

Waterman178 avatar Jul 08 '20 09:07 Waterman178

Hi, I have received the code. I will take a look at it as soon as I find some time.

Thanks,

xabiugarte avatar Jul 09 '20 11:07 xabiugarte

Hi,

I have finally allocated some time to take a look at your code. It seems that you are most likely having issues with how you track processes and threads. In any case, that's is definitely not the way you are supposed to install callbacks, and if you modify the internals of pyrebox in that way I cannot guarantee that it will work properly.

You should be able to track memory read/writes without modifying internals, just by installing regular callbacks and using triggers (there are examples available). Triggers are executed in C/C++ before a python callback is called, so the performance impact should be lower as well.

For instance, you can use as an example the following trigger: https://github.com/Cisco-Talos/pyrebox/blob/master/triggers/trigger_bpw_memrange.cpp

That is configured in the following way:

https://github.com/Cisco-Talos/pyrebox/blob/b5965efff35dd3b72e4f2f7806930d2d868251b6/scripts/mem_write_test.py

You can create your own trigger in the same way, and filter out the memory reads to just those that happen in the context of a given process (pgd) and by instructions in a given range.

Also, for the next time, I would really appreciate if you could create a github repository and push your changes there instead of sending them packaged in a rar file. That would help me to see your changes over the code.

xabiugarte avatar Jul 28 '20 17:07 xabiugarte

Hi,

I have finally allocated some time to take a look at your code. It seems that you are most likely having issues with how you track processes and threads. In any case, that's is definitely not the way you are supposed to install callbacks, and if you modify the internals of pyrebox in that way I cannot guarantee that it will work properly.

You should be able to track memory read/writes without modifying internals, just by installing regular callbacks and using triggers (there are examples available). Triggers are executed in C/C++ before a python callback is called, so the performance impact should be lower as well.

For instance, you can use as an example the following trigger: https://github.com/Cisco-Talos/pyrebox/blob/master/triggers/trigger_bpw_memrange.cpp

That is configured in the following way:

https://github.com/Cisco-Talos/pyrebox/blob/b5965efff35dd3b72e4f2f7806930d2d868251b6/scripts/mem_write_test.py

You can create your own trigger in the same way, and filter out the memory reads to just those that happen in the context of a given process (pgd) and by instructions in a given range.

Also, for the next time, I would really appreciate if you could create a github repository and push your changes there instead of sending them packaged in a rar file. That would help me to see your changes over the code.

I tried to use triggers and scripts to monitor memory reads and writes, the same result, useless, you did not finish watching the video I sent you.It is a TLB problem. When the CPU reads a certain memory address, it will not enter the callback function next time, unless TLB is completely disabled, but it will be many times slower than it is now.

Waterman178 avatar Jul 30 '20 06:07 Waterman178

Hi,

I watched the entire video, but I don't recall any comment regarding the TLB problem you mention. If the TLB is affecting how memory reads/writes are tracked, let's create an issue for that and I'll try to fix it.

For the next issues, I would appreciate if you use a different format for reporting problems. As I mentioned in my previous message, it would be great if you could create a repository where I can see the code and modifications necessary to reproduce the issue. That would really help me debug and understand the issue.

Thanks,

Xabier

xabiugarte avatar Jul 30 '20 07:07 xabiugarte

I watched the entire video, but I don't recall any comment regarding the TLB problem you mention. If the TLB is affecting how memory reads/writes are tracked, let's create an issue for that and I'll try to fix it.

For the next issues, I would appreciate if you use a different format for reporting problems. As I mentioned in my previous message, it would be great if you could create a repository where I can see the code and modifications necessary to reproduce the issue. That would really help me debug and understand the issue.

Thanks,

This problem does not need to submit code. You only need to use your script or trigger to monitor the read and write information of a call in any process.You will find that some addresses do not exist in the log. But the instructions at those addresses did access memory. I mentioned it in the video。

Waterman178 avatar Jul 31 '20 14:07 Waterman178