0xFFFFFFFE

190121 APT(중국-연구자료.scr.hwp) Decoding Script(python)

Jan 21st, 2019
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. # [Sample Information]
  2. # source : blog.alyac.co.kr/2086?category=957259 (일요일 수행된 APT 변종 공격, 오퍼레이션 페이크 캡슐(Operation Fake Capsule) 주의
  3. # hash(md5) : d64e4acd81152d90f0ac28db49ab290a
  4. # 리소스 영역 내부에 존재하는 DLL 파일에서 사용하는 인코딩을 IDAPython을 이용해 풀어보기
  5.  
  6. import idautils
  7. import idaapi
  8. import idc
  9.  
  10. encoded_func = 0x10001010
  11.  
  12. def decode(str_):
  13.     en_array = map(ord, str_)
  14.     result = len(str_)
  15.     count = 0
  16.     if result > 0:
  17.         if result > 0x40:
  18.             pass
  19.         else:
  20.             if count < result:
  21.                 while(result > 0):
  22.                     en_array[count] -= 3
  23.                     result-=1
  24.                     count+=1
  25.     return "".join(map(chr, en_array))
  26.  
  27. def get_string(addr):
  28.     out = ""
  29.     while True:
  30.         if Byte(addr) != 0:
  31.             out += chr(Byte(addr))
  32.         else:
  33.             break
  34.         addr += 1
  35.     return out
  36.  
  37. def find_function_arg(addr):
  38.     while True:
  39.         addr = idc.PrevHead(addr)
  40.  
  41.         if GetMnem(addr) == "mov" and "ecx" in GetOpnd(addr, 0):
  42.             return GetOperandValue(addr, 1)
  43.     return False
  44.  
  45. for addr in XrefsTo(encoded_func, flags=0):
  46.     ret_ffa = find_function_arg(addr.frm)
  47.     if ret_ffa != False:
  48.         string = get_string(ret_ffa)        
  49.         print "Ref Addr: 0x%x | Decoded: %s" % (addr.frm, decode(string))
Advertisement
Add Comment
Please, Sign In to add comment