Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Rarun2's program redirection doesn't work. #3951

Closed
akrasuski1 opened this issue Jan 13, 2016 · 24 comments
Closed

Rarun2's program redirection doesn't work. #3951

akrasuski1 opened this issue Jan 13, 2016 · 24 comments
Labels

Comments

@akrasuski1
Copy link
Contributor

dbg.profile's stdin field seem to work only with files, not with programs. Consider:

$ cat /tmp/prof
#!/usr/bin/rarun2
program=/bin/ls
stdin=!python -c 'print "2"'
$ r2 -d /bin/ls -e dbg.profile=/tmp/prof
Attached debugger to pid = 16782, tid = 16782
Debugging pid = 16782, tid = 16782 now
p/debug_native.c:764 debug_init_maps: /proc: No such file or directory
Using BADDR 0x0
Assuming filepath /bin/ls
bits 64
p/debug_native.c:764 debug_init_maps: /proc: No such file or directory
r_debug_reg: error reading registers
Attached debugger to pid = 16782, tid = 16782
r_debug_reg: error reading registers
r_debug_reg: error reading registers
 -- Experts agree, security holes suck, and we fixed some of them!
r_debug_reg: error reading registers
[0x00000000]> 

There are a couple of errors. On the other hand, if I change /tmp/prof file to use file as input, it works fine:

$ cat /tmp/prof
#!/usr/bin/rarun2
program=/bin/ls
stdin=/tmp/prof
$ r2 -d /bin/ls -e dbg.profile=/tmp/prof
Process with PID 16799 started...
Attached debugger to pid = 16799, tid = 16799
Debugging pid = 16799, tid = 16799 now
Using BADDR 0x400000
Assuming filepath /bin/ls
bits 64
Attached debugger to pid = 16799, tid = 16799
 -- In Soviet Russia, radare2 have documentation.
[0x7efdaf952cd0]>

Note that doing this with just rarun2 works fine in both cases - rarun2 /tmp/prof lists files.

@radare
Copy link
Collaborator

radare commented Jan 13, 2016

program and its arguments must be the last ones in the commandline, try
with:

$ r2 -e dbg.profile=/tmp/prof -d /bin/ls 

also, there are several shorter ways to make that stdin thing for example:

stdin=2

a bit longer:

stdin=!echo 2

i was a bit scared with that python for just an echo :P

On 01/13/2016 06:51 PM, akrasuski1 wrote:

dbg.profile's stdin field seem to work only with files, not with programs. Consider:

$ cat /tmp/prof
#!/usr/bin/rarun2
program=/bin/ls
stdin=!python -c 'print "2"'
$ r2 -d /bin/ls -e dbg.profile=/tmp/prof
Attached debugger to pid = 16782, tid = 16782
Debugging pid = 16782, tid = 16782 now
p/debug_native.c:764 debug_init_maps: /proc: No such file or directory
Using BADDR 0x0
Assuming filepath /bin/ls
bits 64
p/debug_native.c:764 debug_init_maps: /proc: No such file or directory
r_debug_reg: error reading registers
Attached debugger to pid = 16782, tid = 16782
r_debug_reg: error reading registers
r_debug_reg: error reading registers
 -- Experts agree, security holes suck, and we fixed some of them!
r_debug_reg: error reading registers
[0x00000000]> 

There are a couple of errors. On the other hand, if I change /tmp/prof file to use file as input, it works fine:

$ cat /tmp/prof
#!/usr/bin/rarun2
program=/bin/ls
stdin=/tmp/prof
$ r2 -d /bin/ls -e dbg.profile=/tmp/prof
Process with PID 16799 started...
Attached debugger to pid = 16799, tid = 16799
Debugging pid = 16799, tid = 16799 now
Using BADDR 0x400000
Assuming filepath /bin/ls
bits 64
Attached debugger to pid = 16799, tid = 16799
 -- In Soviet Russia, radare2 have documentation.
[0x7efdaf952cd0]>

Reply to this email directly or view it on GitHub:
#3951

@akrasuski1
Copy link
Contributor Author

$ r2 -e dbg.profile=/tmp/prof -d /bin/ls
Attached debugger to pid = 17185, tid = 17185
Debugging pid = 17185, tid = 17185 now
p/debug_native.c:764 debug_init_maps: /proc: No such file or directory
Using BADDR 0x0
Assuming filepath /bin/ls
bits 64
p/debug_native.c:764 debug_init_maps: /proc: No such file or directory
r_debug_reg: error reading registers
Attached debugger to pid = 17185, tid = 17185
r_debug_reg: error reading registers
r_debug_reg: error reading registers
 -- Disassemble in intel syntax with 'e asm.syntax = intel'.
r_debug_reg: error reading registers
[0x00000000]> 

Doesn't seem to work either. Also, the short python program was just an example, normally it would be much longer of course ;)

@radare
Copy link
Collaborator

radare commented Jan 13, 2016

which version of r2 are you using? last one from git?

do r2 -d ls works for you? because it looks like there's not even
/proc in your system? wtf

On 01/13/2016 07:24 PM, akrasuski1 wrote:

$ r2 -e dbg.profile=/tmp/prof -d /bin/ls
Attached debugger to pid = 17185, tid = 17185
Debugging pid = 17185, tid = 17185 now
p/debug_native.c:764 debug_init_maps: /proc: No such file or directory
Using BADDR 0x0
Assuming filepath /bin/ls
bits 64
p/debug_native.c:764 debug_init_maps: /proc: No such file or directory
r_debug_reg: error reading registers
Attached debugger to pid = 17185, tid = 17185
r_debug_reg: error reading registers
r_debug_reg: error reading registers
 -- Disassemble in intel syntax with 'e asm.syntax = intel'.
r_debug_reg: error reading registers
[0x00000000]> 

Doesn't seem to work either. Also, the short python program was just an example, normally it would be much longer of course ;)


Reply to this email directly or view it on GitHub:
#3951 (comment)

@akrasuski1
Copy link
Contributor Author

$ r2 -d ls
Process with PID 17224 started...
Attached debugger to pid = 17224, tid = 17224
Debugging pid = 17224, tid = 17224 now
Using BADDR 0x400000
Assuming filepath /bin/ls
bits 64
Attached debugger to pid = 17224, tid = 17224
 -- Switch between print modes using the 'p' and 'P' keys in visual mode
[0x7fbe7c576cd0]>

I updated r2 just yesterday, I don't believe anythin important changed since then.

@akrasuski1
Copy link
Contributor Author

https://github.com/radare/radare2/blob/40e08dbd89618643309fd2560e9fc19f88668b7c/libr/debug/p/debug_native.c#L764

This is the place which prints the first error - it lies a bit - it's not the /proc that doesn't exist, but the /proc/PID_OF_PROG/maps - which makes me believe that pid is wrong.

@radare
Copy link
Collaborator

radare commented Jan 13, 2016

Confirmed, this is a regression on linux. im looking at it

@radare radare closed this as completed in 9051fed Jan 13, 2016
@akrasuski1
Copy link
Contributor Author

Fix didn't work, same problem persists.

@akrasuski1
Copy link
Contributor Author

Could you reopen the issue?

@crowell crowell reopened this Jan 14, 2016
@radare
Copy link
Collaborator

radare commented Jan 15, 2016

Can anyone reproduce?

@Maijin
Copy link
Contributor

Maijin commented Jan 24, 2016

