Closed Dilrevx closed 3 months ago
The \r
carriage-return is causing the line to be erased. The remote server you're communicating with uses \r\n
to signal line ends like windows does instead of \n
. Try specifying the desired newline using context.newline = b'\r\n'
globally or using p.newline = b'\r\n'
for the remote tube only.
The
\r
carriage-return is causing the line to be erased. The remote server you're communicating with uses\r\n
to signal line ends like windows does instead of\n
. Try specifying the desired newline usingcontext.newline = b'\r\n'
globally or usingp.newline = b'\r\n'
for the remote tube only.
Many thx. Setting p.newline=\r\n
fix the problem for interactive
. But now I am confused. What is happening here? I once thought that interactive just recv and print the bytes transmitted through the socket, without modifying the stream, unlike dropend. Is that wrong?
upd: I have checked the recv_thread in interactive. Its implementation replaces all occurrence of newline
with \n
, so
\r
is eliminated. Another fun fact is that the recv timeout is 50ms, which might introduce a break before \r
. This is why part of the output can be shown under debug log level.
Yet another problem remains unfixed. The script I wrote in further information section simply print the \r
string with python built-in function. With pwn
imported, setting context.newline = \r\n
still leaves the output to be empty. And without pwn
the output is correct even \r
is contained in string.
So I am confused:
print
is fine?import pwn
change the behavior of built-in function print
?Which pwntools version are you running? There were changes in the terminal handling in the beta. pwn version
in the console.
pwntools takes over the terminal like curses apps do to allow for fancy spinning loggers and interactive editing features like gnu readline when imported from pwn
. Using features directly from pwnlib
doesn't touch the terminal.
Printing \r
directly causes it to be interpreted by pwntools' terminal which apparently differs from your default one. @Arusekk can tell you more
My version is 4.10.0. Indeed, I didn't notice the terminal change, which tells everything.
Your explanation is useful enough for me, curses is a good example. Thanks :)
Background
I was under
sh.interactive()
mode without setting debug context. I enteredls
command, pressed enter, and the output was empty linebreaks.This is the pwntools script.
This is the pwntools.interactive output
This is the nc output that I expected
environment
Further information
I attach a breakpoint and dump the strings. Below is the returned string for a
ls
.I write a test script as following:
It seems that
print
CAN translate ASNI codes with first line commented, but CANNOT withpwn
imported. Why is this happening and what should I do with it?