Skip to content

Commit

Permalink
Merge pull request #2 from plutonium-dbg/feature/gdb-server-start-sus…
Browse files Browse the repository at this point in the history
…pended

suspend victim at launch
  • Loading branch information
Philipp authored Sep 16, 2018
2 parents 99cbc81 + 5aae052 commit 8a299e0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
6 changes: 6 additions & 0 deletions clients/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.PHONY: all

all: launch

launch: launch.c
$(CC) $(CFLAGS) -o $@ $<
17 changes: 13 additions & 4 deletions clients/gdbserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
import logging
import re
import select
import signal
import socket
import struct
import subprocess
import sys
import time
import os

from binascii import hexlify, unhexlify
from plutonium_dbg import debugger
Expand Down Expand Up @@ -157,8 +160,9 @@ def _query(request):
if request.startswith('Supported'):
return _q_supported(request)
if request.startswith('Attached'):
for t in mod.enumerate_threads(tgid):
mod.suspend_thread(t)
# not necessary when using launcher, since victim is already suspended
# for t in mod.enumerate_threads(tgid):
# mod.suspend_thread(t)
return '1' # to indicate that we attached to a running process
if request == 'C':
return 'QC' + hex(tgid)[2:]
Expand Down Expand Up @@ -393,8 +397,12 @@ def main(program_args):
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(('', port))

# TODO: startup script
tgid = subprocess.Popen(program_args).pid
tgid = subprocess.Popen(["./launch", program_args]).pid
mod.set_event_mask(tgid, mod.EVENT_EXEC)
time.sleep(1) # TODO: get feedback from launch program
os.kill(tgid, signal.SIGUSR1) # signal that we're set up
mod.wait() # wait for exec event
mod.set_event_mask(tgid, mod.EVENT_SUSPEND)

log.info('listening on :%d' % port)
sock.listen(1)
Expand All @@ -413,5 +421,6 @@ def main(program_args):
if len(sys.argv) < 2:
print("Not enough arguments!")
print("Usage: gdbserver.py victim-program")
exit(-1)

main("".join(sys.argv[1:]))
29 changes: 29 additions & 0 deletions clients/launch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#define _GNU_SOURCE
#include <signal.h>
#include <stdio.h>
#include <unistd.h>

sig_atomic_t received_signal = 0;

void handle_sigusr1(int signal)
{
received_signal = (signal == SIGUSR1);
}

int main(int argc, char *argv[], char *envp[])
{
if (argc < 2)
{
fprintf(stderr, "Usage: %s command...\n", argv[0]);
return 1;
}

// Set up signal handler
signal(SIGUSR1, handle_sigusr1);

// Wait for SIGUSR1
while (!received_signal) usleep(50000);

// Launch target
execvpe(argv[1], &argv[1], envp);
}

0 comments on commit 8a299e0

Please sign in to comment.