发送与netcat的POST请求 [英] Send POST request with netcat

查看:250
本文介绍了发送与netcat的POST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现在PHP这个小脚本,发送一个简单的请求,Twitter的更新您的状态,我已经试过这样:<一href=\"http://pratham.name/twitter-php-script-without-curl.html\">http://pratham.name/twitter-php-script-without-curl.html,它工作。现在,我想送与netcat的这个请求,但是这并不能工作,为什么?

我发送这样的请求:

 回声-e $头| NC twitter.com 80

$的头是我的头,我也有尝试过PHP,所以它是正确的。

任何人都知道我怎么能这样?感谢所有。

修改

 头=POST http://twitter.com/statuses/update.json HTTP / 1.1 \\ r \\ n
主持人:twitter.com \\ r \\ n
授权:基本MYNAME:passwordinbs64 \\ r \\ n
内容类型:应用程序/ x-WWW的形式urlen codeD \\ r \\ n
内容长度:10 \\ r \\ n
连接:关闭\\ r \\ n \\ r \\ n
状态= mymessage;回声-e $头| NC twitter.com 80


解决方案

您发送的数据是不正确的。下面是我执行命令:

  $头=POST http://twitter.com/statuses/update.json HTTP / 1.1 \\ r \\ n
主持人:twitter.com \\ r \\ n
授权:基本MYNAME:passwordinbs64 \\ r \\ n
内容类型:应用程序/ x-WWW的形式urlen codeD \\ r \\ n
内容长度:10 \\ r \\ n
连接:关闭\\ r \\ n \\ r \\ n
状态= mymessage;回声$头|数控twitter.com 80HTTP / 1.1 400错误的请求
日期:星期二,2010 GMT 10点19分38秒06月29日
服务器:Apache
有所不同:接受编码
内容长度:226
连接:关闭
内容类型:text / html的;字符集= ISO-8859-1&LT;!DOCTYPE HTML PUBLIC - // IETF // DTD HTML 2.0 // ENGT&;
&LT; HTML和GT;&LT; HEAD&GT;
&LT;标题&GT; 400错误的请求和LT; /标题&GT;
&LT; /头&GT;&LT;身体GT;
&LT; H1&GT;错误的请求和LT; / H1&GT;
&LT; P&GT;您的浏览器发送的请求该服务器无法理解&LT; BR /&GT;
&所述; / P&GT;
&LT; /身体GT;&LT; / HTML&GT;

我并行运行一个tcpdump和这里是它显示我:

  0×0020:5018 FFFF 671f 0000 504F 5354 2068 7474 P ... ...摹POST.htt
0x0030:703A 2f2f 7477 6974 7465 722e 636f 6d2f号码://twitter.com/
×0040:7374 6174 7573 6573 2f75 7064 6174 652e状态/更新。
0x0050:6a73 6f6e 2048 5454 502F器312e 310D 0a20 json.HTTP / 1.1 ...
0x0060:486f 7374 3A20 7477 6974 7465 722e 636f主持人:.twitter.co
0x0070:6d0d 0a20 4175 7468 6f72 697a 6174 696f米... Authorizatio
0x0080:6e3a 2042 6173 6963 206D 796e 616D 653a N:.Basic.myname:
0x0090:7061 7373 776f 7264 696e 6273 3634 0D0A passwordinbs64 ..
0x00a0:2043 6f6e 7465 6e74 2d74 7970 653a 2061 .Content型:.A
0x00b0:7070 6c69 6361 7469 6f6e 2f78 2d77 7777 pplication / X-WWW
0x00c0:2D66 6f72 6d2d 7572 6c65 6e63 6f64 6564构型,urlen codeD
0x00d0:0D0A 2043 6f6e 7465 6e74 2d6c 656e 6774 ...内容lengt
0x00e0:683a 2031 300D 0a20 436f 6e6e 6563 7469 H:0.10 ... Connecti
0x00f0:6f6e 3A20 436C 6f73 650D 0a0d 0a20 7374上:.Close ST .....
0100:6174 7573 3d6d 796d 6573 7361 6765 0A的ATU = mymessage。

你看到的错误?在每一个换行符都三个字符,但应该只有两个。这是因为你在成为壳的空间的变量定义一个真正的换行符。例如。

  $头=行1
2号线;回声$头一号线2号线

尝试写它在一个行,而不是

  $头=POST http://twitter.com/statuses/update.json HTTP / 1.1 \\ r \\ n主机:twitter.com \\ r \\ nAuthorization:基本MYNAME:passwordinbs64 \\ r \\ nContent类型:应用程序/ x-WWW的形式urlen codeD \\ r \\ nContent长度:10 \\ r \\ nConnection:关闭\\ r \\ n \\ r \\ n状态= mymessage;回声$头| NC twitter.com 80HTTP / 1.1 401未经授权
日期:星期二,2010 GMT 10时25分43秒06月29日
服务器:喜
状态:未经授权401
的X运行时间:0.00577
内容类型:应用程序/ JSON的;字符集= UTF-8
内容长度:63
缓存控制:无缓存,最大年龄= 300
设置Cookie:K = 194.145.236.196.1277807143945525;路径= /;到期=周二,06 10年7月10点25分43秒格林尼治标准​​时间;域= .twitter.com
设置Cookie:guest_id = 1277807143950191;路径= /;过期=星期四,2010年7月29日10点25分43秒GMT
设置Cookie: _twitter_sess=BAh7CDoPY3JlYXRlZF9hdGwrCBOsPYMpAToHaWQiJWQzZDkxNTg2MTY3OTFk%250AMzg5OTUyNWFhZGZlZDY0YjJmIgpmbGFzaElDOidBY3Rpb25Db250cm9sbGVy%250AOjpGbGFzaDo6Rmxhc2hIYXNoewAGOgpAdXNlZHsA--e95d14c755b85ff19606a0bc907c8b7a63d1b508;域= .twitter.com; PATH = /
到期日:星期二,2010 10:30:43 GMT 6月29日
有所不同:接受编码
连接:关闭{错误:[{code:32,消息:无法验证您的身份}]}

