Author Topic: [C] catch stderr of a process  (Read 1610 times)

0 Members and 3 Guests are viewing this topic.

Offline flowjob

  • Knight
  • **
  • Posts: 327
  • Cookies: 46
  • Pastafarian
    • View Profile
[C] catch stderr of a process
« on: May 21, 2012, 08:55:01 pm »
Ok,I'm quite new to C,and for fun and training I want to make something that catches stderr and prints it to the screen,but I don't know how I can attach to a process to be able to read it's stdin/stderr...

So my question is,how can I attach to a process and read its stderr in C?
Quote
<phil> I'm gonna DDOS the washing machine with clothes packets.
<deviant_sheep> dont use too much soap or youll cause a bubble overflow

Offline ca0s

  • VIP
  • Sir
  • *
  • Posts: 432
  • Cookies: 53
    • View Profile
    • ka0labs #
Re: [C] catch stderr of a process
« Reply #1 on: May 21, 2012, 08:56:51 pm »
Look for pipes.
I have not read it all, but I suppose you could do it like this
http://jineshkj.wordpress.com/2006/12/22/how-to-capture-stdin-stdout-and-stderr-of-child-program/
« Last Edit: May 21, 2012, 08:59:09 pm by ca0s »

Offline flowjob

  • Knight
  • **
  • Posts: 327
  • Cookies: 46
  • Pastafarian
    • View Profile
Re: [C] catch stderr of a process
« Reply #2 on: May 21, 2012, 09:08:56 pm »
It's quite helpful about the howto in general :) ,but doesn't really solves my problem,because...

1. I only want to catch stderr
2. I want to attach to a existing process instead of creating a new one...
« Last Edit: May 21, 2012, 09:28:10 pm by Area_13 »
Quote
<phil> I'm gonna DDOS the washing machine with clothes packets.
<deviant_sheep> dont use too much soap or youll cause a bubble overflow

Offline ca0s

  • VIP
  • Sir
  • *
  • Posts: 432
  • Cookies: 53
    • View Profile
    • ka0labs #
Re: [C] catch stderr of a process
« Reply #3 on: May 21, 2012, 09:25:03 pm »
Attaching is more complicated. Look for ptrace. Try to hook write() syscalls which have '2' as file descriptor.
http://www.linuxjournal.com/article/6100
You could also code a dynamic library and override write calls, using the LD_PRELOAD env. variable.
http://scaryreasoner.wordpress.com/2007/11/17/using-ld_preload-libraries-and-glibc-backtrace-function-for-debugging/
« Last Edit: May 21, 2012, 09:27:49 pm by ca0s »

Offline flowjob

  • Knight
  • **
  • Posts: 327
  • Cookies: 46
  • Pastafarian
    • View Profile
Re: [C] catch stderr of a process
« Reply #4 on: May 22, 2012, 07:04:25 pm »
So I've to do something like debugging the process I want to attach to?
« Last Edit: May 22, 2012, 07:11:34 pm by Area_13 »
Quote
<phil> I'm gonna DDOS the washing machine with clothes packets.
<deviant_sheep> dont use too much soap or youll cause a bubble overflow