域内批量获取敏感文件

news2025/2/24 14:09:34

0x01 批量获取域内机器名

自动化工具,当然就要全自动,懒人必备。net group "domain computers" /do ,获取机器是3个一排,然后可以通过正则删除空格,每次也麻烦,直接获取机器名更加方便。

思路就是连接ldap然后指定过滤条件(&(objectclass=computer))获取机器。

获取域内机器

public static DirectoryEntry coon = null;
public static DirectorySearcher search = null;
url = "LDAP://" + ip; 
username = domain user;
password = domain pass;
coon = new DirectoryEntry(url, username, password);
search = new DirectorySearcher(coon);
search.Filter = "(&(objectclass=computer))
 foreach (SearchResult r in Ldapcoon.search.FindAll())
 {
     string computername = "";
     computername = r.Properties["cn"][0].ToString();
     Console.WriteLine(computername);
 }

0x02 机器探测存活

1.把上述机器放入machine.txt内,然后逐行读取

StreamReader machine_name = new StreamReader(@"machine.txt");
while (!machine_name.EndOfStream)
{
    string machine = machine_name.ReadLine();
    Console.WriteLine(machine);
}

2.探测探测存活,这里面向谷歌

 public static bool IsMachineUp(string hostName)
        {
            bool retVal = false;
            try
            {
                Ping pingSender = new Ping();
                PingOptions options = new PingOptions();
                // Use the default Ttl value which is 128,
                // but change the fragmentation behavior.
                options.DontFragment = true;
                // Create a buffer of 32 bytes of data to be transmitted.
                string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
                byte[] buffer = Encoding.ASCII.GetBytes(data);
                int timeout = 800;

                PingReply reply = pingSender.Send(hostName, timeout, buffer, options);
                if (reply.Status == IPStatus.Success)
                {
                    retVal = true;
                }
            }
            catch (Exception ex)
            {
                retVal = false;
                //Console.ForegroundColor = ConsoleColor.Red;
                //Console.WriteLine("[-]" + ex.Message);
                //Console.ForegroundColor = ConsoleColor.White;
            }
            return retVal;
        }

一般来说it机器都为工作机而非服务器,可能存在下班关机等情况,如果大多机器处于关机情况下,就会浪费比较多的时间,所以优先判断存活是很有必要的。

StreamReader machine_name = new StreamReader(@"machine.txt");
while (!machine_name.EndOfStream)
{
    try
    {
        string machine = machine_name.ReadLine();
        if (IsMachineUp(machine))
     {
      //操作
     }
    }
    catch { }
}

0x03 获取桌面文件

我们这里构造获取结果目录呈现结果为:

TargetDesktopinfos
    机器1
        用户A
            文件
        用户B
            文件
    机器2
        用户C
            文件
        用户D
            文件

首先获取当前路径创建TargetDesktopinfos目录。

string currentpath = Directory.GetCurrentDirectory();
DesktopFiles = currentpath + "\\TargetDesktopinfos";
Directory.CreateDirectory(DesktopFiles);

然后获取目标机器c:\users\目录,如果存在该目录创建机器名

string userpath = @"\\" + machine + @"\c$\users";
var user_list = Directory.EnumerateDirectories(userpath);
if (Directory.Exists(userpath))
{
//创建机器名文件夹
    string MachineFolder = DesktopFiles + "\\" + machine;
    Directory.CreateDirectory(MachineFolder);

再遍历users目录存在哪些用户,同理如果存在desktop目录创建用户名和desktop.txt。

string userpath = @"\\" + machine + @"\c$\users";
var user_list = Directory.EnumerateDirectories(userpath);
if (Directory.Exists(userpath))
{
//创建机器名文件夹
string MachineFolder = DesktopFiles + "\\" + machine;
Directory.CreateDirectory(MachineFolder);
foreach (string user in user_list)
{
string DesktopDirectoryPath = user + "\\desktop";
string username = substring(user);
if (Directory.Exists(DesktopDirectoryPath))
{
//创建用户名文件夹
string UserFolder = MachineFolder + "\\" + username;
Directory.CreateDirectory(UserFolder);
//创建desktop.txt文件
string Desktoptxt = UserFolder + "\\desktop.txt";
StreamWriter sw = File.CreateText(Desktoptxt);
sw.Close();

接下来就是遍历desktop目录所有文件以及文件夹内的文件。

这里用到Directory.GetFileSystemEntries方法

public static string[] GetFileSystemEntries (string path, string searchPattern, System.IO.SearchOption searchOption);
第一个参数path:要搜索的路径。

第二个参数searchPattern:要与 `path` 中的文件和目录的名称匹配的搜索字符串。

第三个参数searchOption,指定搜索操作是应仅包含当前目录还是应包含所有子目录的枚举值之一。

这里的SearchOption.AllDirectories我们使用SearchOption.AllDirectories,表示在搜索操作中包括当前目录和所有它的子目录。

完整代码如下

try
            {
                string DesktopFiles = "";
                //获取机器名
                StreamReader machine_name = new StreamReader(@"machine.txt");
                while (!machine_name.EndOfStream)
                {
                    try
                    {
                        string machine = machine_name.ReadLine();
                        if (IsMachineUp(machine))
                        {
                            //获取当前路径
                            string currentpath = Directory.GetCurrentDirectory();
                            DesktopFiles = currentpath + "\\TargetDesktopinfos";
                            Directory.CreateDirectory(DesktopFiles);
                            Console.WriteLine("[*]" + machine);
                            //获取users目录
                            string userpath = @"\\" + machine + @"\c$\users";
                            var user_list = Directory.EnumerateDirectories(userpath);
                            if (Directory.Exists(userpath))
                            {
                                //创建机器名文件夹
                                string MachineFolder = DesktopFiles + "\\" + machine;
                                Directory.CreateDirectory(MachineFolder);
                                foreach (string user in user_list)
                                {
                                    string DesktopDirectoryPath = user + "\\desktop";
                                    string username = substring(user);
                                    if (Directory.Exists(DesktopDirectoryPath))
                                    {
                                        //创建用户名文件夹
                                        string UserFolder = MachineFolder + "\\" + username;
                                        Directory.CreateDirectory(UserFolder);
                                        //创建desktop.txt文件
                                        string Desktoptxt = UserFolder + "\\desktop.txt";
                                        StreamWriter sw = File.CreateText(Desktoptxt);
                                        sw.Close();

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

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

                                        foreach (string file in AllFiles)
                                        {
                                            Console.WriteLine(file);
                                            string create_time = Directory.GetCreationTime(file).ToString();
                                            string writeFileTo = "create time:" + create_time + "  " + file + "\r\n";
                                            File.AppendAllText(Desktoptxt, writeFileTo);
                                        }
                                    }
                                    else
                                    {
                                        continue;
                                    }
                                }
                            }
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("[-]" + machine + " is down");
                            Console.ForegroundColor = ConsoleColor.White;
                        }
                    }
                    catch (System.Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("[-] error");
                        Console.WriteLine("[-] Exception: " + ex.Message);
                        Console.ForegroundColor = ConsoleColor.White;
                        continue;
                    }
                }
                machine_name.Close();
                Console.WriteLine("[+]out put to:" + DesktopFiles);
            }
            catch (System.Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("[-] error");
                Console.WriteLine("[-] Exception: " + ex.Message);
                Console.ForegroundColor = ConsoleColor.White;
                return;
            }

同理要获取DEF盘,这里就举例D盘

public static void D()
        {
            try
            {
                string DFiles = "";
                StreamReader machine_name = new StreamReader(@"machine.txt");
                while (!machine_name.EndOfStream)
                {
                    try
                    {
                        string machine = machine_name.ReadLine();
                        if (IsMachineUp(machine))
                        {
                            string currentpath = Directory.GetCurrentDirectory();
                            DFiles = currentpath + "\\DInfos";
                            Directory.CreateDirectory(DFiles);

                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.WriteLine("[*]" + machine);
                            Console.ForegroundColor = ConsoleColor.White;

                            //获取users目录
                            string dpath = @"\\" + machine + @"\d$";
                            var d_list = Directory.EnumerateDirectories(dpath);
                            if (Directory.Exists(dpath))
                            {
                                //创建机器名文件夹
                                string MachineFolder = DFiles + "\\" + machine;
                                Directory.CreateDirectory(MachineFolder);
                                //创建输出文本
                                string E_txt = MachineFolder + "\\dFiles.txt";
                                StreamWriter sw = File.CreateText(E_txt);
                                sw.Close();
                                try
                                {
                                    var files = Directory.GetFiles(dpath);
                                    foreach (string file in files)
                                    {
                                        Console.WriteLine(file);
                                        string create_time = Directory.GetCreationTime(file).ToString();
                                        string writeFileTo = "create time:" + create_time + "  " + file + "\r\n";
                                        File.AppendAllText(E_txt, writeFileTo);
                                    }

                                    var directorys = Directory.EnumerateDirectories(dpath);
                                    foreach (string directory in directorys)
                                    {
                                        if (!directory.Contains("System Volume Information"))
                                        {
                                            string[] AllFiles = Directory.GetFileSystemEntries(directory, "*", SearchOption.AllDirectories);
                                            foreach (string file in AllFiles)
                                            {
                                                string create_time = Directory.GetCreationTime(file).ToString();
                                                Console.WriteLine(file);
                                                string writeFileTo = "create time:" + create_time + "  " + file + "\r\n";
                                                File.AppendAllText(E_txt, writeFileTo);
                                            }
                                        }
                                    }
                                }
                                catch (UnauthorizedAccessException ex)
                                {
                                    Console.ForegroundColor = ConsoleColor.Red;
                                    Console.WriteLine(ex.Message);
                                    Console.ForegroundColor = ConsoleColor.White;
                                    //goto cc;
                                }


                            }
                        }
                    }
                    catch (System.Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("[-] 不存在D盘");
                        Console.WriteLine(ex.Message);
                        Console.ForegroundColor = ConsoleColor.White;
                        continue;
                    }
                }
                machine_name.Close();
                Console.WriteLine("[+]out put to:" + DFiles);
            }
            catch (System.Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("[-] error");
                Console.WriteLine("[-] Exception: " + ex.Message);
                Console.ForegroundColor = ConsoleColor.White;
                return;
            }
        }

这里我们在08这台域机器桌面存放文件

测试效

结果呈现

接下来直接文件夹搜索password或者vpn等关键字即可。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2682.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

QT调用OpenCV绘制直线、矩形、椭圆、圆、不规则曲线、文本

开发环境:QT5.14.2OpenCV4.5 提前准备:准备编译好的OpenCV开发环境(如自行编译的mingw版的opencv库,本地路径D:\opencv\qt_build64),准备一张测试图片(如:d:\test.jpg)。 项目结构&#xff1a…

如果再来一次,你还会选择互联网么?

现在互联网的就业环境,大家都在感受着一股寒意。也不知道从什么时候开始,身边悲观的声音越来越多了。 如果再给你一次机会,你还会选择互联网吗? 回答这个问题之前,我想跟大家聊聊一个我朋友的故事。 他从学渣到大厂程…

64位下使用回调函数实现监控

前言 在32位的系统下,我们想要实现某些监控十分简单,只需要找到对应的API实现挂钩操作即可检测进程。但在64位系统下随着Patch Guard的引入,导致我们如果继续使用挂钩API的方式进行监控会出现不可控的情况发生。微软也考虑到了用户程序的开发…

Linux shell脚本之笔记及实用笔记

一、前言 二、shell脚本之数据类型 2.1、数组遍历 1)数组定义 如果说变量是存储单个变量的内存空间,那么数组就是多个变量的集合,它存储多个元素在一片连续的内存空间中。在bash中,只支持一维数组,不支持多维数组。Linux Shell 数组用括号来表示,Bash Shell 只支持一维…

15. “接口隔离模式”之 Proxy模式

1. 动机 在面向对象系统中,有些对象由于某些原因(比如对象创建的开销很大,或者某些操作需要安全控制,或者需要进程外的访问等),直接访问会给使用者、或者系统结构带来很多麻烦。如何在不失去透明操作对象的…

Java中值得注意的『运算符、逻辑控制、输入输出』

目录前言一、运算符🍑1、取模运算符%🍑2、增量运算符🍑3、逻辑运算符🍑4、位运算符二、逻辑控制语句🍑1、switch语句三、Java输入和输出🍑1、输出到控制台🍑2、从键盘输入四、猜数字游戏——Jav…

软件过程与项目管理复习(1)

文章目录Week1Project Introduction定义特点Project management项目管理的价值项目管理的5要素Project manager项目经理的技能要求project manager 的核心任务(key activities)规划 planning组织 organizing领导 leading掌控 controllingAgile Scrum master 的核心任…

结构体超详解(小白一看就懂,多维度分析!!!!)

目录 一、前言 二、结构体详解 🍐什么是结构体 🍎结构体的定义与基础结构 🍑结构体的使用 💦结构体的初始化 💦结构体的成员访问 💦结构体数组 💦结构体指针--------------指向结构体变…

PNAS:人类头皮记录电位的时间尺度

导读 人类的许多行为都是由在不同时间尺度上发生的共同过程所支配的。标准的事件相关电位分析假设有关实验事件的响应持续时间是固定的。然而,最近对动物的单个单元记录显示,在需要灵活计时的行为中,神经活动尺度跨越了不同的持续时间。本研…

vue3——使用axios

1、Axios 是什么? 浏览器页面在向服务器请求数据时,因为返回的是整个页面的数据,页面都会强制刷新一下,这对于用户来讲并不是很友好。并且我们只是需要修改页面的部分数据,但是从服务器端发送的却是整个页面的数据,十…

Keras深度学习实战(33)——基于LSTM的序列预测模型

Keras深度学习实战(33)——基于LSTM的序列预测模型0. 前言1. 序列学习任务1.1 命名实体提取1.2 文本摘要1.3 机器翻译2. 从输出网络返回输出序列2.1 传统模型体系结构2.2 返回每个时间戳的网络中间状态序列2.3 使用双向 LSTM 网络小结系列链接0. 前言 在…

Qt易忘样式表总结

目录前言1、Qt设置样式的几种方式2、几种复合控件的样式设置QTableWidgetQCalendarWidgetQTreeWidgetQSpinBoxQComboBox前言 在使用Qt框架开发软件时,为了美观和更好的用户体验,需要为各种控件设置样式。一些通用且简单的样式如背景色、边框、字体字号等…

js实现图片懒加载

js实现图片懒加载 1、介绍getBoundingClientRect()函数 该函数没有参数,用于获取元素位置,返回一个对象,具有六个属性分别是: ele.getBoundingClientRect().top – 返回元素上边到视窗上边的距离 ele.getBoundingClientRect().l…

【经典面试题-LeetCode134:加油站问题(Java实现)】

加油站问题一、题目描述1.题目内容2.样例二、解决方案1.分析2.核心代码一、题目描述 1.题目内容 在一条环路上有 n 个加油站,其中第 i 个加油站有汽油 gas[i] 升。 你有一辆油箱容量无限的的汽车,从第 i 个加油站开往第 i1 个加油站需要消耗汽油 cost[i…

自动控制原理 - 2 控制系统的数学模型 节2.4-2.6

------------------------------------------------------------------------------ 2 控制系统的数学模型2.4 控制系统的传递函数2.5 典型环节的传递函数2.6 结构图的绘制 2 控制系统的数学模型 2.4 控制系统的传递函数 为何引入传递函数? 微分方程模型的优缺…

Webpack面试题总结

说说你对webpack的理解?解决了什么问题? webpack最初的目标是实现前端项目模块化,目的在于更高效的管理和维护项目中的每一个资源 模块化: 最早的时候,我们通过文件划分的形式实现模块化,也就是将每个功能…

JVM性能——开启回收日志和实时查看GC信息

JVM性能——开启回收日志和实时查看GC信息 JDK版本:OpenJDK 1.8.0_352-b08 操作系统:CentOS 7 如果文章内出现测试数据测试代码 depth:23 关于JVM的其他文章 JVM性能——垃圾回收器的优化策略 JVM性能——垃圾回收器的介绍 JVM性能——开启回收日…

网络赚钱项目 - 虚拟项目如何选择产品

今日一个老粉找我,他去年3月份就重视我跟我互动了,他上来并不是索取什么,而是给我信息,比如他最近测验了什么产品,什么产品好卖,都会把测验的数据告诉我,当然作为回报,我也会告诉他一…

Centos7宝塔部署python

前言:宝塔本身有python项目管理器,但是有些依赖安装会存在问题,比如paddlehub安装总是失败,本文在宝塔安装了anaconda基础上配合python项目管理器去部署项目,保障依赖隔离不混乱。 centos7宝塔安装conda流程地址&…

Linux使用YUM安装程序

目录 前言 什么是YUM? 1.本地源:系统安装光盘 目的 1)观察YUM核心配置目录 2)删除官方YUM库 3)编写本地YUM库配置文件 4)挂载安装光盘 保证把光盘放到服务器上,通电 挂载 5&#xff0…