English 中文(简体)
Patching an EXE using IDA
原标题:

Say there is a buggy program that contains a sprintf() and i want to change it to a snprintf so it doesn t have a buffer overflow.. how do I do that in IDA??

问题回答

You really don t want to make that kind of change using information from IDA pro.

Although IDA s disassembly is relatively high quality, it s not high quality enough to support executable rewriting. Converting a call to sprintf to a call to snprintf requires pushing a new argument on to the stack. That requires the introduction of a new instruction, which impacts the EA of everything that follows it in the executable image. Updating those effective addresses requires extremely high quality disassembly. In particular, you need to be able to:

  1. Identify which addresses in the executable are data, and which ones are code
  2. Identify which instruction operands are symbolic (address references) and which instruction operands are numeric.

Ida can t (reliably) give you that information. Also, if the executable is statically linked against the crt, it may not contain snpritnf, which would make performing the rewriting by hand VERY difficult.

There are a few potential workarounds. If there is sufficient padding available in (or after) the function making the call, you might be able to get away with only rewriting a single function. Alternatively, if you have access to object files, and those object files were compiled with the /GY switch (assuming you are using Visual Studio) then you may be able to edit the object file. However, editing the object file may still require substantial fix ups.

Presumably, however, if you have access to the object files you probably also have access to the source. Changing the source is probably your best bet.





相关问题
Using snprintf to avoid buffer overruns

I am using snprintf like this to avoid a buffer overrun: char err_msg[32] = {0}; snprintf(err_msg, sizeof(err_msg) - 1, "[ ST_ENGINE_FAILED ]"); I added the -1 to reserve space for the null ...

String formatting expressions (Python)

String formatting expressions: This is %d %s example! % (1, nice ) String formatting method calls: This is {0} {1} example! .format(1, nice ) I personally prefer the method calls (second ...

Creating a FILE * stream that results in a string

I m looking for a way to pass in a FILE * to some function so that the function can write to it with fprintf. This is easy if I want the output to turn up in an actual file on disk, say. But what I ...

热门标签