1

I'm doing exercise net0 on https://exploit-exercises.com/protostar/. The content of the exercise is to send requested number as a little endian 32bit int to the server. I came up with the following command lines.

mkfifo /tmp/pipe  
cat /tmp/pipe | netcat 127.0.0.1 2999 |tee -a /tmp/log | cut -d ' ' -f 3 | xargs -I{} python -c "import struct; print struct.pack('I',int({}))" > /tmp/pipe

The second command line doesn't finish, and I found cat /tmp/pipe blocking on read (not on open) when use strace to debug.

dcnh35
  • 354
  • 2
  • 13
  • Have you written something to the pipe? – a.l. Apr 16 '18 at 02:22
  • @aLeX yes, the /tmp/log is not empty – dcnh35 Apr 16 '18 at 02:31
  • @aLeX and test comamnd line `echo "Please send '220419784' as a little endian 32bit int" | cut -d ' ' -f 3 | xargs -I{} python -c "import struct; print struct.pack('I',int({}))" ` outputs the right answer. – dcnh35 Apr 16 '18 at 02:37

1 Answers1

1

I found the reason. when the output is not terminal, cut will buffer the output. python print also needs to be flushed. https://unix.stackexchange.com/a/226675/194577

dcnh35
  • 354
  • 2
  • 13