radareorg / radare2

UNIX-like reverse engineering framework and command-line toolset
https://www.radare.org/
GNU Lesser General Public License v3.0
20.73k stars 3.01k forks source link

Output error on #! not handled #8208

Closed bannsec closed 7 years ago

bannsec commented 7 years ago

Just took me a while to realize I didn't have a proper language installed for r2. The example is this command:

#!python test.py

This silently fails. It would be helpful to have this output an error message instead, to the effect of the handler isn't there.

radare commented 7 years ago

It is handled already even if u dont have the api bindings or the lang plugin installed. Use #! To list all the handlers installed

On 14 Aug 2017, at 05:05, Owlz notifications@github.com wrote:

Just took me a while to realize I didn't have a proper language installed for r2. The example is this command:

!python test.py

This silently fails. It would be helpful to have this output an error message instead, to the effect of the handler isn't there.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

bannsec commented 7 years ago

So the problem is, in the above example there is no error. There is simply no output. There should be an indication that the handler mentioned is not installed in my opinion. The lack of error warning caused me to look elsewhere for a problem until i finally realized that the handler was not installed.

radare commented 7 years ago

why do you need an error? #!python works without any plugin installed, because it setups r2pipe, its an alias for #!pipe python …and that’s the reason why r2 -i foo.py works

you dont need an error for something that is not broken

On 14 Aug 2017, at 17:29, Owlz notifications@github.com wrote:

So the problem is, in the above example there is no error. There is simply no output. There should be an indication that the handler mentioned is not installed in my opinion. The lack of error warning caused me to look elsewhere for a problem until i finally realized that the handler was not installed.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/radare/radare2/issues/8208#issuecomment-322222610, or mute the thread https://github.com/notifications/unsubscribe-auth/AA3-ln4zbuWeXfQM9EbzjMcneNvwPZpDks5sYGfjgaJpZM4O15dB.

bannsec commented 7 years ago

Using the docker environment, "#!python" did nothing for me until I also r2pm install lang-python2.

radare commented 7 years ago

do you have python installed in this machine?

On 14 Aug 2017, at 18:56, Owlz notifications@github.com wrote:

Using the docker environment, "#!python" did nothing for me until I also r2pm install lang-python2.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/radare/radare2/issues/8208#issuecomment-322245987, or mute the thread https://github.com/notifications/unsubscribe-auth/AA3-lh2gVjXga323Yhsor9REeGfnNezYks5sYHxXgaJpZM4O15dB.

radare commented 7 years ago

whats the output of #!pipe python ?

On 14 Aug 2017, at 18:56, Owlz notifications@github.com wrote:

Using the docker environment, "#!python" did nothing for me until I also r2pm install lang-python2.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/radare/radare2/issues/8208#issuecomment-322245987, or mute the thread https://github.com/notifications/unsubscribe-auth/AA3-lh2gVjXga323Yhsor9REeGfnNezYks5sYHxXgaJpZM4O15dB.

bannsec commented 7 years ago

Definitely have python installed.

[0x080483f0]> #!pipe python
Python 2.7.9 (default, Jun 29 2016, 13:08:31) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
[0x080483f0]> #!python
Invalid hashbang. See '#!' for help.
[0x080483f0]> #!python -c "test"
[0x080483f0]> 
radare commented 7 years ago

so.. i still dont get whats the problem

[0x00000000]> #!python Invalid hashbang. See '#!' for help. [0x00000000]> #! c: (LGPL) C language extension cpipe: (LGPL) C r2pipe scripting vala: (LGPL) Vala language extension rust: (MIT) Rust language extension pipe: (LGPL) Use #!pipe node script.js lib: (LGPL) Load libs directly into r2

the lang plugin is not installed and python reports invalid hashbang to run that, so the only unexpected thing is that #!python is fallbacking to #!pipe python when an argument is passed?

On 14 Aug 2017, at 19:14, Owlz notifications@github.com wrote:

Definitely have python installed.

[0x080483f0]> #!pipe python Python 2.7.9 (default, Jun 29 2016, 13:08:31) [GCC 4.9.2] on linux2 Type "help", "copyright", "credits" or "license" for more information.

[0x080483f0]> #!python Invalid hashbang. See '#!' for help. [0x080483f0]> #!python -c "test" [0x080483f0]> — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/radare/radare2/issues/8208#issuecomment-322250608, or mute the thread https://github.com/notifications/unsubscribe-auth/AA3-lgIdrlkmdXyOYBwWxCJ16tdo1cMlks5sYIB-gaJpZM4O15dB.

bannsec commented 7 years ago

Well, in my case, it appears it is not falling back to piping to python. This basically stemmed from attempting to use pimp with the python language

! Not installed. There were no errors when In fact python was not called

at all. It wasn't called directly and it wasn't called via pipe. Instead, it appeared that the pimp plugin was working when in fact it was silently failing every command due to the lack of error messages.

On Aug 15, 2017 09:41, "radare" notifications@github.com wrote:

so.. i still dont get whats the problem

[0x00000000]> #!python Invalid hashbang. See '#!' for help. [0x00000000]> #! c: (LGPL) C language extension cpipe: (LGPL) C r2pipe scripting vala: (LGPL) Vala language extension rust: (MIT) Rust language extension pipe: (LGPL) Use #!pipe node script.js lib: (LGPL) Load libs directly into r2

the lang plugin is not installed and python reports invalid hashbang to run that, so the only unexpected thing is that #!python is fallbacking to

!pipe python when an argument is passed?

On 14 Aug 2017, at 19:14, Owlz notifications@github.com wrote:

Definitely have python installed.

[0x080483f0]> #!pipe python Python 2.7.9 (default, Jun 29 2016, 13:08:31) [GCC 4.9.2] on linux2 Type "help", "copyright", "credits" or "license" for more information.

[0x080483f0]> #!python Invalid hashbang. See '#!' for help. [0x080483f0]> #!python -c "test" [0x080483f0]> — You are receiving this because you commented. Reply to this email directly, view it on GitHub < https://github.com/radare/radare2/issues/8208#issuecomment-322250608>, or mute the thread https://github.com/notifications/unsubscribe-auth/AA3- lgIdrlkmdXyOYBwWxCJ16tdo1cMlks5sYIB-gaJpZM4O15dB.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/radare/radare2/issues/8208#issuecomment-322468850, or mute the thread https://github.com/notifications/unsubscribe-auth/AHR34Lu5tLjYHkAhjrIKv4Voa4CtP3Dlks5sYaAZgaJpZM4O15dB .

radare commented 7 years ago

i see, do you have any proposal to handle that case?

On 15 Aug 2017, at 16:36, Owlz notifications@github.com wrote:

Well, in my case, it appears it is not falling back to piping to python. This basically stemmed from attempting to use pimp with the python language

! Not installed. There were no errors when In fact python was not called

at all. It wasn't called directly and it wasn't called via pipe. Instead, it appeared that the pimp plugin was working when in fact it was silently failing every command due to the lack of error messages.

On Aug 15, 2017 09:41, "radare" notifications@github.com wrote:

so.. i still dont get whats the problem

[0x00000000]> #!python Invalid hashbang. See '#!' for help. [0x00000000]> #! c: (LGPL) C language extension cpipe: (LGPL) C r2pipe scripting vala: (LGPL) Vala language extension rust: (MIT) Rust language extension pipe: (LGPL) Use #!pipe node script.js lib: (LGPL) Load libs directly into r2

the lang plugin is not installed and python reports invalid hashbang to run that, so the only unexpected thing is that #!python is fallbacking to

!pipe python when an argument is passed?

On 14 Aug 2017, at 19:14, Owlz notifications@github.com wrote:

Definitely have python installed.

[0x080483f0]> #!pipe python Python 2.7.9 (default, Jun 29 2016, 13:08:31) [GCC 4.9.2] on linux2 Type "help", "copyright", "credits" or "license" for more information.

