博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Making HTTP requests via telnet - Tony's Place
阅读量:6087 次
发布时间:2019-06-20

本文共 3480 字,大约阅读时间需要 11 分钟。

Simple telnet HTTP requests

Using Telnet is a great way to learn about HTTP requests.

For example.. back in the 90s microsoft was running their sites on apache. Nowadays they are eating their own dog food.  ;-)

Here is a simple HEAD request to microsoft.com via telnet.

$ telnet microsoft.com 80Trying 207.46.232.182...Connected to microsoft.com.Escape character is '^]'.HEAD / HTTP/1.0HTTP/1.1 301 Moved PermanentlyConnection: closeDate: Thu, 12 Jul 2007 15:25:37 GMTServer: Microsoft-IIS/6.0X-Powered-By: ASP.NETLocation: http://www.microsoft.comContent-Length: 31Content-Type: text/htmlSet-Cookie: ASPSESSIONIDSCAQCSBR=FMPJMMPAMGNBFELIPABIHHMN; path=/Cache-control: privateConnection closed by foreign host.

The command above was simple. HEAD / HTTP/1.0 followed by 2 line feeds.

The 80 specified in the telnet command is the port that you are hitting when you type in a browser. If another port is used you will see it after a colon. ex: hits the server running on port 8080. If there was one. :-)

When doing GET commands you usually end up sending headers with your command. You should always send the Host header (this isn’t required for HTTP/1.0 but many servers are running multiple sites so you’ll want to send this.)

Here’s an example of a GET against my home page.

$ telnet tonycode.com 80Trying 208.97.136.171...Connected to tonycode.com.Escape character is '^]'.GET / HTTP/1.1Host: tonycode.comHTTP/1.1 200 OKDate: Thu, 12 Jul 2007 16:10:02 GMTServer: Apache/1.3.37 (Unix) mod_throttle/3.1.2 DAV/1.0.3 mod_fastcgi/2.4.2 mod_gzip/1.3.26.1a PHP/4.4.7 mod_ssl/2.8.22 OpenSSL/0.9.7eMS-Author-Via: DAVLast-Modified: Wed, 11 Jul 2007 14:10:28 GMTETag: "19cf7aa-68d-4694e4d4"Accept-Ranges: bytesContent-Length: 1677Content-Type: text/html

I spared you the full contents of my home page. Why did it return the entire page? Because we did a GET instead of HEAD.

Remembering all the headers you need can get tricky so I usually use [ to get what I need and then I can make modifications for testing or scripting purposes.

 

Scripting telnet HTTP requests

I recently needed to hit several production servers that lived behind a VIP. I had access to the servers directly but their behavior was controlled by the host that they were called with so if I used the machine name I was out of luck. Also, port numbers in the request would throw it off. So I needed to send http requests directly to the server and lie about the hostname I was using to access them.

Here is a script file that I run and pipe into telnet.

echo "open $1 $2"sleep 2echo "GET $4 HTTP/1.0"echo "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4"echo "Host: $3"echoechosleep 2

lets put this in a file called getpage and then we run the following

./getpage tonycode.com 80 tonycode.com /| telnet

ok. what did we just do?

  • getpage is sending commands on stdout and telnet is getting them via the pipe
    • getpage 1st tells telnet to open a connection to tonycode.com ($1) port 80 ($2).
    • getpage waits 2 seconds for the connection. Adjust as necessary.
    • getpage sends the request. GET / HTTP/1.0 and sets the host ($3) to tonycode.com.
      • Note $4 is the resource to fetch and we set it to /.
      • I even threw in the user agent header for fun.
      • Those 2 empty echo statements are necessary to tell the server this is the end of the request.
    • Finally getpage sleeps for 2 seconds to allow time for the response to come back. Leave out this line and you’ll get nada.

转载地址:http://fsvwa.baihongyu.com/

你可能感兴趣的文章
开源磁盘加密软件VeraCrypt教程
查看>>
本地vs云:大数据厮杀的最终幸存者会是谁?
查看>>
阿里云公共镜像、自定义镜像、共享镜像和镜像市场的区别 ...
查看>>
shadowtunnel v1.7 发布:新增上级负载均衡支持独立密码
查看>>
Java线程:什么是线程
查看>>
mysql5.7 创建一个超级管理员
查看>>
【框架整合】Maven-SpringMVC3.X+Spring3.X+MyBatis3-日志、JSON解析、表关联查询等均已配置好...
查看>>
要想成为高级Java程序员需要具备哪些知识呢?
查看>>
带着问题去学习--Nginx配置解析(一)
查看>>
onix-文件系统
查看>>
java.io.Serializable浅析
查看>>
我的友情链接
查看>>
多线程之线程池任务管理通用模板
查看>>
CSS3让长单词与URL地址自动换行——word-wrap属性
查看>>
CodeForces 580B Kefa and Company
查看>>
开发规范浅谈
查看>>
Spark Streaming揭秘 Day29 深入理解Spark2.x中的Structured Streaming
查看>>
鼠标增强软件StrokeIt使用方法
查看>>
本地连接linux虚拟机的方法
查看>>
某公司面试java试题之【二】,看看吧,说不定就是你将要做的题
查看>>