Guest User

Zeus2 String Decryption IDC script

a guest
Jul 6th, 2010
5,519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.11 KB | None | 0 0
  1. // IDA IDC script to decrypt encrypted strings in the Zeus/Zbot 2 malware.
  2.  
  3. #include "idc.idc"
  4.  
  5. static main() {
  6.   auto table = LocByName("_encrypted_strings");
  7.   auto decrypta = LocByName("GetEncryptedStringA");
  8.   auto decryptw = LocByName("GetEncryptedStringW");
  9.  
  10.   Message("Decrypting string table\n");
  11.   fix_table(table);
  12.  
  13.   Message("Commenting calls to %s\n", NameEx(BADADDR, decrypta));
  14.   comment_calls(decrypta, table);
  15.  
  16.     Message("Commenting calls to %s\n", NameEx(BADADDR, decryptw));
  17.   comment_calls(decryptw, table);
  18. }
  19.  
  20. static fix_table(table) {
  21.   auto entry;
  22.   auto xorval, length, data;
  23.   auto index, i, s;
  24.  
  25.   entry = table;
  26.  
  27.   while(1) {
  28.     MakeWord(entry);
  29.     xorval = Word(entry);
  30.    
  31.     MakeWord(entry + 2);
  32.     length = Word(entry + 2);
  33.  
  34.     if(length == 0) return;
  35.  
  36.     data = Dword(entry + 4);
  37.  
  38.     s = strfill(0, length+1);
  39.     for(i=0; i<length; i++) {
  40.       s[i] =  (Byte(data + i) - length) ^ xorval;
  41.     }
  42.  
  43.     // fix up disassembly
  44.     MakeNameEx(data, sprintf("EncString_%.2X", index), SN_CHECK);
  45.     MakeComm(entry + 4, s);
  46.    
  47.     // do next entry
  48.     entry = entry + 8;
  49.     index = index + 1;
  50.   }
  51. }
  52.  
  53. static comment_calls(func, table) {
  54.   auto x, t;
  55.   auto prev;
  56.   auto op;
  57.   auto comm;
  58.  
  59.   // find all references to specified function
  60.   for(x=RfirstB(func); x != BADADDR; x = RnextB(func, x)) {
  61.     // check xref type to make sure it's a call
  62.     t = XrefType();
  63.     if(t == fl_CF || t == fl_CN) {
  64.       // check if previous instruction is 'pop eax'
  65.       prev = PrevHead(x, MinEA());
  66.       if(GetMnem(prev) == "pop" && GetOpnd(prev, 0) == "eax") {
  67.         // now look for the push
  68.         for(; prev != BADADDR; prev = PrevHead(prev, MinEA())) {
  69.           if(GetMnem(prev) == "push") {
  70.             // if we found a push, add a comment for the string
  71.             op = GetOperandValue(prev, 0);
  72.             comm = CommentEx(table + (op * 8) + 4, 0);
  73.            
  74.             // add comment to call
  75.             MakeComm(x, comm);
  76.             break;
  77.           }
  78.         }
  79.       }
  80.     }
  81.   }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment