【问题标题】:Binary create a shell as another user二进制以另一个用户身份创建 shell
【发布时间】:2021-12-23 11:18:05
【问题描述】:

我有一个具体的问题, 我有一个二进制文件,它使用 execv 启动 shell,但 shell 更改了用户,而使用 gdb 我似乎无法找到用户更改发生的位置。

level0@RainFall:~$ whoami
level0
level0@RainFall:~$ ls -la
-rwsr-x---+ 1 level1 users 747441 Mar  6  2016 level0
level0@RainFall:~$ gdb
(gdb) file level0
Reading symbols from /home/user/level0/level0...(no debugging symbols found)...done.
(gdb) run 423
Starting program: /home/user/level0/level0 423
process 3718 is executing new program: /bin/dash
$ whoami
level0

但是当我不使用 gdb 时:

level0@RainFall:~$ ./level0 423
$ whoami
level1
$ 

这里是主要的disas

   0x08048ec0 <+0>: push   ebp
   0x08048ec1 <+1>: mov    ebp,esp
   0x08048ec3 <+3>: and    esp,0xfffffff0
   0x08048ec6 <+6>: sub    esp,0x20
   0x08048ec9 <+9>: mov    eax,DWORD PTR [ebp+0xc]
   0x08048ecc <+12>:    add    eax,0x4
   0x08048ecf <+15>:    mov    eax,DWORD PTR [eax]
   0x08048ed1 <+17>:    mov    DWORD PTR [esp],eax
   0x08048ed4 <+20>:    call   0x8049710 <atoi>
   0x08048ed9 <+25>:    cmp    eax,0x1a7
   // it compare argv[1] with 423 if it is unequal it print No!
   0x08048ede <+30>:    jne    0x8048f58 <main+152>
   0x08048ee0 <+32>:    mov    DWORD PTR [esp],0x80c5348
   0x08048ee7 <+39>:    call   0x8050bf0 <strdup>
   0x08048eec <+44>:    mov    DWORD PTR [esp+0x10],eax
   0x08048ef0 <+48>:    mov    DWORD PTR [esp+0x14],0x0
   0x08048ef8 <+56>:    call   0x8054680 <getegid>
   0x08048efd <+61>:    mov    DWORD PTR [esp+0x1c],eax
   0x08048f01 <+65>:    call   0x8054670 <geteuid>
   0x08048f06 <+70>:    mov    DWORD PTR [esp+0x18],eax
   0x08048f0a <+74>:    mov    eax,DWORD PTR [esp+0x1c]
   0x08048f0e <+78>:    mov    DWORD PTR [esp+0x8],eax
   0x08048f12 <+82>:    mov    eax,DWORD PTR [esp+0x1c]
   0x08048f16 <+86>:    mov    DWORD PTR [esp+0x4],eax
   0x08048f1a <+90>:    mov    eax,DWORD PTR [esp+0x1c]
   0x08048f1e <+94>:    mov    DWORD PTR [esp],eax
   0x08048f21 <+97>:    call   0x8054700 <setresgid>
   0x08048f26 <+102>:   mov    eax,DWORD PTR [esp+0x18]
   0x08048f2a <+106>:   mov    DWORD PTR [esp+0x8],eax
   0x08048f2e <+110>:   mov    eax,DWORD PTR [esp+0x18]
   0x08048f32 <+114>:   mov    DWORD PTR [esp+0x4],eax
   0x08048f36 <+118>:   mov    eax,DWORD PTR [esp+0x18]
   0x08048f3a <+122>:   mov    DWORD PTR [esp],eax
   0x08048f3d <+125>:   call   0x8054690 <setresuid>
   0x08048f42 <+130>:   lea    eax,[esp+0x10]
   0x08048f46 <+134>:   mov    DWORD PTR [esp+0x4],eax
   0x08048f4a <+138>:   mov    DWORD PTR [esp],0x80c5348 
   //at this point euid and egid are the one of the user that launched gdb`
   0x08048f51 <+145>:   call   0x8054640 <execv>
   // we never go there since execv opens a shell
   0x08048f56 <+150>:   jmp    0x8048f80 <main+192>
   0x08048f58 <+152>:   mov    eax,ds:0x80ee170
   0x08048f5d <+157>:   mov    edx,eax
   0x08048f5f <+159>:   mov    eax,0x80c5350
   0x08048f64 <+164>:   mov    DWORD PTR [esp+0xc],edx
   0x08048f68 <+168>:   mov    DWORD PTR [esp+0x8],0x5
   0x08048f70 <+176>:   mov    DWORD PTR [esp+0x4],0x1
   0x08048f78 <+184>:   mov    DWORD PTR [esp],eax
   0x08048f7b <+187>:   call   0x804a230 <fwrite>
   0x08048f80 <+192>:   mov    eax,0x0
   0x08048f85 <+197>:   leave  
   0x08048f86 <+198>:   ret    
End of assembler dump.

我不明白如果我通过 gdb 或在 shell 中执行二进制文件会如何改变行为,可能是因为二进制文件的专有是 level1?

如果有人有时间向我解释它是如何工作的,我会非常感激

非常感谢

【问题讨论】:

  • 在调试程序时操作系统会忽略setuid。
  • 哦,好的,非常感谢,但我在程序中看不到 setuid?有没有办法解决这个问题?再次感谢
  • setuid 位在文件中。 -rwsr-x---+s。它通常告诉操作系统以拥有该文件的用户身份运行它。显而易见的解决方法是在以 level1 登录时启动 gdb。

标签: shell assembly gdb setuid execve


【解决方案1】:

我不明白二进制如何改变行为

二进制文件不会——当提供 set-uid 二进制文件时,内核会创建一个具有不同 UID 的新进程(这就是 -rwsr-x---+ 中的 s 的含义)。

出于明显的安全原因,内核在调试二进制文件时不会这样做。

【讨论】:

    猜你喜欢
    • 2019-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-25
    • 2019-12-21
    • 1970-01-01
    • 2019-05-13
    • 2017-04-16
    相关资源
    最近更新 更多