Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm running an Apache Tomcat server. Making some security testing I'd noticed than my server is returning a 200 HTTP status code of the default error page when I try to access to a non-existent element instead of return a 404 status code and redirect me to the default error page. I suspect that this is not the only fail with this issue.

Anyone can suggest me a process to check the most common HTTP status codes?

share|improve this question

1 Answer 1

I would use a Bash script that invokes netcat once for each response type, with appropriate input to generate each different kind of response code. I would pipe this though grep to check for the correct response and echo out a message on STDERR if it's not correct.

This should be relatively easy for the 2xx, 3xx and 4xx ranges assuming there exist URLs on your server that actually generate each different response code. The 5xx ranges refer to server-side errors, so to deliberately invoke them you will need to set up specific URLs on your server that cause each error. The 1xx range are probably best tested using a more complete HTTP client such as curl or wget.

There is most likely more than one way to solve this problem.


There's a nasty bug in some version of netcat that means that it exits as soon as it has finished reading from STDIN. Also, the man pages shipped with this buggy version include an example that doesn't work. The workaround is the -q <number> option which specifies a number of seconds to hang around waiting for an answer before quitting.

echo -ne "GET / HTTP/1.1\nHost: example.com\n\n" | nc -q 1 example.com 80 | grep -q "HTTP/1.1 301" || echo "HTTP 302 test failed!" >&2
share|improve this answer
    
Thanks for your help. I'd been reading the 'man netcat' page, but I can not figure how to force the server to return the codes. What I'm not understanding? –  amusero Mar 29 '12 at 14:21
    
I added an example to my answer that avoids the bug I suspect you are running into. –  Ladadadada Mar 29 '12 at 15:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.