Skip to content

Commit e6fe90e

Browse files
committed
added robots.txt support for http exploit server
1 parent 39b2e82 commit e6fe90e

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
@@ -42,7 +42,8 @@ def initialize(info = {})
4242

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

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

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

185205
# Set {#on_request_uri} to handle the given +uri+ in addition to the one
@@ -605,6 +625,22 @@ def send_not_found(cli)
605625
cli.send_response(resp_404)
606626
end
607627

628+
#
629+
# Sends a canned robots.txt file
630+
#
631+
def send_robots(cli, request)
632+
print_status("sending robots.txt")
633+
robots = create_response(200, 'Success')
634+
robots['Content-Type'] = "text/plain"
635+
636+
robots.body = %Q{\
637+
User-agent: *
638+
Disallow: /
639+
}
640+
641+
cli.send_response(robots)
642+
end
643+
608644

609645
#
610646
# Returns the configured (or random, if not configured) URI path

0 commit comments

Comments
 (0)