Skip to content

Running And Pinging HTTPD on OpenBSD

Stephen Malina edited this page Dec 30, 2016 · 2 revisions

December 30, 2016

Goal

Get httpd to return reasonable results to me through a curl command from my local machine.

Summary

  1. Modified httpd's config file ("/etc/httpd.conf") to include the following.
prefork 2 # Not needed, mostly for experimenting.
 
server "default" { 
	listen on * port 80 
  directory auto index
} 
 
types { 
	text/css		css 
	text/html		html htm 
	text/plain		txt 
	image/gif		gif 
	image/jpeg		jpeg jpg 
	image/png		png 
	application/javascript	js 
	application/xml		xml 
}
  1. Ran httpd in verbose / debug mode.
$ doas httpd -d -v
  1. Made a curl request from my local machine. Received a 403 Forbidden in response.
$ curl 107.191.39.182
  1. Added a bunch of print statements to the code to figure out where in the code the 403 got set. Figured out that the error happened in server_file_access as a result of not setting auto index in httpd's config file.
  2. Modified the config file to include directory auto index (see above).
  3. Now I'm getting back an empty "index.html".

Lingering Questions

  1. The recursive call to server_file_access (in server_file_access) on line 130 of "server_file.c" still returns 404. Why? As far as I can tell from the code, if auto-indexing is on, the logic that handles ret=404 from the recursive call knows to return "index.html". Since 404 means "Not Found", I suppose this makes sense.

Notes

Success!

doas httpd -v -d
$ doas ([email protected]) password:
startup
no actions, nothing to do
server exiting, pid 77800
logger exiting, pid 14129
$

Time to set up a config file. Using a very basic config file, the server's now listening on port 80 on all ports.

prefork 2 
 
server "default" { 
	listen on * port 80 
} 
 
types { 
	text/css		css 
	text/html		html htm 
	text/plain		txt 
	image/gif		gif 
	image/jpeg		jpeg jpg 
	image/png		png 
	application/javascript	js 
	application/xml		xml 
}

Got a response from the server!

curl 107.191.39.182
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>403 Forbidden</title>
<style type="text/css"><!--
body { background-color: white; color: black; font-family: 'Comic Sans MS', 'Chalkboard SE', 'Comic Neue', sans-serif; }
hr { border: 0; border-bottom: 1px dashed; }

--></style>
</head>
<body>
<h1>403 Forbidden</h1>
<hr>
<address>OpenBSD httpd</address>
</body>
</html>

The server's returning forbidden. Let's dive into the code and try to figure out why.

After much printf-ing, I've determined that the exit method we're calling is server_abort_http in "server_http.c". There are two candidates for who could be calling it. The first is "server_http.c"'s server_response function on line 1166. This seems unlikely because this if-statement includes a check of whether SRVFLAG_BLOCK is true, which I'm assuming corresponds to the block option in "httpd.conf". The second is "server_file.c". This file contains a number of calls to server_abort_http, all of which pass return code as a variable. In addition, I've added a print statement to the end of server_response which prints when server_file gets called. I just noticed that this print-statement get invoked when I make a curl request to the server.

Turns out, I'm error-ing out in server_file_access. AH, so silly, the problem was that httpd will by default return an error if there's no "index.html" file. I added directory auto index to "/etc/httpd.conf" and now I'm getting back an empty "index.html" file.