Httpd Written In Postscript? Shell?
eMBee writes: "You thought the kernel-httpd is weird?
then look at these: a shell script, and another one in Postscript." Ya know, this kinda stuff gives me faith in humanity. Faith that we've evolved too far: it's time to back-up to, say ... using bone chips as knives ;)
YDD
"To install it, run from inetd:"
/usr/bin/gs gs -dNODISPLAY -q \
/home/pugo/src/postscript/pshttpd/pshttpd.ps
= == % PS-HTTPD V1.0 % = ==== /get_file % read file /infile /buff 2048 string def { % loop infile buff readstring { stdout exch writestring /read_command % read /command { /stdin (%stdin) (r) file def /inbuff 256 string def /command exch def } def /concatstr % (a) (b) -- (ab) { /beta exch def /alfa /buffer 1024 string def alfa buffer copy pop buffer alfa length beta putinterval buffer (\000) /hitcount { /hitfile (/usr/local/psweb/hits) (r) file def /hits 16 /hitfile (/usr/local/psweb/hits) (w+) file def cvi 1 /print_header { stdout (HTTP/1.0 200 /parse_result { command token { (GET) eq { ( ) search { root exch /filename exch def pop pop % define filename and clean stack filename /filename exch def } if % /infile exch (r) file def % open file print_header get_file } if } if } if } def % Init /stdout (%stdout) (w) file def /command () def % Root-path (root of WWW-pages)
8080 stream tcp nowait nobody
Here's the source, in case the server gets PSDotted:
%! %================================================
Copyright 2000 Anders Karlsson, pugo@pugo.org % License: GNU General Public License
%==============================================
and send it to %stdout {
} { stdout exch writestring infile closefile exit } ifelse } bind loop } def
command from stdin and define it to
stdin inbuff readline pop
exch def
search pop exch pop exch pop } def
string def hitfile hits readstring pop hitfile closefile
add hits cvs hitfile exch writestring hitfile closefile } def
OK\n\n) writestring % stdout (Server: PS-HTTPD/1.0\n) writestring % stdout (Content-type:
text/html\n) writestring } def
concatstr % build path
filename length 1 sub 1 getinterval (/) eq { filename (index.html) concatstr
add index.html filename (..) search { stdout (4711 Stupid user error!\n\n) writestring quit } if pop
filename
environment
/root (/usr/local/psweb) def %% Uncomment this and place a file named "/usr/local/psweb/hits" %%
(you can change the path in hitcount above) containing only a "0" to %% get a hitcount % % hitcount
% add one to the hitcount % Read a command from the server read_command parse_result quit
"... it's time to back-up to, say ... using bone chips as knives"
:-)
Funny you should mention that - a lot of very delicate eye-surgery these days is done with glass or obsidian knives because at the small sizes needed they're a lot sharper than steel. The blades are flaked by Aleuts, who've been fashioning such knives for centuries, because they're the only ones who still have the skills to do it (incidentally making some of the most dangerous water-based weaponry in the world).
OK, it's mostly off-topic, but it's still damned cool
Some years ago, somebody set out to implement various things using only dd and sh. Their accomplishments included a text editor, a web server and -- to prove a point -- a Turing machine. The things could be found on the now non-existant http://dd.sh/ (fantastic, eh? :) but are now located on http://www.assurdo.com/dd.sh/. These things warm my heart. *happy sigh*
Few people realise that PostScript is a full programming language, not just a page description language for printers (for the uninitiated, it's similar to Forth -- remember the Jupiter Ace?). I used to have a ray tracing program that someone had written in PostScript (in under 2K as well!). Of course, performance wasn't too great...
"The invisible and the non-existent look very much alike." -- Delos B. McKown
At the asmutils page. 586 bytes standalone executable. Make that!
Best regards,
The Anonymous Coward from Estern Europe
While we're talking about HTTPD's written in various languages, the W3 Consortium has written a free (as in speech) HTTPD entirely in Java for maximal portability: Jigsaw (see also the Jigsaw test site — that is, let's see how Jigsaw reacts to being slashdotted:-).
As you can guess, Jigsaw is fully HTTP/1.1 compliant (last time I checked, Apache still had some problems with that). While it's certainly much less efficient than Apache, it's probably also more flexible, modular and reusable. Personaly I haven't given it more than a cursory glance: I wonder if some people have tried it more thoroughly and would care to review its pros and cons?
Man, trying to secure a httpd written in sh is gonna suck. Just for starters, try:/ ../../../../etc/passwd
http://jester.vip.net.pl:8081/../../../../../..
It also appears you can execute arbitrary commands by changing your reverse DNS to contain the command and '|', ';' and/or '&'.
There is a good reason not to write CGI scripts in shell, and an even better one not to write a whole httpd!
I heard about a company who wrote a graphical interface to a 4 bit operating system and called the whole thing NT Server!
You can't handle the truth.
http://www3.l0pht.com/~dildog/webserver.doc
Note that you can upload files, download them, execute programs, and change file attributes by clicking on them in the directory list. The webserver shuts down when they close the document though, since I didn't bother to try to make the tool any more insidious than it was already.
Have fun.