Now that we know that netcat can be used just like a utility like telnet, let's also show you a couple of ways to have netcat act like a web browser:
The first one is simply acting as a basic web browser and getting the default page of any Web server:
echo -e "GET / HTTP/1.0\n\n" | nc www.google.com 80
However what I like best is when using netcat with a here document.
That allows us to use a lot of different text and not worry about any of the formatting as far as quotations are concerned, and allow us to create a script easily:
nc -w 30 -q 5 URL 80 << EOF
GET /$PAGE HTTP/1.1
Host: HOST
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://HOST/
EOF
What this command will do is take all the text after the beginning EOF to the ending EOF and redirect it back as input to the command nc. This is instead of using "echo" to issue commands to netcat as in the first example.
Notice the difference that in the second example we'd literally have two new lines so that we are telling netcat to send that across the network to complete the HTTP transaction, where in the first example we've simply enabled interpretation of backslash escapes with the (-e) option to echo to do so w/the two \n's.
This can also be handy to use in a for loop as well to get lots of pages attended.
Note that we could also take the output of this command and redirect it into a file to be saved later by modifying the first line of the command like this:
nc -w 30 -q 5 somehost.com 80 <
More Info:
tldp.org/LDP/abs/html/here-docs.html



0 comments:
Post a Comment