/lib/msf/base/sessions/meterpreter_python.rb

https://github.com/jduck/metasploit-framework · Ruby · 120 lines · 103 code · 10 blank · 7 comment · 5 complexity · 845e15e1f5be6198010c2b1dc652abcf MD5 · raw file

  1. # -*- coding: binary -*-
  2. require 'msf/base/sessions/meterpreter'
  3. require 'msf/windows_error'
  4. module Msf
  5. module Sessions
  6. ###
  7. #
  8. # This class creates a platform-specific meterpreter session type
  9. #
  10. ###
  11. class Meterpreter_Python_Python < Msf::Sessions::Meterpreter
  12. ERROR_TYPE_UNKNOWN = 1
  13. ERROR_TYPE_PYTHON = 2
  14. ERROR_TYPE_WINDOWS = 3
  15. # 16-bit CRC-CCITT XMODEM
  16. PYTHON_ERROR_CRCS = {
  17. 0x02dd => 'NotImplementedError',
  18. 0x049a => 'RuntimeWarning',
  19. 0x09ae => 'IndentationError',
  20. 0x0bf4 => 'SystemExit',
  21. 0x1494 => 'GeneratorExit',
  22. 0x1511 => 'ConnectionRefusedError',
  23. 0x1765 => 'SyntaxWarning',
  24. 0x1f0e => 'SystemError',
  25. 0x33b1 => 'StandardError',
  26. 0x37b8 => 'IOError',
  27. 0x39df => 'PermissionError',
  28. 0x39e6 => 'AttributeError',
  29. 0x3b70 => 'ChildProcessError',
  30. 0x3c93 => 'UserWarning',
  31. 0x3ca3 => 'BufferError',
  32. 0x3e32 => 'StopIteration',
  33. 0x423c => 'NotADirectoryError',
  34. 0x42f1 => 'ConnectionError',
  35. 0x453b => 'UnboundLocalError',
  36. 0x470d => 'LookupError',
  37. 0x4cb2 => 'WindowsError',
  38. 0x4ecc => 'ResourceWarning',
  39. 0x532d => 'UnicodeEncodeError',
  40. 0x5dde => 'ConnectionAbortedError',
  41. 0x6011 => 'EOFError',
  42. 0x637f => 'UnicodeWarning',
  43. 0x6482 => 'RuntimeError',
  44. 0x6a75 => 'ArithmeticError',
  45. 0x6b73 => 'BlockingIOError',
  46. 0x70e0 => 'UnicodeDecodeError',
  47. 0x72b4 => 'AssertionError',
  48. 0x75a1 => 'TabError',
  49. 0x77c2 => 'ReferenceError',
  50. 0x7a4c => 'FutureWarning',
  51. 0x7a78 => 'Warning',
  52. 0x7ef9 => 'IsADirectoryError',
  53. 0x81dc => 'ConnectionResetError',
  54. 0x87fa => 'OSError',
  55. 0x8937 => 'KeyError',
  56. 0x8a80 => 'SyntaxError',
  57. 0x8f3e => 'TypeError',
  58. 0x9329 => 'MemoryError',
  59. 0x956e => 'ValueError',
  60. 0x96a1 => 'OverflowError',
  61. 0xa451 => 'InterruptedError',
  62. 0xa4d7 => 'FileExistsError',
  63. 0xb19a => 'ZeroDivisionError',
  64. 0xb27b => 'IndexError',
  65. 0xb628 => 'UnicodeError',
  66. 0xbb63 => 'TimeoutError',
  67. 0xbc91 => 'ImportWarning',
  68. 0xc18f => 'BrokenPipeError',
  69. 0xc3a0 => 'KeyboardInterrupt',
  70. 0xcbab => 'ImportError',
  71. 0xcd47 => 'NameError',
  72. 0xcd82 => 'ProcessLookupError',
  73. 0xdd4a => 'BaseException',
  74. 0xe5a3 => 'BytesWarning',
  75. 0xe97a => 'FileNotFoundError',
  76. 0xe98a => 'PendingDeprecationWarning',
  77. 0xf47c => 'DeprecationWarning',
  78. 0xf7c6 => 'Exception',
  79. 0xfa9d => 'EnvironmentError',
  80. 0xfcb4 => 'UnicodeTranslateError',
  81. 0xff8d => 'FloatingPointError'
  82. }
  83. def initialize(rstream, opts={})
  84. super
  85. self.platform = 'python/python'
  86. self.binary_suffix = 'py'
  87. end
  88. def lookup_error(error_code)
  89. unknown_error = 'Unknown error'
  90. error_type = error_code & 0x0f
  91. return unknown_error if error_type == ERROR_TYPE_UNKNOWN
  92. error_code &= 0xffff0000
  93. error_code >>= 16
  94. if error_type == ERROR_TYPE_PYTHON
  95. python_error = PYTHON_ERROR_CRCS[error_code]
  96. return "Python exception: #{python_error}" unless python_error.nil?
  97. elsif error_type == ERROR_TYPE_WINDOWS
  98. return "Windows error: #{Msf::WindowsError.description(error_code)}"
  99. end
  100. unknown_error
  101. end
  102. def supports_ssl?
  103. false
  104. end
  105. def supports_zlib?
  106. false
  107. end
  108. end
  109. end
  110. end