【发布时间】:2021-06-25 14:58:34
【问题描述】:
我已阅读此infect.c 源代码,该源代码演示了如何使用恶意入口点感染 ELF 文件。
它是这样进行的:
- 将可执行文件加载到内存中
- 找到合适的段来扩展有效载荷
- 更新有效载荷以跳转原始入口点位置
- 更新入口点跳转payload位置
- 使用恶意负载扩展分段
它是如何发现合适的 phdr 的:
static int findinfectionphdr(Elf64_Phdr const *phdr, int count)
{
Elf64_Off pos, endpos;
int i, j;
for (i = 0 ; i < count ; ++i) {
if (phdr[i].p_filesz > 0 && phdr[i].p_filesz == phdr[i].p_memsz
&& (phdr[i].p_flags & PF_X)) {
pos = phdr[i].p_offset + phdr[i].p_filesz;
endpos = pos + sizeof infection;
for (j = 0 ; j < count ; ++j) {
if (phdr[j].p_offset >= pos && phdr[j].p_offset < endpos
&& phdr[j].p_filesz > 0)
break;
}
if (j == count)
return i;
}
}
return -1;
}
第一个循环查找要感染的可执行段,第二个循环测试是否有任何其他段容易与受感染的段重叠。
如果所有片段都是连续的,则无法执行此感染。
所以这是我的问题:为什么编译器不在 ELF 文件中生成连续的段? 或者:是什么证明了他们之间的差距?
【问题讨论】: