简体   繁体   English

如何在Java中使用套接字打印/获取传入的HTTP POST请求的有效负载(带有套接字)

[英]How to print/get payload of incoming HTTP POST request in Java (with Sockets)

for a course on secure software, I've created a small man-in-the-middle proxy. 对于安全软件课程,我创建了一个小型的中间人代理。 I've come to the point where I intercept the crucial message. 我已经到了拦截关键信息的地步。 This message is an HTTP POST request and the flag to capture is in the payload. 此消息是HTTP POST请求,要捕获的标志在有效负载中。

eg 例如

POST http://someurl.com/index.php HTTP/1.1
Origin: null
User-Agent: Mozilla/5.0 (Unknown; Linux i686) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.7 Safari/534.34
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Content-Length: 37
Content-Type: application/x-www-form-urlencoded
Connection: Keep-Alive
Accept-Encoding: gzip
Accept-Language: en-US, *
Host: someurl.com

So the payload, a 37 byte flag, is obviously there, but when I print it, nothing comes out (as you see). 因此,有效载荷(一个37字节的标志)显然在那里,但是当我打印它时,什么也没有出现(如您所见)。

What code would you use to print the payload, knowing that I am working with Java.net Sockets (ie there is an inputstream available do to whatever with.) At the moment I attached a BufferedReader which prints all lines, but when I keep on printing anything coming from the stream, even null, I still don't get any output. 在知道我正在使用Java.net套接字的情况下,您将使用什么代码来打印有效负载(即,可以对任何内容执行输入流操作。)此刻,我附加了一个BufferedReader,它可以打印所有行,但是当我继续时打印任何来自流的内容,甚至为null,我仍然没有任何输出。

I've searched for a while but couldn't find anything useful. 我搜索了一段时间,但找不到任何有用的东西。 There is probably a very easy solution which I can't seem to come up with. 可能有一个非常简单的解决方案,我似乎无法提出。

Thanks 谢谢

SOLVED. 解决了。 what I did wrong was reading a line in stead of reading 37 bytes. 我做错的是读取一行而不是读取37个字节。 as this was a connection keep-alive stream, the stream never closed and thus the 'readline' method kept waiting for ever. 由于这是一个连接保持活动的流,因此该流从未关闭,因此“ readline”方法一直在等待。

as discussed in https://community.oracle.com/thread/1691291 https://community.oracle.com/thread/1691291中所述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM