Wednesday, March 12, 2008

how to setup httpd, CGI script on busybox

1. httpd setup--Hyper Text Transfer Protocol Daemon

Two ways of launching httpd daemon-- with inetd and standalone. To launch httpd in inetd, add a line to the /etc/inetd.conf
http stream tcp nowait root /usr/sbin/httpd httpd -i -h /www

Note: -i switch indicates httpd to be launched by inetd super daemon and -h indicates the http home directory is /www. All the webpages should be under /www. To make http service more secure, we probably should not use root user. Instead we should change root user to apach(or whatever user account). Create the user account apach, here is the line in /etc/passwd
apach:x:48:48:webaccess:/www:/bin/false
and the line in /etc/group
apach:x:48:
and the line in /etc/shadow
apach:x:48:
Change the ownership of /www and /etc/httpd.conf to apach
chown apach:apach /etc/httpd.conf
chown -R apach:apach /www


By default, it will look for /etc/httpd.conf for
setup information Here is a sample httpd.conf

#httpd.conf
A:127.0.0.1
A:172.30. #Allow address from 172.30.0.0/16

D:* # Deny from any other IP connec
tions
/cgi-bin:wli:123456 #require user wli, password on url starting with /cgi-bin

This configuration only allow local host and machines 172.30/16 subnet to have http access. For any script in cgi-bin directory, it requires username wli and password 123456. Password can be encrypted with MD5 hash.

In addition, make sure http is in the /etc/service. It should look like
http 80/tcp # WorldWideWeb H
TTP
http 80/udp # WorldWideWeb HTTP


The above lines open up port 80 for http traffic. That's the default port for http access. We can change toe other port as well if needed.

Create a html test page called index.html and put it in directory /www

When you open up the page(http://172.30.80.24/index.html or simply http://172.30.80.24) f rom any 172.30 subnet machine, it will look like the following

Hello, this is a test page.


2. CGI script setup

CGI script is an executable program. It can be written in any language supported by the server machine. All CGI script will be placed in /www/cgi-bin directory. As configured in httpd.conf. The username and password are required to run the CGI script.

The following is a sample CGI script. Make sure the script has executable permission.

This sample script is a shell script. It will execute env command on server machine and send the result back in html format. Here is the output(http://172.30.80.24/cgi-bin/test).

GATEWAY_INTERFACE=CGI/1.1
REMOTE_USER=wli
USER=root
REMOTE_ADDR=172.30.80.21
QUERY_STRING=
HOME=/
AUTH_TYPE=Basic
HTTP_USER_AGENT=Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12
SCRIPT_FILENAME=/www/cgi-bin/test.cgi
REQUEST_URI=/cgi-bin/test.cgi
inetd_dummy=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
SERVER_SOFTWARE=busybox httpd/1.9.1
TERM=vt102
PATH=/sbin:/usr/sbin:/bin:/usr/bin
SERVER_PROTOCOL=HTTP/1.0
PATH_INFO=
SHELL=/bin/sh
REQUEST_METHOD=GET
PWD=/www/cgi-bin
SCRIPT_NAME=/cgi-bin/test.cgi







3 comments:

Unknown said...

Seems need additional setup to get the CGI running. My browser (IE7) dumped the CGI source script on the display. It means the CGI script did get executed. Any suggestions?

darknessB said...

I want the password of this wep

Unknown said...

5566778800