Archangelwu

Wirelurker 1.1.0 running with python 3.3.3

Nov 10th, 2014
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. """Detecting the WireLurker malware family on Mac OS X."""
  5.  
  6.  
  7. __copyright__ = 'Copyright (c) 2014, Palo Alto Networks, Inc.'
  8. __author__ = 'Claud Xiao'
  9. __version__ = '1.1.0'
  10.  
  11.  
  12. import os
  13. import sys
  14. import platform
  15. import plistlib
  16. import subprocess
  17. from os.path import expanduser
  18.  
  19.  
  20. MALICIOUS_FILES = [
  21. '/Users/Shared/run.sh',
  22. '/Library/LaunchDaemons/com.apple.machook_damon.plist',
  23. '/Library/LaunchDaemons/com.apple.globalupdate.plist',
  24. '/usr/bin/globalupdate/usr/local/machook/',
  25. '/usr/bin/WatchProc',
  26. '/usr/bin/itunesupdate',
  27. '/Library/LaunchDaemons/com.apple.watchproc.plist',
  28. '/Library/LaunchDaemons/com.apple.itunesupdate.plist',
  29. '/System/Library/LaunchDaemons/com.apple.appstore.plughelper.plist',
  30. '/System/Library/LaunchDaemons/com.apple.MailServiceAgentHelper.plist',
  31. '/System/Library/LaunchDaemons/com.apple.systemkeychain-helper.plist',
  32. '/System/Library/LaunchDaemons/com.apple.periodic-dd-mm-yy.plist',
  33. '/usr/bin/com.apple.MailServiceAgentHelper',
  34. '/usr/bin/com.apple.appstore.PluginHelper',
  35. '/usr/bin/periodicdate',
  36. '/usr/bin/systemkeychain-helper',
  37. '/usr/bin/stty5.11.pl',
  38. ]
  39.  
  40. SUSPICIOUS_FILES = [
  41. '/etc/manpath.d/',
  42. '/usr/local/ipcc/',
  43. os.path.join(expanduser('~'), 'Library/Caches/com.maiyadi.appinstaller/'),
  44. os.path.join(expanduser('~'), 'Library/Saved Application State/com.maiyadi.appinstaller.savedState/'),
  45. ]
  46.  
  47.  
  48. def scan_files(paths):
  49. results = []
  50.  
  51. for f in paths:
  52. if os.path.exists(f):
  53. results.append(f)
  54.  
  55. return results
  56.  
  57.  
  58. def is_file_hidden(f):
  59. if not os.path.exists(f) or not os.path.isfile(f):
  60. return False
  61.  
  62. if sys.version_info[0] >= 2 and sys.version_info[2] >= 7 and sys.version_info >= 3:
  63. return os.stat(f).st_flags.UF_HIDDEN
  64.  
  65. else:
  66. try:
  67. proc = subprocess.Popen("ls -ldO '%s' | awk '{print $5}'" % f, shell=True,
  68. stdout=subprocess.PIPE,
  69. stderr=subprocess.STDOUT)
  70. output = proc.stdout.read()
  71. proc.communicate()
  72. return output.find('hidden') != -1
  73.  
  74. except Exception as e:
  75. return False
  76.  
  77.  
  78. def is_app_infected(root):
  79. try:
  80. pl = plistlib.readPlist(os.path.join(root, 'Contents', 'Info.plist'))
  81. be = pl['CFBundleExecutable']
  82. bundle_exec = os.path.join(root, 'Contents', 'MacOS', be)
  83. bundle_exec_ = bundle_exec + '_'
  84. if is_file_hidden(bundle_exec) and is_file_hidden(bundle_exec_):
  85. return True
  86.  
  87. the_script = os.path.join(root, 'Contents', 'Resources', 'start.sh')
  88. the_pack = os.path.join(root, 'Contents', 'Resources', 'FontMap1.cfg')
  89. if is_file_hidden(the_script) and is_file_hidden(the_pack):
  90. return True
  91.  
  92. the_installer = os.path.join(root, 'Contents', 'MacOS', 'appinstaller')
  93. the_mal_ipa = os.path.join(root, 'Contents', 'Resources', 'infoplistab')
  94. if os.path.isfile(the_installer) and os.path.isfile(the_mal_ipa):
  95. return True
  96.  
  97. return False
  98.  
  99. except Exception:
  100. return False
  101.  
  102.  
  103. def scan_app():
  104. infected_apps = []
  105.  
  106. for target in ['/Applications', expanduser('~/Applications')]:
  107. for root, __, __ in os.walk(target):
  108. if root.lower().endswith('.app'):
  109. if is_app_infected(root):
  110. infected_apps.append(root)
  111.  
  112. return infected_apps
  113.  
  114.  
  115. def main():
  116. print ('WireLurker Detector (version %s)' % __version__)
  117. print (__copyright__)
  118. print ('')
  119.  
  120. if platform.system() != 'Darwin':
  121. print ('ERROR: The script should only be run in a Mac OS X system.')
  122. sys.exit(-1)
  123.  
  124. print ('[+] Scanning for known malicious files ...')
  125. mal_files = scan_files(MALICIOUS_FILES)
  126. if len(mal_files) == 0:
  127. print ('[-] Nothing is found.')
  128. else:
  129. for f in mal_files:
  130. print ('[!] Found malicious file: %s' % f)
  131.  
  132. print ('[+] Scanning for known suspicious files ...')
  133. sus_files = scan_files(SUSPICIOUS_FILES)
  134. if len(sus_files) == 0:
  135. print ('[-] Nothing is found.')
  136. else:
  137. for f in sus_files:
  138. print ('[!] Found suspicious file: %s' % f)
  139.  
  140. print ('[+] Scanning for infected applications ... (may take minutes)')
  141. infected_apps = scan_app()
  142. if len(infected_apps) == 0:
  143. print ('[-] Nothing is found.')
  144. else:
  145. for a in infected_apps:
  146. print ('[!] Found infected application: %s' % a)
  147.  
  148. if len(mal_files) == 0 and len(sus_files) == 0 and len(infected_apps) == 0:
  149. print ("[+] Your OS X system isn't infected by the WireLurker. Thank you!")
  150. return 0
  151. else:
  152. print ("[!] WARNING: Your OS X system is highly suspicious of being infected by the WireLurker.\n" \
  153. "[!] You may need to delete all malicious or suspicious files and/or applications above.\n" \
  154. "[!] For more information about the WireLurker, please refer: \n"\
  155. "[!] http://researchcenter.paloaltonetworks.com/2014/11/wirelurker-new-era-os-x-ios-malware/")
  156. return 1
  157.  
  158.  
  159. if __name__ == '__main__':
  160. main()
Advertisement
Add Comment
Please, Sign In to add comment