$ cat /tmp/prof
#!/usr/bin/rarun2
program=/bin/ls
stdin=!echo 2
$ r2 -e dbg.profile=/tmp/prof -d /bin/ls
Attached debugger to pid = 27894, tid = 27894
Debugging pid = 27894, tid = 27894 now
p/debug_native.c:764 Cannot open '/proc/27894/maps': No such file or directory
Using BADDR 0x0
Assuming filepath /bin/ls
bits 64
p/debug_native.c:764 Cannot open '/proc/27894/maps': No such file or directory
r_debug_reg: error reading registers
r_debug_reg: error reading registers
r_debug_reg: error reading registers
 -- You can debug a program from the graph view ('ag') using standard radare2 commands
r_debug_reg: error reading registers
^D
Do you want to quit? (Y/n)
Do you want to kill the process? (Y/n)

@radare
Copy link
Collaborator

radare commented Jan 24, 2016

Echo is not a program

On 24 Jan 2016, at 10:04, Maijin notifications@github.com wrote:

$ cat /tmp/prof
#!/usr/bin/rarun2
program=/bin/ls
stdin=!echo 2
$ r2 -e dbg.profile=/tmp/prof -d /bin/ls
Attached debugger to pid = 27894, tid = 27894
Debugging pid = 27894, tid = 27894 now
p/debug_native.c:764 Cannot open '/proc/27894/maps': No such file or directory
Using BADDR 0x0
Assuming filepath /bin/ls
bits 64
p/debug_native.c:764 Cannot open '/proc/27894/maps': No such file or directory
r_debug_reg: error reading registers
r_debug_reg: error reading registers
r_debug_reg: error reading registers
-- You can debug a program from the graph view ('ag') using standard radare2 commands
r_debug_reg: error reading registers
^D
Do you want to quit? (Y/n)
Do you want to kill the process? (Y/n)

Reply to this email directly or view it on GitHub.

@radare
Copy link
Collaborator

radare commented Jan 24, 2016

Welcome to unix

On 24 Jan 2016, at 10:04, Maijin notifications@github.com wrote:

$ cat /tmp/prof
#!/usr/bin/rarun2
program=/bin/ls
stdin=!echo 2
$ r2 -e dbg.profile=/tmp/prof -d /bin/ls
Attached debugger to pid = 27894, tid = 27894
Debugging pid = 27894, tid = 27894 now
p/debug_native.c:764 Cannot open '/proc/27894/maps': No such file or directory
Using BADDR 0x0
Assuming filepath /bin/ls
bits 64
p/debug_native.c:764 Cannot open '/proc/27894/maps': No such file or directory
r_debug_reg: error reading registers
r_debug_reg: error reading registers
r_debug_reg: error reading registers
-- You can debug a program from the graph view ('ag') using standard radare2 commands
r_debug_reg: error reading registers
^D
Do you want to quit? (Y/n)
Do you want to kill the process? (Y/n)

Reply to this email directly or view it on GitHub.

@Maijin
Copy link
Contributor

Maijin commented Jan 24, 2016

#3951 (comment)

I just followed your instructions....

Same with "2"

$ cat /tmp/prof 
#!/usr/bin/rarun2
program=/bin/ls
stdin=2
$ r2 -e dbg.profile=/tmp/prof -d /bin/ls
[ERROR] rarun2: Cannot open: 2
Can't config the environment.
Attached debugger to pid = 32718, tid = 32718
Debugging pid = 32718, tid = 32718 now
p/debug_native.c:764 Cannot open '/proc/32718/maps': No such file or directory
Using BADDR 0x0
Assuming filepath /bin/ls
bits 64
p/debug_native.c:764 Cannot open '/proc/32718/maps': No such file or directory
r_debug_reg: error reading registers
r_debug_reg: error reading registers
r_debug_reg: error reading registers
 -- Now with more better English!
r_debug_reg: error reading registers
^D
Do you want to quit? (Y/n)
Do you want to kill the process? (Y/n)

Same with the first example

