CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

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