CODEGATE2012 Binary200 Writeup
å
æ¥ã®CODEGATE2012 äºé¸ã
ä¸å¿ãå°ãã§ãåãããã£ãåé¡ã«ã¤ãã¦ã¯ããããããªäººã®æ¸ãããWriteupãåèã«
ãèªåã§çç±ãã¤ããªããçããå°åºã§ãããã¬ãã«ã¾ã§è½ã¨ãããã§ããã®ã§ããã
Binary200ã§ããªãã¤ã¾ãããã®ã§ãã¡ã¢ãã¦ãWriteupã
使ç¨ãããã¼ã«
- OllyDbg 1.10
- OllyDbg 2.01
- IDA 5.0
- PEiD 0.95
- ImpREC 1.7c
åé¡
Find a printable string that the program would print ultimately.
Download
ãã¡ã¤ã«ã®è§£æ
ã¾ãããã¡ã¤ã«ã®ç¨®é¡ã調ã¹ãã
[dolphin@siro BINARY200]$ file A1A81BBD9D2FD44FAE8013E753830464
A1A81BBD9D2FD44FAE8013E753830464: PE32 executable for MS Windows (DLL) (GUI) Intel 80386 32-bit
Windowsã®DLLã ã¨åããã®ã§ãã¨ããããOllyDbg 1.10ã§éããããã¨ããããªã¡ãã»ã¼ã¸ãã
å§ç¸®ããã¦ãããããã確ãã«ãPackç³»ã®ç®å°ã¨ããããPUSHADãè¦åããããã
1001112B . 60 PUSHAD
ããã«ã¼ã調ã¹ããããPEiDã使ãã
PEtiteã§ããã¯ããã¦ãããã¨ãåããã
é©å½ãªã¢ã³ããã«ã¼ã試ãã¦ã¿ããããã¾ãã¢ã³ããã¯ã§ããªãã®ã§ãæåã¢ã³ããã¯(manual unpacking)ãè¡ãã
æåã¢ã³ããã¯
æåã¢ã³ããã¯ã®æé ã¯ã以ä¸ã®éãã§ãããIATã«ã¯ãå¤é¨DLLé¢æ°ã®ã¤ã³ãã¼ãæ å ±ãæ ¼ç´ããã¦ããã
- å®è¡ããã
- ã¢ã³ããã¯ãããå®è¡ã³ã¼ããã¡ã¢ãªä¸ã«ãã¼ãããã
- ã¡ã¢ãªä¸ã«ãã¼ããããå®è¡ã³ã¼ãããã³ããã
- ãã³ããããã¡ã¤ã«ã®IAT(Import Address Table)ãä¿®æ£ãã
[å®è¡ããã]
å®è¡ãããã«ã¯ãEXEã§ããã°ãã®ã¾ã¾å®è¡ãããã°ãããã
ä»åã¯DLLãªã®ã§ãOllyDbg 1.10ãç¨ãã¦ããããã¬ä¸ã§å®è¡ãããã
åç´ã«ãOllyDbg 1.10ã§éãã¦ãF9(Run)ãæ¼ãã ãã§ããã
ãã®éã以ä¸ã®ãããªã¡ãã»ã¼ã¸ã表示ãããããOKãã¿ã³ãæ¼ãã¦éããShift+F9ãªã©ã§ä¾å¤ãæããã°ããã
[ã¢ã³ããã¯ãããå®è¡ã³ã¼ããã¡ã¢ãªä¸ã«ãã¼ãããã]
ããã¨ãOEP(Original Entry Point: ããã°ã©ã ã®éå§å°ç¹)ã¸ã¨JMPããå½ä»¤ã§ãç¾ããã
ãã®å ´åã10002598ãOEPã¨ãªãããã®OEPããªãã¨ãIATãä¿®æ£ã§ããªãã®ã§ãã¡ã¢ãã¦ããã
1001110F > $- E9 8414FFFF JMP binary20.10002598
[ã¡ã¢ãªä¸ã«ãã¼ããããå®è¡ã³ã¼ãããã³ããã]
OEPã¸JMPã(F8ãªã©ã§1å½ä»¤å®è¡ãããã°ãã)ãOllyDbgã®ãã©ã°ã¤ã³ã§ããOllyDumpãç¨ãã¦ãã³ãããã
ãã®ã¨ããOEPã«ã¸ã£ã³ããã¦ããå½ä»¤ã表示ãããªãå ´åãããããCtrl+Aãæ¼ãã¦å解æããã°ããã
Dumpãã¿ã³ãæ¼ãã¦ãé©å½ã«bin200.dllã®ãããªååãã¤ãã¦ä¿åããã
[ãã³ããããã¡ã¤ã«ã®IATãä¿®æ£ãã]
ä»åº¦ã¯ImpRECã§IATãä¿®æ£ããã
- ãã³ããããã¡ã¤ã«ãOllyDbgã§éãã(ã¨ã©ã¼ãåºã¦ããã¨ããããOKãæ¼ãã°ããã)
- ImpRECãèµ·åããAttach to an Active Process ãã loaddll.exe ãé¸ã¶ã
- Pick DLL ãã¿ã³ãæ¼ãã¦ãåé¡ã®DLLãã¡ã¤ã«ãé¸æããã
- OEPã®å¤ããã¡ã¢ããå¤ã«æ¸ãå¤ããã(10002598ãªãã00002598ã¨å ¥åããã)
- AutoSearch ãã¿ã³ãæ¼ãã
- Get Imports ãã¿ã³ãæ¼ãã
- Fix Dump ãã¿ã³ãæ¼ãããã³ããããã¡ã¤ã«ãé¸æããã
- ãã³ããããã¡ã¤ã«åã«"_"ãã¤ããååã§ä¿åãããã
ãããªæãã«ãªã£ã¦ããã°æåã§ããã
以ä¸ã§æåã¢ã³ããã¯ã¯å®äºã¨ãªãã
å®è¡ã³ã¼ãã®è§£æ
ã¢ã³ããã¯ããDLLãã¡ã¤ã«ãOllyDbg 1.10ã§éããã¨ãã¦ããã¨ã©ã¼ãåºãã
ããã§ãIDA ã OllyDbg 2.01 ã使ã£ã¦éãã
Exportããã¦ããé¢æ°ãã"x" 㨠"_c@4"(IDAã§è¦ãã¨"c(x)")ã¨ãªã£ã¦ããã
ããã§ãåé¢æ°ãè¦ãã¨ã"SetServiceState" ã "RegisterServiceCtrlHandler" ãªã©ã®å¼ã³åºããè¦ã¤ããã
ãµã¼ãã¹ã¨ãã¦åä½ããã¨ãããã¨ãåããã
ç¹ã«ãIDAã§è¦ãã¨ããåãããã "x" ã«ã¯ fopen ãã fputs ãããè¦åããããæªãããã¨ãåããã
å®éãOllyDbgçã§DLLãå®è¡ãã¦ãããé©å½ãªã¨ãã㧠"x" ãå¼ã³åºãã¨ã
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\
ã«ãµã¼ãã¹ãç»é²ããã"x" ãå¼ã³åºããããã¨ãåããã
IDA㧠"x" ãè¦ãã¨ãfopen ãã fputs ãããããã®ã§ã
ãã®ä¸ãè¦ã¦ã¿ããããã¨ãããã¤ã CALL ãããã
ç¹ã«æªãã CALL ã 1BC0 ã§ãxorãshlãshrã大éã«ä½¿ã£ã¦ããã
ãããæå·åããããã¯å¾©å·åã®ã³ã¼ãã ã¨è¦ã¦ééããªãã ããã
ããä¸ã¤ãæ°ã«ãªããã®ã¨ãã¦ã次ã®ã³ã¼ããããã
localtimeã§åå¾ããå¤ã®8ãã¤ãç®ã¨ 6 ãæ¯è¼ãã¦ããã
localtimeã«ã¤ãã¦èª¿ã¹ãã°ããåãããã8ãã¤ãç®ã¯ãæéãã表ãã
ã¤ã¾ãã6æãã©ããããã§ãã¯ãã¦ããã³ã¼ãã§ããã
6æãªããvar_238ã«ã¯6ãå
¥ããã¨ããä»çµã¨ãªã£ã¦ããããã ã
ãã®é¢æ°ã¯ã6æã«å®è¡ãããå¿
è¦æ§ãé«ãã¨èããããã
ç´æ¥å®è¡ã«ããã¢ããã¼ã
ä¸åº¦ã¯æåãããã©ãå¾ããåç¾ãããã¨ããããã©ããã¾ããããªãã£ãã
ãªã®ã§ãããã§ã¯è¨äºã«ãã¦ãã¾ããã
ä¸ã®ã»ãã«æ¸ãã¦ãããåèãµã¤ãã®3ã¤ç®ãè¦ã¦ããã£ãã»ããæ©ãããªã®ã§ãå²æã
éç解æã«ããã¢ããã¼ã
æå·åã¢ã«ã´ãªãºã ã®ç¹å®
å
ã«ãµãããæªããCALLå
10001BC0 ãè¦ã¦ã¿ãã
ããã¨ãããã¾ãæªããå®æ°ãç¾ããã
ãã®å®æ°ã§ãããã¨ãTEA(Tiny Encryption Algorithm)ããããããã
ãã®å¾ã® shl ã shr ãadd ã sub ãªã©ãåèã«ããªãããTEAã®ã³ã¼ãã¨æ¯è¼ããã¨ã
ã©ããTEAã§ã¯ãªããã¨ããããã
TEAã®Wikipediaã«ã¯ãSee Alsoã¨ãã¦ãRC4ãXTEAçã並ãã§ããã
ããããã®ã³ã¼ããè¦ã¦ããã¨ãXTEAã®ã³ã¼ãã§ããã¨åããã
å¼æ°è§£æ
å°éã«10001BC0ã®å¼æ°ã解æãã¦ããã
x+21Eã§ã¯ã復å·åã¨ãã¦10001BC0ãå¼ã³åºãã¦ãããã¨ãåããã
éµã¯16ãã¤ã(128ããã)ãæå·åããããã¼ã¿ã¯8ãã¤ããªã®ã§ã
大ä½ãããªæãã
6æã«å®è¡ããå ´åãecxã¯6ãªã®ã§ã1000A158(hex)ã«48(decimal)ã足ãã¦ã
1000A188ã®Valueãæå·åããããã¼ã¿ã§ããã¨åããã
ããã¾ã§ããã°ãããä¸æ¯ã
éµè§£æ
éµã¯ã10001B40ãå¼ã³åºãã¦çæãã¦ããã
è¦ã¦ã¿ãã¨ãåç´ã«ãå¼æ°ã§æ¸¡ããã1000B440ããèªã¿è¾¼ãã§ããã ãã¨åããã
æ©éãã®éµã使ã£ã¦å¾©å·åãã¦ã¿ã¦ãããã®ã ãããã¾ããããªãã
IDAã ã¨è¦ªåã«è¡¨ç¤ºãã¦ãããã®ã§åãããããããã®å¤ã¯å®è¡æã«è¥å¹²æ¸ãæããã
é ã追ã£ã¦è¦ã¦ãããã
IDAã®å ´åãå®æ°ã®å³å´ã«ããã³ã¡ã³ãã«ã«ã¼ã½ã«ãå½ã¦ãã¨ã
ãã®å®æ°ã«å¥ã®å¤ã代å
¥ãããã¨ãã¦ããã³ã¼ãã表示ãããã
ããã«ã¯ãªãã¯ãããã¨ã§ããã®ã³ã¼ãã¾ã§é£ãã§ãããã®ã§ã確èªããã
ãã®ä¸ä¾ã以ä¸ã«ç¤ºãã
ããã¯ã1000B44Fã«0xDEãæ¸ãè¾¼ããã¨ãã¦ããå¦çã§ããã
åå²ããããCreateThreadã®æ»ãå¤ã0ã§ãªããã°ãæ¸ãè¾¼ãã
APIåã§ãããã°ããã«åããããæ»ãå¤ã0ã¨ããã®ã¯ãé¢æ°ã®å®è¡ã失æããã¨ãã§ããã
ãªã®ã§ãããã¯0xDEãæ¸ãè¾¼ã¾ããªããã°ãªããªãã
ãã®ãããªãã©ãããããã¤ãããã®ã§ãå
¨ã¦æ½°ãã¦ããã
復å·å
é©å½ã«ããã°ã©ã ãæ¸ãã¦ã復å·åããã
ãã ããã¨ã³ãã£ã¢ã³åé¡ã«æ³¨æããã
vã¯ãIDAä¸ã§ã¯4ãã¤ãã®æ´æ°ã¨ãã¦è¡¨ç¤ºããã¦ããã®ã§ãé転ããã
ã¾ããä¸è¨ã®ããã°ã©ã ã§è¡¨ç¤ºãããçµæããé転ããªããã°ãªããªãã
(XTEAã®ã³ã¼ãã¯ãWikipediaã®ã³ããã§ãããnum_roundsã¯ã10001CE9ããåããã)
[dolphin@siro bin200]$ cat mofu.c
#include
void decipher(unsigned int num_rounds, uint32_t v[2], uint32_t const key[4]) {
unsigned int i;
uint32_t v0=v[0], v1=v[1], delta=0x9E3779B9, sum=delta*0x20;
for (i=0; i < num_rounds; i++) {
v1 -= (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + key[(sum>>11) & 3]);
sum -= delta;
v0 -= (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + key[sum & 3]);
}
v[0]=v0; v[1]=v1;
}int main(int argc, char *argv[])
{
int i, j;
uint32_t v[2] = { 0x1EAEA1C7, 0xB3506D02 };
uint32_t key[4] = { 0x1Ea0f5c6, 0xd9ec02f6, 0x59187c2e, 0x6f855dde };
decipher( 0x20, v, key );
printf("%s\n", (char*)v );
printf("\n");
return 0;}
[dolphin@siro bin200]$ ./mofu
W%I&l)K=
ãã£ã¦çãã¯ã"&I%W=K)l"ã¨ãªãã
ææ³
ããã§200ãã・・・^^ï¼ï¼ï¼