$ cat /tmp/prof
#!/usr/bin/rarun2
program=/bin/ls
stdin=!python -c 'print "2"'
$ r2 -e dbg.profile=/tmp/prof -d /bin/ls
Attached debugger to pid = 394, tid = 394
Debugging pid = 394, tid = 394 now
p/debug_native.c:764 Cannot open '/proc/394/maps': No such file or directory
Using BADDR 0x0
Assuming filepath /bin/ls
bits 64
p/debug_native.c:764 Cannot open '/proc/394/maps': No such file or directory
r_debug_reg: error reading registers
r_debug_reg: error reading registers
r_debug_reg: error reading registers
 -- No such file or directory.
r_debug_reg: error reading registers
^D
Do you want to quit? (Y/n)
Do you want to kill the process? (Y/n)

@Thaelz
Copy link

Thaelz commented Oct 24, 2016

Happy Haloween, the dead thread is coming back! (Sorry for that..)
From what i've experienced, the /proc/pid/maps file error is a consequence of the failed stdin input command.
A workaround to get the result of a command as stdin:
$ cat /tmp/prof
#!/usr/bin/rarun2
program=/bin/ls
stdin=$(python -c 'print "2"')
Or with a python script:
stdin=$(python sample.py)
Then the errors related to the /proc/pid/maps should disappear (and the analysis of sections, entrypoint, etc.. will get expected results) as the stdin argument is correctly interpreted (see edit).

EDIT: Seems it doesn't make things work but just bypass these errors, the stdin is still interactive (and not reading the command output) while debugging..

@Maijin Maijin added the rarun2 label Oct 24, 2016
@radare
Copy link
Collaborator

radare commented Oct 25, 2016

$( is nothing, RTFM

On 24 Oct 2016, at 14:14, Thaelz notifications@github.com wrote:

Happy Haloween, the dead thread is coming back! (Sorry for that..)
From what i've experienced, the /proc/pid/maps file error is a consequence of the failed stdin input command.
A workaround to get the result of a command as stdin:
$ cat /tmp/prof
#!/usr/bin/rarun2
program=/bin/ls
stdin=$(python -c 'print "2"')
Or with a python script:
stdin=$(python sample.py)
Then the errors related to the /proc/pid/maps should disappear (and the analysis of sections, entrypoint, etc.. will get expected results) as the stdin argument is correctly interpreted.


You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub #3951 (comment), or mute the thread https://github.com/notifications/unsubscribe-auth/AA3-lob6zu34ZhHU0VBWLPRk0gOtbu_bks5q3KEjgaJpZM4HENwR.

@Maijin
Copy link
Contributor

Maijin commented Oct 25, 2016

Following your instruction it doesn't work either.

@Maijin
Copy link
Contributor

Maijin commented Oct 25, 2016

instructionS

@Diadlo
Copy link
Contributor

Diadlo commented Jan 20, 2017

I, think, I found the reason of error: https://github.com/radare/radare2/blob/1.1.0/libr/socket/run.c#L247
Here ends the original process (whose PID has been saved) and continue new one

@radare
Copy link
Collaborator

radare commented Jan 20, 2017 via email

@Diadlo
Copy link
Contributor

Diadlo commented Jan 21, 2017

@radare I'm trying to fix the issue, but changing sign s/==/!=/ provide a regression.

@radare
Copy link
Collaborator

radare commented Jan 22, 2017 via email

@Diadlo
Copy link
Contributor

Diadlo commented Jan 22, 2017

@radare I will try

@pragyan1994
Copy link

radare2$: r2 -d ls
Child killed
ptrace: Cannot attach: Invalid argument
Possibly unsigned r2. Please see doc/macos.md
ERRNO: 22 (EINVAL)
[w] Cannot open 'dbg:///bin/ls' for writing.

having this error! How to troubleshoot

@Maijin
Copy link
Contributor

Maijin commented Dec 28, 2017

This is not the same issue, please see doc/macos.md as written.

@radareorg radareorg locked and limited conversation to collaborators Dec 28, 2017
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants