7

My phone is a Galaxy S3, not rooted. I have "ES File Explorer" and "Terminal Emulator" installed.

I downloaded an Android build of 'wget', intending to execute it from the Terminal Emulator app. The file currently exists in /storage/sdcard0/Download (which is an internal partition, not a physical SD card) as:

-rw-rw-r-- root sdcard_rw 241974 2016-03-11 wget

./wget gives Permission denied. chmod o+x wget gives "Bad mode"; this is apparently because Android's chmod only accepts octal digits; chmod 665 wget gives "Operation not permitted". I can copy the file with "cp", so the filesystem is writable.

Other Q&A's here give several possible reasons for chmod failing on Android. One is SD cards formatted with FAT which do not support permission bits; but as I say this is not actually an SD card. Another is the filesystem being mounted with "noexec". My Android/Linux knowledge is way too lacking to check such things.

Is Android blocking me from executing wget by design? Is there a way to execute it without rooting my phone?

Andrew T.
  • 16,898
  • 10
  • 77
  • 134
Chungzuwalla
  • 173
  • 1
  • 1
  • 4

3 Answers3

6

Yes, this is by design. You can't execute binaries from the SD card without system or superuser privileges (and remounting it without the noexec option) because otherwise apps could just download and execute malicious code at will. In older versions of Android the SD card also did not have emulated permissions so chmod would naturally fail.

Some devices/older versions of Android might allow execution from /data/local/tmp/, so you could try putting it there. Otherwise, you'll probably need root.

Matthew Read
  • 50,777
  • 30
  • 148
  • 275
5

Android, just as Linux, prevents any user but root, to change the permission bits of any file not owned by such user. That said, chmod is ineffective, unless you have root privileges.

By the way, even if you had such privileges, you wouldn't have been able to change permissions, as long as the target path is /storage/sdcard0 or /storage/emulated/0. This depends upon a security policy, which is implemented in the form of the FUSE filesystem, and can be circumvented by moving to /data/media/0 or /data/media/emulated/0, and chmoding the file from this position. Please notice that this procedure will let you execute a script only if you launch it from one of the abovementioned locations.

Lastly, it should be noted that the Android port of chmod does not support symbolic editing of the flags (+rwx and so on), so you'll be forced to edit them via their corresponding octal values. You'll also do need root privileges, in order to be able to access /data/media. Trying to cd to such directory by using user privileges results in a Permission denied error.

Grimoire
  • 2,978
  • 4
  • 17
  • 31
0
  • first, to make file executable, you should do chmod 775 wget (and not 665)
  • but, you can only change modes of file if you are it its owner (or root). In your case, owner is root (and group sdcard_rw, as indicated by your ls -l), so only root can change permissions. As you are not root (you can check with id command, but as you say you haven't got a rooted device, so you can't use su to become root) you cannot change its permissions.
  • Also, modes can only be changed if filesystem containing file supports UN*X permissions. Your /storage/sdcard0/Download is probably FAT, which doesn't support it (you can check filesystem type with cat /proc/mounts)

Having said all that, if the file was shell script, you could execute it even with missing x mode with sh /storage/sdcard0/Download/script.

But if it is ELF binary (as it is the case with your wget), you are probably out of luck on Android (on desktop GNU/Linux system, you can execute ELF binaries indirectly via dynamic linker /lib64/ld-linux-x86-64.so.2 /mnt/Download/wget, but I don't think Android allow the same with its /system/bin/linker - I could be wrong on that one, though)

Matija Nalis
  • 204
  • 2
  • 5