I have found this little script in PHP that send a simple request to twitter for update your status, I have tried this: http://pratham.name/twitter-php-script-without-curl.html, and it work. Now, I want send this request with netcat, but this doesn't work, why?

I send request in this way:

echo -e $head | nc twitter.com 80

The $head are my header that I have tried with also PHP, so it are right.

Anyone know how I can make this? Thanks to all.

edit.

head="POST http://twitter.com/statuses/update.json HTTP/1.1\r\n
Host: twitter.com\r\n
Authorization: Basic myname:passwordinbs64\r\n
Content-type: application/x-www-form-urlencoded\r\n
Content-length: 10\r\n
Connection: Close\r\n\r\n
status=mymessage";

echo -e $head | nc twitter.com 80

解决方案

The data you send is not correct. Here's the command I'm executing:

$ head="POST http://twitter.com/statuses/update.json HTTP/1.1\r\n
Host: twitter.com\r\n
Authorization: Basic myname:passwordinbs64\r\n
Content-type: application/x-www-form-urlencoded\r\n
Content-length: 10\r\n
Connection: Close\r\n\r\n
status=mymessage"; echo $head  | nc twitter.com 80

HTTP/1.1 400 Bad Request
Date: Tue, 29 Jun 2010 10:19:38 GMT
Server: Apache
Vary: Accept-Encoding
Content-Length: 226
Connection: close
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
</body></html>

I'm running a tcpdump in parallel and here is what it shows me:

0x0020:  5018 ffff 671f 0000 504f 5354 2068 7474  P...g...POST.htt
0x0030:  703a 2f2f 7477 6974 7465 722e 636f 6d2f  p://twitter.com/
0x0040:  7374 6174 7573 6573 2f75 7064 6174 652e  statuses/update.
0x0050:  6a73 6f6e 2048 5454 502f 312e 310d 0a20  json.HTTP/1.1...
0x0060:  486f 7374 3a20 7477 6974 7465 722e 636f  Host:.twitter.co
0x0070:  6d0d 0a20 4175 7468 6f72 697a 6174 696f  m...Authorizatio
0x0080:  6e3a 2042 6173 6963 206d 796e 616d 653a  n:.Basic.myname:
0x0090:  7061 7373 776f 7264 696e 6273 3634 0d0a  passwordinbs64..
0x00a0:  2043 6f6e 7465 6e74 2d74 7970 653a 2061  .Content-type:.a
0x00b0:  7070 6c69 6361 7469 6f6e 2f78 2d77 7777  pplication/x-www
0x00c0:  2d66 6f72 6d2d 7572 6c65 6e63 6f64 6564  -form-urlencoded
0x00d0:  0d0a 2043 6f6e 7465 6e74 2d6c 656e 6774  ...Content-lengt
0x00e0:  683a 2031 300d 0a20 436f 6e6e 6563 7469  h:.10...Connecti
0x00f0:  6f6e 3a20 436c 6f73 650d 0a0d 0a20 7374  on:.Close.....st
0x0100:  6174 7573 3d6d 796d 6573 7361 6765 0a    atus=mymessage.

Do you see the mistake? At each line break are three characters, but there should be only two. This happens because you have a real line break in your variable definition that becomes a space in the shell. E.g.

$ head="line1
line2" ; echo $head

line1 line2

Try writing it all in one line instead.

$ head="POST http://twitter.com/statuses/update.json HTTP/1.1\r\nHost: twitter.com\r\nAuthorization: Basic myname:passwordinbs64\r\nContent-type: application/x-www-form-urlencoded\r\nContent-length: 10\r\nConnection: Close\r\n\r\nstatus=mymessage" ; echo $head | nc twitter.com 80

HTTP/1.1 401 Unauthorized
Date: Tue, 29 Jun 2010 10:25:43 GMT
Server: hi
Status: 401 Unauthorized
X-Runtime: 0.00577
Content-Type: application/json; charset=utf-8
Content-Length: 63
Cache-Control: no-cache, max-age=300
Set-Cookie: k=194.145.236.196.1277807143945525; path=/; expires=Tue, 06-Jul-10 10:25:43 GMT; domain=.twitter.com
Set-Cookie: guest_id=1277807143950191; path=/; expires=Thu, 29 Jul 2010 10:25:43 GMT
Set-Cookie: _twitter_sess=BAh7CDoPY3JlYXRlZF9hdGwrCBOsPYMpAToHaWQiJWQzZDkxNTg2MTY3OTFk%250AMzg5OTUyNWFhZGZlZDY0YjJmIgpmbGFzaElDOidBY3Rpb25Db250cm9sbGVy%250AOjpGbGFzaDo6Rmxhc2hIYXNoewAGOgpAdXNlZHsA--e95d14c755b85ff19606a0bc907c8b7a63d1b508; domain=.twitter.com; path=/
Expires: Tue, 29 Jun 2010 10:30:43 GMT
Vary: Accept-Encoding
Connection: close

{"errors":[{"code":32,"message":"Could not authenticate you"}]}

这篇关于发送与netcat的POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