pwntools icon indicating copy to clipboard operation
pwntools copied to clipboard

catch signals on server()

Open notdodo opened this issue 6 years ago • 3 comments

pwntools verion

3.12.2

basic example

from pwn import server, remote, log, context
import signal
import sys
import time

context.log_level = 'error'

def receiveSignal(signalNumber, frame):  
    log.info('Received:', signalNumber)
    sys.exit(1)
    return


def te(r):
    while True:
        r.sendline("ping")
        log.info(r.recvline())
        time.sleep(1)


if __name__ == "__main__":
    signal.signal(signal.SIGINT, receiveSignal)
    s = server(port=8080, callback=te)
    s.next_connection()

CTRL+C is not catched, thus no prints or no program exit

notdodo avatar Mar 06 '19 16:03 notdodo

I’m on vacation / mobile so I can’t check, but I believe this is due to use of “pwn” instead of “pwnlib”. We do some stuff to exception handling IIRC.

Try “from pwnlib.tubes.server import server” and so on. I’ll check more when I return.

On Wed, Mar 6, 2019 at 11:18 AM Edoardo Rosa [email protected] wrote:

pwntools verion

3.12.2 basic example

from pwn import server, remote, log, contextfrom base64 import b64decodeimport signalimport sysimport time

context.log_level = 'error' def receiveSignal(signalNumber, frame): log.info('Received:', signalNumber) sys.exit(1) return

def te(r): while True: r.sendline("ping") log.info(r.recvline()) time.sleep(1)

if name == "main": signal.signal(signal.SIGINT, receiveSignal) s = server(port=8080, callback=te) s.next_connection()

CTRL+C is not catched, thus no prints or no program exit

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Gallopsled/pwntools/issues/1281, or mute the thread https://github.com/notifications/unsubscribe-auth/AAG0GER9Nu_9QSCcuM-0vYwmh2PbJ8iiks5vT-pAgaJpZM4bhRaK .

--

Zach Riggle

zachriggle avatar Mar 07 '19 12:03 zachriggle

Thank you for the response while in vacation :D and sorry for the trouble.

Same result with:

from pwnlib.tubes.server import server
from pwn import log
import sys


def te(r):
    r.sendline("ping")
    log.info(r.recvline())


if __name__ == "__main__":
    try:
        s = server(port=8080, callback=te)
        s.next_connection()
    except KeyboardInterrupt:
        sys.exit(1)

notdodo avatar Mar 07 '19 21:03 notdodo

This might be connected to the server spawning threads. Try using a different signal (say SIGUSR1), and sending that different signal to the process (if exploit PID is 31337, kill -USR1 31337).

Arusekk avatar Nov 03 '20 23:11 Arusekk