nachtwezen
nachtwezen

Reputation: 123

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.

e.g.

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).

What code would you use to print the payload, knowing that I am working with Java.net Sockets (i.e. 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.

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

Upvotes: 1

Views: 2083

Answers (1)

nachtwezen
nachtwezen

Reputation: 123

SOLVED. what I did wrong was reading a line in stead of reading 37 bytes. as this was a connection keep-alive stream, the stream never closed and thus the 'readline' method kept waiting for ever.

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

Upvotes: 1

Related Questions