zardus / preeny

Some helpful preload libraries for pwning stuff.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The sock program doesn't output “You wrote: ” to standard output in the centos6.9

dongbiao830415 opened this issue · comments

1、 Result
[root@bogon preeny]# LD_PRELOAD=/root/src/preeny/x86_64-redhat-linux/desock.so ./tests/sock
HI!
1234
[root@bogon preeny]#
2、 This piece of code here doesn't seem to be working。
“FILE *zomg = fdopen(s, "w");”“

fflush(zomg); 

Add this line at the end of the file and try again?

I think this might be a bug in the 'tests/sock.c', because the socket file is block buffered by default, and if you use fprintf to write to the socket, the characters are saved up and would not be written to the socket immediately.
The debug output of the original ./sock( only print last few lines).

//...
+++ read 5 bytes from 0 (will write to 503)
+++ wrote 5 bytes to 503 (had read from 0)
+++ shutting down desock...
+++ sending SIGINT to thread 3...
+++ read poll() timed out on fd 503
+++ read poll() timed out on fd 0
+++ ... sent!
+++ read poll() timed out on fd 503
+++ ... shutdown complete!

we can observe that when shutting down desock, there is no data come from fd 503 which proves my hypothesis above.
As to resolve this problem, you can also add a line setlinebuf(zomg) before fprintf.