@@ -15,6 +15,12 @@ module Exploit::Remote::Gdb
15
15
16
16
include Msf ::Exploit ::Remote ::Tcp
17
17
18
+ # thrown when an expected ACK packet is never received
19
+ class BadAckError < RuntimeError ; end
20
+
21
+ # thrown when a response is incorrect
22
+ class BadResponseError < RuntimeError ; end
23
+
18
24
# Default list of supported GDB features to send the to the target
19
25
GDB_FEATURES = 'qSupported:multiprocess+;qRelocInsn+;qvCont+;'
20
26
@@ -31,10 +37,10 @@ def send_ack
31
37
end
32
38
33
39
# Reads an ACK packet from the wire
34
- # @raise [RuntimeError ] if a bad ACK is received
40
+ # @raise [BadAckError ] if a bad ACK is received
35
41
def read_ack
36
42
unless sock . get_once == '+'
37
- raise 'received bad ack'
43
+ raise BadAckError
38
44
end
39
45
vprint_status ( 'Received ack...' )
40
46
end
@@ -53,9 +59,11 @@ def send_cmd(cmd)
53
59
# @param opts [Hash] the options hash
54
60
# @option opts :decode [Boolean] rle decoding should be applied to the response
55
61
# @return [String] the response
62
+ # @raise [BadResponseError] if the expected response is missing
56
63
def read_response ( opts = { } )
57
64
decode = opts . fetch ( :decode , false )
58
65
res = sock . get_once
66
+ raise BadResponseError if res . nil?
59
67
res = decode_rle ( res ) if decode
60
68
vprint_status ( 'Result: ' +res )
61
69
send_ack
@@ -95,9 +103,12 @@ def write(buf, addr)
95
103
96
104
# Steps execution and finds $PC pointer and architecture
97
105
# @return [Hash] with :arch and :pc keys containing architecture and PC pointer
106
+ # @raise [BadResponseError] if necessary data is missing
98
107
def process_info
99
108
data = step
100
- pc_data = data . split ( ';' ) [ 2 ] . split ( ':' )
109
+ pc_data = data . split ( ';' ) [ 2 ]
110
+ raise BadResponseError if pc_data . nil?
111
+ pc_data = pc_data . split ( ':' )
101
112
my_arch = PC_REGISTERS [ pc_data [ 0 ] ]
102
113
pc = pc_data [ 1 ]
103
114
@@ -107,7 +118,8 @@ def process_info
107
118
108
119
{
109
120
arch : my_arch ,
110
- pc : Rex ::Text . to_hex ( Rex ::Arch . pack_addr ( my_arch , Integer ( pc , 16 ) ) , '' )
121
+ pc : Rex ::Text . to_hex ( Rex ::Arch . pack_addr ( my_arch , Integer ( pc , 16 ) ) , '' ) ,
122
+ pc_raw : Integer ( pc , 16 )
111
123
}
112
124
end
113
125
@@ -141,6 +153,11 @@ def step
141
153
read_response ( decode : true )
142
154
end
143
155
156
+ def run ( filename )
157
+ send_cmd "vRun;#{ Rex ::Text . to_hex ( filename , '' ) } "
158
+ read_response
159
+ end
160
+
144
161
# Performs a handshake packet exchange
145
162
# @param features [String] the list of supported features to tell the remote
146
163
# host that the client supports (defaults to +DEFAULT_GDB_FEATURES+)
0 commit comments