Trying to interact with a remote console using pwntools

Hi everyone,

I work with Python language from time to time but here’s a issue that I have never met.

Actually Im playing with an remote console that asks me to return every word it gives.

For example :

>>> car # Remote console gives a word
car # I answer
Ok next word ! # Remote console after checking
>>> house # Remote console gives a second word and is waiting for me

I could manually answer each word the console says. But I’d like to make a Python script to automate it.
I’m thinking about a loop that would do this job, that is to say :

  1. get the word from the remote console
  2. send that word back to the remote console

I tried it with the pwntools library by using the recvline() and sendline() commands. I wrote :

import pwn
import re
c = pwn.remote ("URL", port)
question = str(c.recvline())
c.sendline(question)
c.interactive()

By doing this, the console returns :

Ok next word !
>>> house

That’s a start but obviously as there’s no loop, the script can’t send “house” back. To adapt it, I used while and for loops on the recvline command but without results after many tries. And I must admit I’m getting stuck.
Is there a trick to do it and put each try inside the >>> input of the service ?

Any help would be very appreciated.
Thanks !

It may or may not be of help, if we knew what code you’ve tried and what you’re getting as a return from recvline.

My thoughts are that it could be a character encoding issue?

Thanks for your answer.

From recvline, I get :

Ok next word !
>>> the_word_to_repeat

But I only get this one time since I did not make a loop. What I’d like to do at each word is getting that word in recvline and sending back in sendline

Thanks !

Looking at this documentation: Getting Started — pwntools 4.8.0 documentation

… it seems to me that you should be sending bytes not str, as in your code:

question = str(c.recvline())
c.sendline(question)

I don’t ‘know’ as such, as I’ve never tried this, so I’m sorry if this is of no help to you.