Gallopsled / pwntools

CTF framework and exploit development library
http://pwntools.com
Other
11.96k stars 1.7k forks source link

catch signals on server() #1281

Open notdodo opened 5 years ago

notdodo commented 5 years ago

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

zachriggle commented 5 years ago

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 notifications@github.com 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

notdodo commented 5 years ago

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)
Arusekk commented 3 years ago

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).