@@ -43,7 +43,8 @@ def initialize(info = {})
43
43
44
44
register_advanced_options ( [
45
45
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 ] )
47
48
] )
48
49
49
50
# Used to keep track of resources added to the service manager by
@@ -180,7 +181,26 @@ def start_service(opts = {})
180
181
print_status ( "Local IP: #{ proto } ://#{ Rex ::Socket . source_address ( '1.2.3.4' ) } :#{ opts [ 'ServerPort' ] } #{ uopts [ 'Path' ] } " )
181
182
end
182
183
184
+ if datastore [ 'SendRobots' ]
185
+ add_robots_resource
186
+ end
187
+
183
188
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
184
204
end
185
205
186
206
# Set {#on_request_uri} to handle the given +uri+ in addition to the one
@@ -610,6 +630,22 @@ def send_not_found(cli)
610
630
cli . send_response ( resp_404 )
611
631
end
612
632
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
+
613
649
614
650
#
615
651
# Returns the configured (or random, if not configured) URI path
0 commit comments