@@ -42,7 +42,8 @@ def initialize(info = {})
42
42
43
43
register_advanced_options ( [
44
44
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 ] ) ,
46
47
] )
47
48
48
49
# Used to keep track of resources added to the service manager by
@@ -179,7 +180,26 @@ def start_service(opts = {})
179
180
print_status ( "Local IP: #{ proto } ://#{ Rex ::Socket . source_address ( '1.2.3.4' ) } :#{ opts [ 'ServerPort' ] } #{ uopts [ 'Path' ] } " )
180
181
end
181
182
183
+ if datastore [ 'SendRobots' ]
184
+ add_robots_resource ( )
185
+ end
186
+
182
187
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
183
203
end
184
204
185
205
# Set {#on_request_uri} to handle the given +uri+ in addition to the one
@@ -605,6 +625,22 @@ def send_not_found(cli)
605
625
cli . send_response ( resp_404 )
606
626
end
607
627
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
+
608
644
609
645
#
610
646
# Returns the configured (or random, if not configured) URI path
0 commit comments