forked from RowTeam/SharpSQLTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetting.cs
More file actions
146 lines (132 loc) · 4.3 KB
/
Setting.cs
File metadata and controls
146 lines (132 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using SharpSQLTools.FunModule;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
namespace SharpSQLTools
{
class Setting
{
private String Command = String.Empty;
public SqlConnection Conn = null;
public Setting(SqlConnection Connection)
{
Conn = Connection;
}
/// <summary>
/// 判断文件是否存在
/// </summary>
public bool File_Exists(String path)
{
Command = String.Format(@"
DECLARE @r INT
EXEC master.dbo.xp_fileexist '{0}', @r OUTPUT
SELECT @r as n", path);
if (int.Parse(Batch.RemoteExec(Conn, Command, false)) == 1)
return true;
return false;
}
/// <summary>
/// 设置 configuration
/// </summary>
public bool Set_configuration(String option, int value)
{
Command = String.Format("exec master.dbo.sp_configure '{0}',{1}; RECONFIGURE;", option, value);
Batch.RemoteExec(Conn, Command, false);
return Check_configuration(option, value);
}
/// <summary>
/// 检查 configuration 的配置
/// </summary>
public bool Check_configuration(String option, int value)
{
Command = String.Format("SELECT cast(value as INT) as v FROM sys.configurations where name = '{0}';", option);
if (int.Parse(Batch.RemoteExec(Conn, Command, false)) == value)
return true;
return false;
}
#region 启用/关闭 OLE Automation Procedures 配置
/// <summary>
/// 开启 OLA
/// </summary>
public bool Enable_ola()
{
if (!Set_configuration("show advanced options", 1))
{
Console.WriteLine("[!] cannot enable 'show advanced options'");
return false;
}
if (!Set_configuration("Ole Automation Procedures", 1))
{
Console.WriteLine("[!] cannot enable 'Ole Automation Procedures'");
return false;
}
return true;
}
/// <summary>
/// 关闭 OLA
/// </summary>
public bool Disable_ole()
{
if (!Set_configuration("show advanced options", 1))
{
Console.WriteLine("[!] cannot enable 'show advanced options'");
return false;
}
if (!Set_configuration("Ole Automation Procedures", 0))
{
Console.WriteLine("[!] cannot disable 'Ole Automation Procedures'");
return false;
}
if (!Set_configuration("show advanced options", 0))
{
Console.WriteLine("[!] cannot disable 'show advanced options'");
return false;
}
return true;
}
#endregion
#region 启用/关闭 xp_cmdshell
/// <summary>
/// 开启 xp_cmdshell
/// </summary>
public bool Enable_xp_cmdshell()
{
if (!Set_configuration("show advanced options", 1))
{
Console.WriteLine("[!] cannot enable 'show advanced options'");
return false;
}
if (!Set_configuration("xp_cmdshell", 1))
{
Console.WriteLine("[!] cannot enable 'xp_cmdshell'");
return false;
}
return true;
}
/// <summary>
/// 关闭 xp_cmdshell
/// </summary>
public bool Disable_xp_cmdshell()
{
if (!Set_configuration("show advanced options", 1))
{
Console.WriteLine("[!] cannot enable 'show advanced options'");
return false;
}
if (!Set_configuration("xp_cmdshell", 0))
{
Console.WriteLine("[!] cannot disable 'xp_cmdshell'");
return false;
}
if (!Set_configuration("show advanced options", 0))
{
Console.WriteLine("[!] cannot disable 'show advanced options'");
return false;
}
return true;
}
#endregion
}
}