ç¹°ãè¿ããŸãããã»ãã¥ãªãã£ã·ã¹ãã ãé«åºŠã«ãªããå¿ èŠãªæåèšå®ãå¢ããã»ã©ãã³ãŒãèªäœã®å€èŠ³ãããããçš®é¡ã®ãã§ãã¯ããšã³ã³ãŒãããã§ãã¯ãµã ã«åœ±é¿ãäžããŸãããããã®æ¹æ³ã¯ãé©åãªæ¹æ³ã§ããŸããŸãªå Žæã«è©°ã蟌ãå¿ èŠããããŸãã¯ã©ãã«ãŒãèŠã€ãã«ããããã³ãŒãã ã³ãŒãã¯èªããªãããã«èŠããå€æŽããã®ãé£ãããªãããã¹ãŠã«æéãããããŸãã
ãããã£ãŠãåé¡ã¯ãä¿è·ã®ã¬ãã«/è²»ãããæé/ã³ãŒãã®å¯èªæ§/ã³ã¹ããªã©ã®éã§åŠ¥åç¹ãèŠã€ããããšã§ãã
ããã°ã©ã å ã®æååãé£èªåããããã®ç¬èªã®ãœãªã¥ãŒã·ã§ã³ãå ±æãããã®ã§ãããããã¯æå°éã®ä¿è·ããæäŸããŸãããã1ïŒç¡æ2ïŒç°¡å3ïŒã³ãŒãã®å€èŠ³ãã»ãšãã©æãªããªã4ïŒæ°ããèŠãŸããã§ããã
ããã«èšãããã®ã¯ããã®ãœãªã¥ãŒã·ã§ã³ã¯èªä¿¡ãæã£ãŠããã«ãŒã®çµéšãå°ãã ãé ãããã ãã§ãããããã¯éåžžã«ç°¡åã§ãåæã»ããã¢ããããçŽ15åããããããŸããã noo-hackersã«å¯Ÿããæå°éã®ä¿è·ãæäŸããã³ãŒãã£ã³ã°ã§ããå®å šãªã¿ã€ãã®æèãä¿ãããã®ã¡ãœãããèªåã§éçºããŠä»ã®ã¿ã€ãã®é²åŸ¡ãå®è£ ããæ©äŒãäžããããšãç®çãšããŠããŸãã
é£èªåæåå-ãªãå¿ èŠãªã®ã
éåžžãC / C ++ã§ããã°ã©ã ãã³ã³ãã€ã«ããå Žåãããã°ã©ã ã§äœ¿çšããããã¹ãŠã®è¡ã¯ã.exeãã¡ã€ã«å ã®ãã¬ãŒã³ããã¹ãã§ãã ããã¯æ¬¡ã®çç±ã§æªãã§ãã
- ããã°ã©ã ããã¹ã¯ãŒã/ããŒã䜿çšããŠããå Žåããããã¯ãã¡ã€ã«ãéããŠè¡šç€ºããã ãã®äººã«ããã«èŠããããã«ãªããŸãã
- ãããã³ã«/æ©èœ/ã¡ãã»ãŒãžããã³ä»ã®ã·ã¹ãã è¡ã®ååãèŠããšãæ»æè
ã¯ããã°ã©ã ã䜿çšããŠããæ©èœ/ã©ã€ãã©ãªãããã³äžè¬çã«ã©ã®ã¢ã«ãŽãªãºã ã«åºã¥ããŠãããã«ã€ããŠã®æ
å ±ãååŸã§ããããã«ããããã°ã©ã ã®åæãšãããã³ã°ã®äœæ¥ã倧å¹
ã«ç°¡çŽ åãããŸãã ç§ãæè¿åºäŒã£ãéåžžã«è¯ãäŸã®1ã€ã¯ããã®ããŒãžã®äžéšã«ããpokerbotoscar.wordpress.com/2009/03/20/how-casinos-detect-pokerbotsã§ããèè
ã¯ãããŒã«ãŒã¯ã©ã€ã¢ã³ããåã«1è¡ãã€äœæãããšããäºå®ã«ã€ããŠå€ãã®çµè«ãäžããããšã瀺ããŠããŸãã圌ã®ãã€ããªã«ãããŸãã
- ããã°ã©ã ã®ã€ã¡ãŒãžã«ç¹å®ã®è¡ãèŠã€ãã£ãå Žåãæ»æè
ã¯ãããã¬ãŒã«çŽæ¥ãã¬ãŒã¯ãã€ã³ããèšå®ããããšãã°ããã©ã€ã»ã³ã¹ã賌å
¥ããšããè¡ã衚瀺ãããŠããããã°ã©ã å
ã®å Žæãå³åº§ã«èŠã€ããããšãã§ããŸãã ãã®åŸãã©ã€ã»ã³ã¹ãã§ãã¯æ©èœïŒããšãã°ïŒãç°¡åã«æ€åºãããŸãããããã«ã¯æè¡çãªåé¡ããããŸãã ãã€ããªã«è¡ããªãå Žåãé¢æ°ã®æ€çŽ¢ã¯å°ãé
ããªããŸãã
Sysinternals Process Explorerããã°ã©ã ã䜿çšãããšããã¹ãŠã®æååãç°¡åã«è¡šç€ºã§ããŸããSysinternalsProcess Explorerããã°ã©ã ã§ã¯ãèªã¿èŸŒãŸããããã°ã©ã ã§3æåããé·ãæååããã¹ãŠããã«è¡šç€ºãããŸãã
å¿ èŠæ¡ä»¶
ç§ã®èŠä»¶ã¯éåžžã«åçŽã§ãã-é£èªåã¯èªåçã«è¡ãããã³ãŒããæå°éã«å€æŽããå¿ èŠããããè¡ã¯ãã€ããªã§ãã¡ã¢ãªå ã®ããã°ã©ã ã®ã€ã¡ãŒãžã§ãèªããªãã¯ãã§ãã
å€ãã®ãœãªã¥ãŒã·ã§ã³ã¯ãåã«ãã€ããªã®è¡ããšã³ã³ãŒãããèµ·åæã«ããã°ã©ã ã¯ãã¹ãŠã®è¡ãééããŠãã³ãŒãããŸãã ããã¯ãåãProcess Explorerã§ããã€ã¡ãŒãžãããã¡ã€ã«ãšåããããç°¡åã«è¡ãèªã¿åããããããéå¹æã§ãã ïŒããã¯ã¯ã©ãã«ãŒããŒã«ã§ãããããŸããããåã«taskmgrã®ä»£ããã«ãªããŸããïŒ
phpã§æååãçŽæ¥ãšã³ã³ãŒãããã¹ã¯ãªãããäœæãããããphpèªäœãšPATHã®php.exeãžã®ãã¹ã®äž¡æ¹ãå¿ èŠã§ãã
ããã§ã¯ãããžãã¹ã«åãæãããŸãããã
Visual Studio 2008ã䜿çšããŸããããä»ã®ããŒãžã§ã³ã®Visual Studioã§ãåãããã«æ©èœããŸãã VSã®å¥åŠãªç¹ãèãããšãä»ã®ã³ã³ãã€ã©ãŒã¯ããã«ç°¡åã«ãªããŸãã
ãŸããé£èªåããããŒobfuscator.h
é£èªåã䜿çšãããåãã¡ã€ã«ã«æ¥ç¶ããå¿ èŠããããŸãã
#ifndef _OBFUSCATOR_H #define _OBFUSCATOR_H #ifdef X #pragma message("MACRO X IS ALREADY DEFINED, EXPECT SERIOUS ERRORS") #endif #ifdef DO_OBFUSCATE_STRINGS __forceinline char *obDecodeStr(char *inst); #define X(s)obDecodeStr(OBPREPROCESSENCODEDSTR(s)) #else #define X(s)s #endif #endif
ã芧ã®ãšããããã¯ãXïŒïŒã䜿çšããŸãããã®å Žåãé£èªåãããåæååã¯ã©ãããããŸãã ååã¯1æåã®ã¿ã§æ§æããïŒä¿è·ãããã³ãŒããžã®åœ±é¿ãæå°éã«æããããïŒããããžã§ã¯ãå ïŒãŸãã¯å€éšã©ã€ãã©ãªïŒã§åããã¯ãã宣èšãããå¯èœæ§ãããããããã«ããã°ãŠã£ã³ããŠã«è¡šç€ºãããã¡ãã»ãŒãžãè¿œå ããŸããã
DO_OBFUSCATE_STRINGSãå®çŸ©ãããŠããå Žåãæååã¯XïŒsïŒobDecodeStrïŒOBPREPROCESSENCODEDSTRïŒsïŒïŒã«çœ®ãæããããŸã
ãOBPREPROCESSENCODEDSTRãã¯ãæååããšã³ã³ãŒãããã¹ã¯ãªãããæ€çŽ¢ããããŒã¯ã³ã§ãã ååã¯ããã®æåã®çµã¿åããããããžã§ã¯ãã®ä»ã®å Žæã§èŠã€ããããšãé€å€ããããã«ç¹å¥ã«é·ãäœãããŠããŸãã ãããã£ãŠãã¹ã¯ãªããèªäœïŒ
<?php date_default_timezone_set('UTC'); function parseArgs($argv){ array_shift($argv); $out = array(); foreach ($argv as $arg){ // --foo --bar=baz if (substr($arg,0,2) == '--'){ $eqPos = strpos($arg,'='); // --foo if ($eqPos === false){ $key = substr($arg,2); $value = isset($out[$key]) ? $out[$key] : true; $out[$key] = $value; } // --bar=baz else { $key = substr($arg,2,$eqPos-2); $value = substr($arg,$eqPos+1); $out[$key] = $value; } } // -k=value -abc else if (substr($arg,0,1) == '-'){ // -k=value if (substr($arg,2,1) == '='){ $key = substr($arg,1,1); $value = substr($arg,3); $out[$key] = $value; } // -abc else { $chars = str_split(substr($arg,1)); foreach ($chars as $char){ $key = $char; $value = isset($out[$key]) ? $out[$key] : true; $out[$key] = $value; } } } // plain-arg else { $value = $arg; $out[] = $value; } } return $out; } $args = parseArgs($argv); echo "Obfuscating strings in ".$args[1]."\r\n"; $f = fopen($args[0], 'rb'); $o = fopen($args[1], 'wb'); define('ENCODESTRTOKEN', 'OBPREPROCESSENCODEDSTR('); while ($line= fgets ($f)) { while (($esp = strpos($line, ENCODESTRTOKEN))!==false) { $sesp = $esp; $esp+=strlen(ENCODESTRTOKEN); while ($line[$esp]!='"') $esp++; $esp++; $sstart = $esp; $s = ''; while (true) { if ($line[$esp]=='"') break; if ($esp>=strlen($line)) break; if ($line[$esp]=='\\') { if ($line[$esp+1]=='\\') $s.='\\'; if ($line[$esp+1]=='r') $s.="\r"; if ($line[$esp+1]=='n') $s.="\n"; if ($line[$esp+1]=='t') $s.="\t"; $esp+=2; continue; } $s.=$line[$esp]; $esp++; } $enc = ""; $ch = 0; $chphase = 0; while ($ch<strlen($s)) { if ($chphase==0) $cod = ord($s[$ch]) & 15; else $cod = (ord($s[$ch]) & (255-15))/16; $cod = dechex(rand(1,15)*16 + $cod); $enc.="\\x$cod"; if ($chphase==0) $chphase = 1; else { $ch++; $chphase = 0;}; } echo "Obfuscating string \"$s\" to \"$enc\"\r\n"; $line = substr_replace($line, $enc, $sstart, $esp-$sstart); $line = substr_replace($line, "", $sesp, strlen(ENCODESTRTOKEN)-1); }; fputs($o, $line); }; ?>
ã芧ã®ãšãããã¹ã¯ãªããã¯ã³ãã³ãã©ã€ã³ãããã¡ã€ã«åãèªã¿åããããŒã¯ã³ãOBPREPROCESSENCODEDSTRããæ¢ããŸãã ãã®ãããªããŒã¯ã³ãèŠã€ãããšãæååã¯ããšã³ã³ãŒãããããŸãã
ãšã³ã³ãŒãã¢ã«ãŽãªãºã ã¯ç¢ºãã«æãå®å®ããŠããããã§ã¯ãããŸããããããã«ããä¿è·ã匷åããããšæãããå Žåã¯ãèªåã§ç°¡åã«å€æŽã§ããŸãã ããã§ã¯ãåã«å®äŸãšããŠç€ºããŸãã
ãã®ãã¡ã€ã«ããããžã§ã¯ãã®ã«ãŒããã£ã¬ã¯ããªã«çœ®ããobfuscate-i.phpãšããååãä»ããŸã
ãããŠæåŸã«ããã³ãŒãæ©èœãå«ããã¡ã€ã«
#include "obfuscator.h" typedef char odecoded[4095]; odecoded obbuf[4]; unsigned short lastbuf = 0; __forceinline char *obDecodeStr(char *inst) { lastbuf++; if (lastbuf>3) lastbuf = 0; unsigned int i = 0; unsigned int db = 0; bool phase = true; unsigned short schar = 0; while (inst[i]!=(char)0) { if (phase) { schar = 0; schar+=(((unsigned short)inst[i]) & 0x0F); } else { schar+=(((unsigned short)inst[i]) & 0x0F) * 16; obbuf[lastbuf][db] = (char)schar; db++; } phase = !phase; i++; } obbuf[lastbuf][db] = (char)0; return obbuf[lastbuf]; }
ãã®é¢æ°ã§èå³æ·±ãã®ã¯ãæååã眮ãããŠããå Žæã§æååããã³ãŒãããã®ã§ã¯ãªããã¢ãã¬ã¹ãæ¢ã«è¿ãããŠããç¹å¥ãªãããã¡ã«ãã³ãŒãããããšã§ãã ããã«ãããããã°ã©ã ã®ã€ã¡ãŒãžã§ã¯ããã¹ãŠã®è¡ããã³ãŒããããç¶æ ã«ãªãããšã¯ãããŸããã æåŸã«ãã³ãŒãããããã®ã®ãã¡ã4ã€ã®ã¿ããã³ãŒããããŸãã
__forceinlineã¯ãobDecodeStré¢æ°èªäœã«ãã¬ãŒã¯ãã€ã³ããèšå®ãããã¹ãŠã®è¡ãéæ³ã®ããã«ååŸããããšã«ãããæ»æè ãé²ãè©Šã¿ãšããŠäœ¿çšãããŸããã
ãããã¡ã1ã§ã¯ãªã4ãªã®ã¯ãªãã§ããïŒ
MessageBoxã®åŒã³åºããæ³åããŠãã ããïŒ0ãXïŒãããå€ãïŒãXïŒãããå¥ã®å€ãïŒãMB_OKïŒ
é£èªåã®ããã§ã¯ãªãå Žåãè¡ã®ã¢ãã¬ã¹ã ããMessageBoxé¢æ°ã«å ¥ãããã¹ãŠãæ£åžžã«ãªããŸãã ãã ããé£èªåãã¢ã¯ãã£ãã«ãªããšããã®åŒã³åºãã¯MessageBoxïŒ0ãobDecodeStrïŒããã®ä»ã®å€ãïŒãobDecodeStrïŒããã®ä»ã®å€ãïŒãMB_OKïŒã«å€ãããobDecodeStrã®äž¡æ¹ã®åŒã³åºãã*ã¡ãã»ãŒãžããã¯ã¹ãçŽæ¥å®è¡ãããåã«å®è¡ãããŸãã ãŸãããããã¡ã1ã€ã®ã¿äœ¿çšãããŠããå ŽåãobDecodeStrã®2åç®ã®ã³ãŒã«ã§ã¯ãå ã®æååãåçŽã«æžãæããããåãåŒæ°ãé¢æ°ã®äž¡æ¹ã®åŒæ°ã«ãªããŸãïŒMessageBoxïŒ0ãâ some another valueâãâ some another valueâãMB_OKïŒã
ãããã£ãŠã1ã§ã¯ãªã4ã€ã®ãããã¡ãŒãäžåºŠã«4ã€ä»¥äžã®é£èªåãããchar *ãã©ã¡ãŒã¿ãŒãåãé¢æ°ã䜿çšããå Žåã¯ããããã¡ãŒã®æ°ãå¢ããå¿ èŠããããŸãã
ãããžã§ã¯ãæ§æ
ã§ã¯ãããããã¹ãŠèªåçã«æ§æããæ¹æ³ã¯ïŒ
ïŒç§ã¯ãã¹ãŠã®ãªãã·ã§ã³ãè±èªã§æžããŠããŸãããã·ã¢ã®ã¹ã¿ãžãªãæã£ãŠããå Žåã§ããããªãã¯ãããç解ããã ãããšæããŸãïŒ
- ãŸãããããžã§ã¯ãã®ãªãªãŒã¹æ§æã2åã³ããŒããŸãã æåã®ã³ããŒã¯Release-obfuscated-prestepãšåŒã°ãã2çªç®ã¯Release-obfuscatedã§ãã ïŒVisualStudioã¯ååŠçããããã¡ã€ã«ãä¿åããããããå€éšããŒã«ã«æž¡ãã1ã¹ãããã§ã³ã³ãã€ã«ããæ¹æ³ãç¥ããªããããåã¹ããããå¿ èŠã§ãïŒã
- Release-obfuscated-prestepã®æ§æã§ãobfuscator.ppãé€ããã¹ãŠã®.cppãã¡ã€ã«ãéžæãã[ããããã£]ã«ç§»åããŸãã ããã§ãC ++ /ããªããã»ããµ/æºåããããã¡ã€ã«ã®çæã®äžã§ãè¡çªå·ãªã/ EP / PãéžæããŸãã
ããã«ãããã³ã³ãã€ã«ãã代ããã«ããã¹ãŠã®.cppãã¡ã€ã«ãããªããã»ããµã§åŠçããã圢åŒã§æ¡åŒµå.iã§ä¿åãããŸãã ã€ãŸããXïŒïŒãã¯ããå«ãããããã®ãã¹ãŠã®ãã¯ãã¯æ¢ã«ãããã€ãããŠããŸãã - ãã®æ§æãæ§ç¯ããŸãïŒRelease-obfuscated-prestepïŒã ãªã³ã«ã¯ãååãªãªããžã§ã¯ããã¡ã€ã«ããªãããã«ããå®äºããªãããšãèªããŸãããåé¡ã§ã¯ãããŸãããçæããã.iãã¡ã€ã«ã®ã¿ãå¿ èŠã§ãã
- ãããã®æ°ãã.iãã¡ã€ã«ããã¹ãŠèŠã€ããŠããããžã§ã¯ãã«è¿œå ããŸãã ã¹ã¿ãžãªããã®æ¡åŒµæ©èœã®æ°ããã«ãŒã«ãäœæãããã©ãããå°ããå ŽåãNOãšå®å šã«çããããšãã§ããŸãã
- ããããã¹ãŠã®ãã¡ã€ã«ãéžæããŠã[ããããã£]ã«ç§»åããŸãã ãªãªãŒã¹é£èªåãé€ããã¹ãŠã®æ§æã§ããããã®ãã¡ã€ã«ã«[ãã«ãããé€å€]â[ã¯ã]ãèšå®ããŸãã
- ãªãªãŒã¹é£èªåãããæ§æã§ããããã®ãã¡ã€ã«ã«ãã«ãããé€å€âNOãèšå®ããæåŸã«ãåããã¡ã€ã«ã«å¯ŸããŠãã«ã¹ã¿ã ãã«ãã¹ãããã®èšå®ã§ãã³ãã³ãã©ã€ã³ã«æ¬¡ãå
¥åããŸãã
php obfuscate-i.php $(InputPath) src-obfuscated\$(InputName).ob.cpp
ãããŠãåºåãã£ãŒã«ãã«å ¥åããŸã
src-obfuscated\$(InputName).ob.cpp
åŠçæžã¿ãã¡ã€ã«ãä¿åããsrc-obfuscatedãã£ã¬ã¯ããªãäœæããå¿ èŠãããå ŽåããããŸãã - ããããã¹ãŠã®.iãã¡ã€ã«ãéžæããå³ã¯ãªãã¯ããŠ[ã³ã³ãã€ã«]ãéžæããŸãã Visual Studioãã¹ã¯ãªãããåŒã³åºããšããã°ãŠã£ã³ããŠã«ããã»ã¹ã衚瀺ããã* .ob.cppãã¡ã€ã«ã衚瀺ãããã¯ãã§ãã
- ãããã®æ°ãããã¡ã€ã«ããããžã§ã¯ãã«è¿œå ãããªãªãŒã¹é£èªåãããæ§æã§ã¯ãã«ãããé€å€ãNOã«èšå®ããä»ã®ãã¹ãŠã®æ§æã§ã¯YESã«èšå®ããŸãã
- obfuscator.cppãé€ããã¹ãŠã®å ã®.cppãã¡ã€ã«ãéžæãããªãªãŒã¹é£èªåãããæ§æã»ããã§ãã«ãããé€å€ãYESã«ããŸã
- æåŸã«ãRelease-obfuscated-prestepããã³Release-obfuscatedã®æ§æã§ããããžã§ã¯ãèªäœã®ããããã£ã«ç§»åããC / C ++ / Preprocessor / Preperocessor Definitionsã§ã·ã³ãã«DO_OBFUSCATE_STRINGSãè¿œå ããŠãé£èªåãå®éã«æå¹ã«ããŸãã
ããã§ãåè¡ãXïŒïŒã§ã©ããããé£èªåããããŒãæ¥ç¶ããã ãã§ãè¡ãä¿è·ãããŸãã
éåžžã®éçºã§ã¯ãå€æŽãããªããŸãŸã®å€ããªãªãŒã¹/ãããã°æ§æã䜿çšããŸãããã€ããªããªãªãŒã¹ãããšãã¯ããŸããªãªãŒã¹é£èªååã¹ãããæ§æããã«ããïŒæåŸãŸã§ãã«ããããŸããïŒãæåŸã«ãªãªãŒã¹é£èªåãè¡ãããä¿è·ãããããã€ããªã