[0x080483f0]> #!python Invalid hashbang. See '#!' for help. [0x080483f0]> #!python -c "test" [0x080483f0]> — You are receiving this because you commented. Reply to this email directly, view it on GitHub < https://github.com/radare/radare2/issues/8208#issuecomment-322250608>, or mute the thread https://github.com/notifications/unsubscribe-auth/AA3- lgIdrlkmdXyOYBwWxCJ16tdo1cMlks5sYIB-gaJpZM4O15dB.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/radare/radare2/issues/8208#issuecomment-322468850, or mute the thread https://github.com/notifications/unsubscribe-auth/AHR34Lu5tLjYHkAhjrIKv4Voa4CtP3Dlks5sYaAZgaJpZM4O15dB .

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/radare/radare2/issues/8208#issuecomment-322486356, or mute the thread https://github.com/notifications/unsubscribe-auth/AA3-loZQAob4xWO6mKlXZ8RfYCzalyfZks5sYazbgaJpZM4O15dB.

bannsec commented 7 years ago

I'd just assume output a message about it not being run. The following is a trace I ran to see if python was somehow being executed silently without any indication, but it appears not:

[0x080483f0]> #!python test66m[0x080483f0]>\033[0m #!"..., 44
)                                          = 44
<... r_core_prompt resumed> )                                                                           = 1
r_core_prompt_exec(0x559bc5795e40, 0x7ffc5c2f175e, 0x559bc75ab5d0, 0x74736574206e6f <unfinished ...>
SYS_write(1, "", 0)                                                                                     = 0
<... r_core_prompt_exec resumed> )                                                                      = 1
r_core_prompt(0x559bc5795e40, 0, 0x7f5f31445340, 0x7f5f31445340 <unfinished ...>
SYS_ioctl(0, 0x5401, 0x7ffc5c2f14b0, 0x7f5f2db9b460)                                                    = 0
SYS_ioctl(0, 0x5413, 0x7ffc5c2f1550, 0x7f5f2db9b460)                                                    = 0
SYS_ioctl(0, 0x5401, 0x7ffc5c2f1510, 0x7f5f2db9b460)                                                    = 0
SYS_ioctl(0, 0x5413, 0x7ffc5c2f15b0, 0x7f5f2db9b460)                                                    = 0
SYS_ioctl(0, 0x5401, 0x7ffc5c2f1560, 0)                                                                 = 0
SYS_ioctl(0, 0x5402, 0x7ffc5c2f1530, 0x7ffc5c2f1530)                                                    = 0
SYS_ioctl(0, 0x5401, 0x7ffc5c2f1530, 0x7ffc5c2f1530)                                                    = 0

Here's what happens when I use pipe

[0x080483f0]> #!pipe python)                                     = 92
SYS_read(0, "\r", 1)                                                                                    = 1
)                                                                            = 5
SYS_ioctl(0, 0x5401, 0x7ffc5c2f1560, 0)                                                                 = 0
SYS_ioctl(0, 0x5402, 0x7ffc5c2f1530, 0x7ffc5c2f1530)                                                    = 0
SYS_ioctl(0, 0x5401, 0x7ffc5c2f1530, 0x7ffc5c2f1530)                                                    = 0
)                                                                          = 6
[0x080483f0]> #!pipe python66m[0x080483f0]>\033[0m #!"..., 44
)                                          = 44
<... r_core_prompt resumed> )                                                                           = 1
r_core_prompt_exec(0x559bc5795e40, 0x7ffc5c2f175e, 0x559bc75ab5d0, 0x6e6f6874797020 <unfinished ...>
SYS_dup(0)                                                                                              = 8
SYS_pipe(0x7ffc5c2f2170, 0x559bc764f1c7, 0xffffffff, 0x7ffc5c2f1b00)                                    = 0
SYS_pipe(0x7ffc5c2f2160, 0x559bc764f1c7, 0xffffffff, 0x7ffc5c2f1b00)                                    = 0
SYS_clone(0x1200011, 0, 0, 0x7f5f31e5a9d0)                                                              = 166
SYS_close(12)                                                                                           = 0
SYS_close(9)                                                                                            = 0
SYS_rt_sigaction(2, 0x7ffc5c2f1a70, 0x7ffc5c2f1b10, 8)                                                  = 0
SYS_read(11Python 2.7.9 (default, Jun 29 2016, 13:08:31) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>