Skip to content

Commit c9853a6

Browse files
committed
Land rapid7#8735, robots.txt for HttpServer
2 parents 2d9e14b + a950ecc commit c9853a6

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

lib/msf/core/exploit/http/server.rb

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ def initialize(info = {})
4343

4444
register_advanced_options([
4545
OptAddress.new('URIHOST', [false, 'Host to use in URI (useful for tunnels)']),
46-
OptPort.new('URIPORT', [false, 'Port to use in URI (useful for tunnels)'])
46+
OptPort.new('URIPORT', [false, 'Port to use in URI (useful for tunnels)']),
47+
OptBool.new('SendRobots', [false, 'Return a robots.txt file if asked for one', false])
4748
])
4849

4950
# Used to keep track of resources added to the service manager by
@@ -180,7 +181,26 @@ def start_service(opts = {})
180181
print_status("Local IP: #{proto}://#{Rex::Socket.source_address('1.2.3.4')}:#{opts['ServerPort']}#{uopts['Path']}")
181182
end
182183

184+
if datastore['SendRobots']
185+
add_robots_resource
186+
end
187+
183188
add_resource(uopts)
189+
190+
end
191+
192+
def add_robots_resource
193+
proc = Proc.new do |cli, req|
194+
self.cli = cli
195+
send_robots(cli, req)
196+
end
197+
198+
vprint_status('Adding hardcoded URI /robots.txt')
199+
begin
200+
add_resource('Path' => '/robots.txt', 'Proc' => proc)
201+
rescue RuntimeError => e
202+
print_warning(e.message)
203+
end
184204
end
185205

186206
# Set {#on_request_uri} to handle the given +uri+ in addition to the one
@@ -610,6 +630,22 @@ def send_not_found(cli)
610630
cli.send_response(resp_404)
611631
end
612632

633+
#
634+
# Sends a canned robots.txt file
635+
#
636+
def send_robots(cli, request)
637+
print_status('Sending robots.txt')
638+
robots = create_response(200, 'Success')
639+
robots['Content-Type'] = 'text/plain'
640+
641+
robots.body = %Q{\
642+
User-agent: *
643+
Disallow: /
644+
}
645+
646+
cli.send_response(robots)
647+
end
648+
613649

614650
#
615651
# Returns the configured (or random, if not configured) URI path

0 commit comments

Comments
 (0)