/我手敲的代码(中文注释)/chapter11/volatility-2.3/build/lib/volatility/plugins/sockets.py

https://github.com/giantbranch/python-hacker-code · Python · 72 lines · 39 code · 10 blank · 23 comment · 6 complexity · 6c51560a4a295023ea15a2bdc214af9a MD5 · raw file

  1. # Volatility
  2. #
  3. # Authors:
  4. # Mike Auty <mike.auty@gmail.com>
  5. #
  6. # This file is part of Volatility.
  7. #
  8. # Volatility is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License Version 2 as
  10. # published by the Free Software Foundation. You may not use, modify or
  11. # distribute this program under any other version of the GNU General
  12. # Public License.
  13. #
  14. # Volatility is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with Volatility. If not, see <http://www.gnu.org/licenses/>.
  21. #
  22. #pylint: disable-msg=C0111
  23. import volatility.plugins.common as common
  24. import volatility.debug as debug
  25. import volatility.win32 as win32
  26. import volatility.utils as utils
  27. import volatility.protos as protos
  28. class Sockets(common.AbstractWindowsCommand):
  29. """Print list of open sockets"""
  30. def __init__(self, config, *args, **kwargs):
  31. common.AbstractWindowsCommand.__init__(self, config, *args, **kwargs)
  32. config.add_option("PHYSICAL-OFFSET", short_option = 'P', default = False,
  33. cache_invalidator = False,
  34. help = "Physical Offset", action = "store_true")
  35. @staticmethod
  36. def is_valid_profile(profile):
  37. return (profile.metadata.get('os', 'unknown') == 'windows' and
  38. profile.metadata.get('major', 0) == 5)
  39. def render_text(self, outfd, data):
  40. offsettype = "(V)" if not self._config.PHYSICAL_OFFSET else "(P)"
  41. self.table_header(outfd,
  42. [("Offset{0}".format(offsettype), "[addrpad]"),
  43. ("PID", ">8"),
  44. ("Port", ">6"),
  45. ("Proto", ">6"),
  46. ("Protocol", "15"),
  47. ("Address", "15"),
  48. ("Create Time", "")
  49. ])
  50. for sock in data:
  51. if not self._config.PHYSICAL_OFFSET:
  52. offset = sock.obj_offset
  53. else:
  54. offset = sock.obj_vm.vtop(sock.obj_offset)
  55. self.table_row(outfd, offset, sock.Pid, sock.LocalPort, sock.Protocol,
  56. protos.protos.get(sock.Protocol.v(), "-"),
  57. sock.LocalIpAddress, sock.CreateTime)
  58. def calculate(self):
  59. addr_space = utils.load_as(self._config)
  60. if not self.is_valid_profile(addr_space.profile):
  61. debug.error("This command does not support the selected profile.")
  62. return win32.network.determine_sockets(addr_space)