Linux, FreeBSD, Juniper, Cisco / Network security articles and troubleshooting guides

FAQ
It is currently Fri Dec 01, 2023 3:44 pm


Tutorials applicable on more than one Unix/Linux OS and shell scripts: ssh / openssl / protocols.

Author Message
debuser
  Post  Post subject: Using echo, netcat(nc) and tr to create an HTTP connection  |  Posted: Thu Mar 04, 2010 5:01 am

Joined: Thu Aug 06, 2009 2:48 am
Posts: 105

Offline
 

Using echo, netcat(nc) and tr to create an HTTP connection

Fortunately for debugging HTTP connections, there is a very simple way of generating one from command line when elinks or lynx are not available.

For this we need the most basic http command and header: GET/POST and Host.

Code:
# echo 'GET / HTTP/1.1 Host: www.mysite.ro'
GET / HTTP/1.1 Host: www.mysite.ro


but the above output is not valid for sending it to a web server. We need some new lines added to it:

Code:
# echo 'GET / HTTP/1.1BHost: www.mysite.roB' | tr "B" "\n"
GET / HTTP/1.1
Host: www.mysite.ro



Now I'll take the above output (where tr replaced the B (uppercase B) with a new line) and inject it into a webserver using netcat (nc):
Code:
# echo 'GET / HTTP/1.1BHost: www.mysite.roBB' | tr "B" "\n" | nc localhost 80
HTTP/1.1 200 OK
Date: Thu, 04 Mar 2010 08:56:15 GMT
Server: Apache/2.2.13 (Unix) DAV/2 mod_ssl/2.2.13 OpenSSL/0.9.8k
Set-Cookie: 0b1edb316356a304958c8070b6cd7673=8c2a000573ba9f66fc2379fbcf4b3fda; path=/
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
Expires: Mon, 1 Jan 2001 00:00:00 GMT
Last-Modified: Thu, 04 Mar 2010 08:56:15 GMT
Cache-Control: post-check=0, pre-check=0
Pragma: no-cache
Connection: close
...rest of the output is ommited...


What appears below my command is the webserver's output to the http GET command and the HOST header.
P.S.: In this case, www.mysite.ro is not hosted and the webserver serves the default vhost.





Top
Display posts from previous:  Sort by  
E-mail friendPrint view

Topics related to - "Using echo, netcat(nc) and tr to create an HTTP connection"
 Topics   Author   Replies   Views   Last post 
There are no new unread posts for this topic. Using curl to get the HTTP response from an HTTP server

debuser

3

5700

Tue Dec 06, 2011 9:05 am

admin View the latest post

 

Who is online
Users browsing this forum: No registered users and 0 guests
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
Jump to:  
News News Site map Site map SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list


Delete all board cookies | The team | All times are UTC - 5 hours [ DST ]



phpBB SEO