Advertisement
Guest User

check_plugins

a guest
Mar 1st, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.58 KB | None | 0 0
  1. #!/usr/bin/python
  2. ############
  3. # Script to check for blocked browser plug-ins in Mac OS X.
  4. # Requires biplist: https://bitbucket.org/wooster/biplist
  5. ############
  6. # 1.0 - Jorge Escala - 2013-03-01
  7. #        * Initial script creation.
  8. ############
  9.  
  10. import os.path, sys, getopt
  11. from distutils.version import LooseVersion
  12. from biplist import *
  13.  
  14. # Variables
  15. VERSION = "1.0"
  16. CMDNAME = os.path.basename(sys.argv[0])
  17. javaOK = True
  18. flashOK = True
  19.  
  20. # Set PLIST Paths
  21. XPROT_PLIST = "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/XProtect.meta.plist"
  22. FLASH_PLIST = "/Library/Internet Plug-Ins/Flash Player.plugin/Contents/Info.plist"
  23. JAVA_PLIST = "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist"
  24. pldict = {}
  25. reconEA_opt = False
  26. verbose_opt = False
  27.  
  28. def version():
  29.         print CMDNAME + ", version " + VERSION
  30.         sys.exit(1)
  31.  
  32. def usage():
  33.     print CMDNAME + " (" + VERSION + ")"
  34.     print "(C)2013 Jorge Escala"
  35.     print "usage: " + CMDNAME + " [option]"
  36.     print "options:"
  37.     print "    -h  display this usage screen"
  38.     print "    -r  run as a JAMF Casper Suite Recon Extended Attribute"
  39.     print "    -v  display version"
  40.     print "    -V  verbose output"
  41.     sys.exit(1)
  42.  
  43. def verbose():
  44.     print "Minimum Flash: "+minFlash
  45.     print "Current Flash: "+currentFlash
  46.     print "Minimum Java:  "+minJava
  47.     print "Current Java:  "+currentJava
  48.  
  49. try:
  50.     opts, args = getopt.getopt(sys.argv[1:], 'hvVr')
  51. except getopt.GetoptError, err:
  52.     print >> sys.stderr, CMDNAME + ": " + str(err)
  53.     sys.exit(2)
  54.  
  55. for o, a in opts:
  56.         if o == "-h":
  57.                 usage()
  58.         elif o == "-r":
  59.                 reconEA_opt = True
  60.         elif o == "-v":
  61.                 version()
  62.         elif o == "-V":
  63.                 verbose_opt = True
  64.  
  65. # Get blocked versions
  66. if os.path.isfile(XPROT_PLIST):
  67.     try:
  68.         plist = readPlist(XPROT_PLIST)
  69.     except (InvalidPlistException, NotBinaryPlistException), e:
  70.         print "Not a plist:", e
  71.     try:
  72.         minFlash = plist["PlugInBlacklist"]["10"]["com.macromedia.Flash Player.plugin"]["MinimumPlugInBundleVersion"]
  73.     except KeyError:
  74.         minFlash = ""
  75.     try:
  76.         minJava = plist["PlugInBlacklist"]["10"]["com.oracle.java.JavaAppletPlugin"]["MinimumPlugInBundleVersion"]
  77.     except KeyError:
  78.         minJava = ""
  79. else:
  80.     sys.stderr.write("ERROR: XProtect not found.\n")
  81.     sys.exit(3)
  82.  
  83. # Get current Flash version
  84. if os.path.isfile(FLASH_PLIST):
  85.     try:
  86.         plist = readPlist(FLASH_PLIST)
  87.     except (InvalidPlistException, NotBinaryPlistException), e:
  88.         print "Not a plist:", e
  89.     try:
  90.         currentFlash = plist["CFBundleVersion"]
  91.     except KeyError:
  92.         currentFlash = "Problem Detected"
  93. else:
  94.     currentFlash = "Not Installed"
  95.  
  96. # Get current Java version
  97. if os.path.isfile(JAVA_PLIST):
  98.     try:
  99.         plist = readPlist(JAVA_PLIST)
  100.     except (InvalidPlistException, NotBinaryPlistException), e:
  101.         print "Not a plist:", e
  102.     try:
  103.         currentJava = plist["CFBundleVersion"]
  104.     except KeyError:
  105.         currentJava = "Problem Detected"
  106. else:
  107.     currentJava = "Not Installed"
  108.  
  109. # Check for verbose run
  110. if verbose_opt:
  111.     verbose()
  112.  
  113. # Check for blocked plug-ins
  114. if LooseVersion(minFlash) > LooseVersion(currentFlash):
  115.     flashOK = False
  116. if LooseVersion(minJava) > LooseVersion(currentJava):
  117.     javaOK = False
  118.  
  119. if reconEA_opt:
  120.     result = ""
  121.     if not flashOK:
  122.         result = result+"Flash "
  123.     if not javaOK:
  124.         result = result+"Java "
  125.     print "<result>"+result+"</result>"
  126.     sys.exit(0)
  127. else:
  128.     if not flashOK:
  129.         print "Adobe Flash is blocked and must be updated to "+minFlash
  130.     if not javaOK:
  131.         print "Oracle Java is blocked and must be updated to "+minJava
  132.     if not flashOK or not javaOK:
  133.         sys.exit(4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement