Advertisement
saleks28

tsuib_1_pyth

Jan 30th, 2021
1,114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.11 KB | None | 0 0
  1. from idautils import *
  2. from idc import *
  3. from ida_ida import *
  4.  
  5. def find_xor():
  6.     xor_counter = 0
  7.     ea = inf_get_min_ea()
  8.     for funcAddr in Functions(get_segm_start(ea), get_segm_end(ea)):
  9.         name = get_func_name(funcAddr)
  10.         instructions_addresses = list(FuncItems(funcAddr))
  11.         for addr in instructions_addresses:
  12.             instruction = print_insn_mnem(addr)
  13.             if instruction == "xor" and print_operand(addr, 1) != print_operand(addr, 0):
  14.                 xor_counter += 1
  15.                 print("In function {} at addr 0x{} {} {}, {}".format(name, addr, instruction, print_operand(addr, 0), print_operand(addr, 1)))
  16.     print("Total quantity of XOR operation: {}".format(xor_counter))
  17.    
  18.  
  19. def find_defense():
  20.     print("========================")
  21.     functions = list(["ds:CheckRemoteDebuggerPresent", "ds:IsDebuggerPresent"])
  22.     ea = inf_get_min_ea()
  23.     for funcAddr in Functions(get_segm_start(ea), get_segm_end(ea)):
  24.         name = get_func_name(funcAddr)
  25.         instructions_addresses = list(FuncItems(funcAddr))
  26.         for addr in instructions_addresses:
  27.             instruction = print_insn_mnem(addr)
  28.             if instruction == "call":
  29.                 oper = print_operand(addr, 0)
  30.                 for i in functions:
  31.                     if oper.find(i) != -1:
  32.                         print("In function {} is detected at addr 0x{} call {}".format(name, funcAddr, oper))
  33.     print("========================")
  34.  
  35. def find_time_manages():
  36.     print("========================")
  37.     functions = list(["ds:GetTickCount", "ds:GetSystemTimeAsFileTime"])
  38.     ea = inf_get_min_ea()
  39.     for funcAddr in Functions(get_segm_start(ea), get_segm_end(ea)):
  40.         name = get_func_name(funcAddr)
  41.         instructions_addresses = list(FuncItems(funcAddr))
  42.         for addr in instructions_addresses:
  43.             instruction = print_insn_mnem(addr)
  44.             if instruction == "call":
  45.                 oper = print_operand(addr, 0)
  46.                 for i in functions:
  47.                     if oper.find(i) != -1:
  48.                         print("In function {} is detected at addr 0x{} call {}".format(name, funcAddr, oper))
  49.             elif instruction == "rdtsc":
  50.                 oper = print_operand(addr, 0)
  51.                 print("In function {} is detected at addr 0x{} rtdsc {}".format(name, funcAddr, oper))
  52.  
  53. def find_rare():
  54.     print("========================")
  55.     ea = inf_get_min_ea()
  56.     for funcAddr in Functions(get_segm_start(ea), get_segm_end(ea)):
  57.         name = get_func_name(funcAddr)
  58.         instructions_addresses = list(FuncItems(funcAddr))
  59.         for addr in instructions_addresses:
  60.             instruction = print_insn_mnem(addr)
  61.             if instruction == "int":
  62.                 oper = print_operand(addr, 0)
  63.                 print("In function {} is detected at addr 0x{} int {}".format(name, funcAddr, oper))
  64.     print("========================")
  65.  
  66. def find_peb_teb():
  67.     print("========================")
  68.     ea = inf_get_min_ea()
  69.     for funcAddr in Functions(get_segm_start(ea), get_segm_end(ea)):
  70.         name = get_func_name(funcAddr)
  71.         instructions_addresses = list(FuncItems(funcAddr))
  72.         for addr in instructions_addresses:
  73.             instruction = print_insn_mnem(addr)
  74.             if instruction == "mov":
  75.                 oper = print_operand(addr, 1)
  76.                 if oper.find("fs:30h") != -1:
  77.                     print("Reading from PEB detected\nIn function {} is detected at addr 0x{} mov {}, {}".format(name, funcAddr,  print_operand(addr, 0), oper))
  78.                 elif oper.find("fs:18h") != -1:
  79.                     print("Reading from TEB detected\nIn function {} is detected at addr 0x{} mov {}, {}".format(name, funcAddr,  print_operand(addr, 0), oper))
  80.  
  81. def find_crypt():
  82.     print("========================")
  83.     ea = inf_get_min_ea()
  84.     jmps = ['jmp', 'jnz', 'jz', 'jbe', 'jne', 'je', 'jb', 'jg', 'jge']
  85.     for func in Functions(get_segm_start(ea), get_segm_end(ea)):
  86.         func_name = get_func_name(func)
  87.         xor_addr = 0
  88.         instructions_addresses = list(FuncItems(func))
  89.         for instr_addr in instructions_addresses:
  90.             if print_insn_mnem(instr_addr) == 'xor':
  91.                 code = print_operand(instr_addr, 1)[0:-1]
  92.                 try:
  93.                     val = int(code)
  94.                 except ValueError:
  95.                     pass
  96.                 else:
  97.                     if val <= 8192 and val >= 1:
  98.                         xor_value = val
  99.                         xor_addr = instr_addr
  100.    
  101.             if print_insn_mnem(instr_addr) in jmps:
  102.                 oper = print_operand(instr_addr, 0)
  103.                 if oper.find('loc_') != -1:
  104.                     if instr_addr > xor_addr and xor_addr > int(oper[4:len(oper) + 1], 16):
  105.                         print ("Function with xor coding {} at address {}. Constant key = {}".format(func_name, hex(func)[0:-1].upper(), xor_value))
  106.     print("========================")
  107.  
  108. def anti_xor():
  109.     mov_counter = 0
  110.     decrypted = list()
  111.     print("========================")
  112.     ea = inf_get_min_ea()
  113.     for funcAddr in Functions(get_segm_start(ea), get_segm_end(ea)):
  114.         name = get_func_name(funcAddr)
  115.         instructions_addresses = list(FuncItems(funcAddr))
  116.         for addr in instructions_addresses:
  117.             if print_insn_mnem(addr) == "mov":
  118.                 if print_operand(addr, 1) == "0" and mov_counter > 2 and decrypted is not None:
  119.                     string = ""
  120.                     for i in decrypted:
  121.                         symbol = i ^ 0x22
  122.                         if symbol == 32 or symbol == 33 or (symbol >= 40 and symbol <= 126):
  123.                             string += chr(symbol)
  124.                     if string != "":
  125.                         print (repr(string))
  126.                     decrypted = list()
  127.                     mov_counter = 0
  128.                 if get_operand_type(addr,1) == 5:
  129.                     decrypted.append(get_operand_value(addr, 1))
  130.                     mov_counter += 1
  131.             else:
  132.                 mov_counter = 0
  133.                 decrypted = list()
  134.     print("========================")
  135.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement