Is it possible for a Crystal lang process to chang

2019-05-23 04:02发布

If a Crystal language process is running as root, can it change it's euid/uid to something else? For example:

 old_euid, old_ui = Process.euid, Process.uid
 Process.euid = someone_else
 Process.uid  = someone_else

1条回答
手持菜刀,她持情操
2楼-- · 2019-05-23 04:26

Yes, by using bindings to libc:

lib LibC
  fun setuid(uid_t : Int)
  fun getuid : Int
end

LibC.getuid                         #=> 0
Process.run("whoami", output: true) #=> root

LibC.setuid(uid)
LibC.getuid                         #=> my uid
Process.run("whoami", output: true) #=> my user name

The program needs to be running as root of course (i. e. sudo crystal source.cr)

查看更多
登录 后发表回答