/volatility/volatility/plugins/registry/shutdown.py

https://github.com/Cisco-Talos/pyrebox · Python · 110 lines · 73 code · 12 blank · 25 comment · 15 complexity · 58da25c5fd4ec5b555ab83abda12cf08 MD5 · raw file

  1. # Volatility
  2. # Copyright (C) 2008-2013 Volatility Foundation
  3. #
  4. # This file is part of Volatility.
  5. #
  6. # Volatility is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # Volatility is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Volatility. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. """
  20. @author: Jamie Levy (gleeda)
  21. @license: GNU General Public License 2.0
  22. @contact: jamie@memoryanalysis.net
  23. @organization: Volatility Foundation
  24. """
  25. #pylint: disable-msg=C0111
  26. import volatility.plugins.registry.registryapi as registryapi
  27. from volatility.renderers import TreeGrid
  28. import volatility.plugins.common as common
  29. import volatility.addrspace as addrspace
  30. import volatility.obj as obj
  31. import volatility.debug as debug
  32. import volatility.utils as utils
  33. import datetime
  34. import struct
  35. class ShutdownTime(common.AbstractWindowsCommand):
  36. "Print ShutdownTime of machine from registry"
  37. def __init__(self, config, *args, **kwargs):
  38. common.AbstractWindowsCommand.__init__(self, config, *args, **kwargs)
  39. config.add_option('HIVE-OFFSET', short_option = 'o',
  40. help = 'Hive offset (virtual)', type = 'int')
  41. self.regapi = None
  42. def calculate(self):
  43. addr_space = utils.load_as(self._config)
  44. self.regapi = registryapi.RegistryApi(self._config)
  45. result = {}
  46. if not self._config.HIVE_OFFSET:
  47. self.regapi.set_current("SYSTEM")
  48. else:
  49. name = obj.Object("_CMHIVE", vm = addr_space, offset = self._config.HIVE_OFFSET).get_name()
  50. self.regapi.all_offsets[self._config.HIVE_OFFSET] = name
  51. self.regapi.current_offsets[self._config.HIVE_OFFSET] = name
  52. self.regapi.reset_current()
  53. currentcs = self.regapi.reg_get_currentcontrolset()
  54. if currentcs == None:
  55. currentcs = "ControlSet001"
  56. shutdownkey = currentcs + "\\Control\\Windows"
  57. key = self.regapi.reg_get_key("system", shutdownkey)
  58. value = self.regapi.reg_get_value("system", shutdownkey, "ShutdownTime", given_root = key)
  59. result["key"] = key
  60. result["hive"] = "SYSTEM"
  61. result["valuename"] = "ShutdownTime"
  62. result["value"] = value
  63. result["timestamp"] = ""
  64. if value != None:
  65. try:
  66. bufferas = addrspace.BufferAddressSpace(self._config, data = value)
  67. result["timestamp"] = obj.Object("WinTimeStamp", vm = bufferas, offset = 0, is_utc = True)
  68. except (struct.error, TypeError):
  69. pass
  70. yield result
  71. def unified_output(self, data):
  72. return TreeGrid([("Registry", str),
  73. ("KeyPath", str),
  74. ("LastWrite", str),
  75. ("ValueName", str),
  76. ("Value", str),
  77. ], self.generator(data))
  78. def generator(self, data):
  79. for result in data:
  80. if result["key"]:
  81. yield (0, [str(result["hive"]),
  82. str(self.regapi.reg_get_key_path(result["key"])),
  83. str(result["key"].LastWriteTime),
  84. str(result["valuename"]),
  85. str(result["timestamp"] if result["timestamp"] else result["value"])
  86. ])
  87. def render_text(self, outfd, data):
  88. keyfound = False
  89. for result in data:
  90. if result["key"]:
  91. keyfound = True
  92. outfd.write("Registry: {0}\n".format(result["hive"]))
  93. outfd.write("Key Path: {0}\n".format(self.regapi.reg_get_key_path(result["key"])))
  94. outfd.write("Key Last updated: {0}\n".format(result["key"].LastWriteTime))
  95. outfd.write("Value Name: {0}\n".format(result["valuename"]))
  96. outfd.write("Value: {0}\n\n".format(result["timestamp"] if result["timestamp"] else result["value"]))
  97. if not keyfound:
  98. outfd.write("The requested key could not be found in the hive(s) searched\n")