neurobin / shc

Shell script compiler
https://neurobin.org/projects/softwares/unix/shc/
GNU General Public License v3.0
2.02k stars 345 forks source link

Operation not permitted ereror #73

Closed haimiko closed 5 years ago

haimiko commented 5 years ago

When compiling with the -H option, on Ubutuntu 14-16, the resulting binary returns the following error when trying to run it: Operation not permitted Killed

Running a binary compiled without -H works just fine.

Thoughts?

Output from strace:

execve("./mytest", ["./mytest"], [/* 21 vars */]) = 0
brk(NULL)                               = 0x165a000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("tls/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("tls/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("libc.so.6", O_RDONLY|O_CLOEXEC)   = -1 ENOENT (No such file or directory)
open("/usr/local/lib/tls/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/local/lib/tls/x86_64", 0x7fff400b8290) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/tls/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/local/lib/tls", 0x7fff400b8290) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/local/lib/x86_64", 0x7fff400b8290) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/local/lib", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=26160, ...}) = 0
mmap(NULL, 26160, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f992dae4000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\t\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1868984, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f992dae3000
mmap(NULL, 3971488, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f992d4fc000
mprotect(0x7f992d6bc000, 2097152, PROT_NONE) = 0
mmap(0x7f992d8bc000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1c0000) = 0x7f992d8bc000
mmap(0x7f992d8c2000, 14752, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f992d8c2000
close(3)                                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f992dae2000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f992dae1000
arch_prctl(ARCH_SET_FS, 0x7f992dae2700) = 0
mprotect(0x7f992d8bc000, 16384, PROT_READ) = 0
mprotect(0x602000, 4096, PROT_READ)     = 0
mprotect(0x7f992daeb000, 4096, PROT_READ) = 0
munmap(0x7f992dae4000, 26160)           = 0
prctl(PR_SET_DUMPABLE, 0)               = 0
prctl(PR_SET_PTRACER, 4294967295)       = 0
getppid()                               = 4933
brk(NULL)                               = 0x165a000
brk(0x167b000)                          = 0x167b000
open("/proc/4933/cmdline", O_RDONLY)    = 3
fstat(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
read(3, "strace\0./mytest\0", 8192) = 22
read(3, "", 7168)                       = 0
close(3)                                = 0
fstat(1, {st_mode=S_IFCHR|0600, st_rdev=makedev(4, 64), ...}) = 0
ioctl(1, TCGETS, {B115200 opost isig icanon echo ...}) = 0
write(1, "Operation not permitted\n", 24Operation not permitted
) = 24
getpid()                                = 4935
kill(4935, SIGKILL <unfinished ...>
+++ killed by SIGKILL +++
Killed
neurobin commented 5 years ago

Try running with sudo

haimiko commented 5 years ago

I neglected to mention that I'm already running as root.

haimiko commented 5 years ago

Oddly enough, with sudo it works on the workstation I compiled it on but when I try running it on another identical workstation I get this error: sh: 1: Syntax error: ")" unexpected

neurobin commented 5 years ago

It's because, the -H runs the code in default shell (which may not match with the code). see https://github.com/neurobin/shc#the-hardening-flag--h

haimiko commented 5 years ago

Right I read that. But how does that explain that it works fine on the originating system but not on a an identical clone?

On Wed, Feb 13, 2019 at 4:19 AM Md Jahidul Hamid notifications@github.com wrote:

It's because, the -H runs the code in default shell. see https://github.com/neurobin/shc#the-hardening-flag--h

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/neurobin/shc/issues/73#issuecomment-463161368, or mute the thread https://github.com/notifications/unsubscribe-auth/ADKkVmiHIQnz8SIs4J3wxfY8wdNzIrTbks5vM_SlgaJpZM4a0TXL .

neurobin commented 5 years ago

Please check the default shell, they are probably different.

ls -la $(which sh)

e.g: For me it's dash:

lrwxrwxrwx 1 root root 4 Aug 22 17:48 /bin/sh -> dash
haimiko commented 5 years ago

Both show lrwxrwxrwx 1 root root 4 Dec 5 2017 /bin/sh -> dash

On Wed, Feb 13, 2019 at 7:35 AM Md Jahidul Hamid notifications@github.com wrote:

Please check, the default shell, they are probably different.

ls -la $(which sh)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/neurobin/shc/issues/73#issuecomment-463221491, or mute the thread https://github.com/notifications/unsubscribe-auth/ADKkVqHCZmkP9xKbUWVzWKyrvQSjXakqks5vNCKfgaJpZM4a0TXL .

neurobin commented 5 years ago

Did you use the -r flag during compilation?

haimiko commented 5 years ago

That fixed it. Thank you for your help.

On Thu, Feb 14, 2019 at 2:28 AM Md Jahidul Hamid notifications@github.com wrote:

Did you use the -r flag during compilation?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/neurobin/shc/issues/73#issuecomment-463556078, or mute the thread https://github.com/notifications/unsubscribe-auth/ADKkVhlkYr0Vuvw-RxElY6pgIXNNjXP6ks5vNSw_gaJpZM4a0TXL .