├── README.md ├── SharpAltiris.sln └── SharpAltiris ├── Program.cs └── SharpAltiris.csproj /README.md: -------------------------------------------------------------------------------- 1 | # SharpAltiris 2 | -------------------------------------------------------------------------------- /SharpAltiris.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.32014.148 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpAltiris", "SharpAltiris\SharpAltiris.csproj", "{012BA770-AEAB-4485-9AB1-BC9086112479}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {012BA770-AEAB-4485-9AB1-BC9086112479}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {012BA770-AEAB-4485-9AB1-BC9086112479}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {012BA770-AEAB-4485-9AB1-BC9086112479}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {012BA770-AEAB-4485-9AB1-BC9086112479}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {302A7DB7-AC0D-4AA2-A5D9-295CCF89AE28} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /SharpAltiris/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net.NetworkInformation; 4 | using System.Net; 5 | using System.Net.Sockets; 6 | using System.Runtime.InteropServices; 7 | using System.IO; 8 | using System.Text; 9 | using System.Net.Security; 10 | using System.Security.Cryptography.X509Certificates; 11 | using System.Text; 12 | 13 | using System.Text.RegularExpressions; 14 | using System.Net.Http; 15 | 16 | namespace SharpAltiris 17 | { 18 | class Program 19 | { 20 | 21 | public static void GetComputerGuidByName(string notificationServer, string computerName, string username = null, string password = null) 22 | { 23 | string webserviceUrl = "/altiris/ASDK.NS/ItemManagementService.asmx/GetItemsByName?itemName=" + computerName; 24 | string finalUrl = notificationServer + webserviceUrl; 25 | 26 | string requestOutput = HttpRequest(finalUrl, null, username, password); 27 | Regex re = new Regex("[a-zA-Z0-9\\-]*", RegexOptions.IgnoreCase); 28 | string match = re.Match(requestOutput,0).Value; 29 | Console.WriteLine("Name: " + computerName); 30 | Console.WriteLine(match); 31 | 32 | } 33 | 34 | //TO DO - Find a way of getting this info 35 | public static void FindUserComputer(string notificationServer, string targetUser, string username = null, string password = null) 36 | { 37 | string webserviceUrl = "/altiris/ASDK.NS/ResourceManagementService.asmx/GetResourceByContext?parameters=type:computer, %" + targetUser + "%"; 38 | string finalUrl = notificationServer + webserviceUrl; 39 | string requestOutput = HttpRequest(finalUrl, null, username, password); 40 | Console.WriteLine(requestOutput); 41 | } 42 | 43 | public static void GetItemDetailsByGuid(string notificationServer, string guid, string username = null, string password = null) 44 | { 45 | string webserviceUrl = "/altiris/ASDK.NS/ItemManagementService.asmx/GetItemByGuid?itemGuid=" + guid; 46 | string finalUrl = notificationServer + webserviceUrl; 47 | string requestOutput = HttpRequest(finalUrl, null, username, password); 48 | Console.WriteLine(requestOutput); 49 | } 50 | 51 | public static void GetScriptTasks(string notificationServer, string username = null, string password = null) 52 | { 53 | string webserviceUrl = "/altiris/ASDK.NS/ItemManagementService.asmx/GetItemsByType?typeName=ScriptTask"; 54 | string finalUrl = notificationServer + webserviceUrl; 55 | 56 | string requestOutput = HttpRequest(finalUrl, null, username, password); 57 | Console.WriteLine(requestOutput); 58 | } 59 | 60 | public static void GetScriptTaskXml(string notificationServer, string taskGuid, string username = null, string password = null) 61 | { 62 | string webserviceUrl = "/altiris/ASDK.NS/ItemManagementService.asmx/ExportItemXmlString?itemGuid=" + taskGuid; 63 | string finalUrl = notificationServer + webserviceUrl; 64 | 65 | string requestOutput = HttpRequest(finalUrl, null, username, password); 66 | Console.WriteLine(requestOutput); 67 | } 68 | 69 | public static void ImportScriptXmlString(string notificationServer, string xmlTask, string username = null, string password = null) 70 | { 71 | string webserviceUrl = "/altiris/ASDK.NS/ItemManagementService.asmx/ImportItemXmlString"; 72 | string finalUrl = notificationServer + webserviceUrl; 73 | string postData = "xml=" + xmlTask; 74 | string requestOutput = HttpRequest(finalUrl, postData, username, password); 75 | Console.WriteLine(requestOutput); 76 | Console.WriteLine("[+] Task imported successfully"); 77 | 78 | } 79 | 80 | public static void ScheduleTask(string notificationServer, string taskGuid, string computerGuids, string executionName, string username = null, string password = null) 81 | { 82 | string webserviceUrl = "/altiris/ASDK.Task/TaskManagementService.asmx/ExecuteTask"; 83 | string finalUrl = notificationServer + webserviceUrl; 84 | string scheduleXml = "@AssignedResources" + computerGuids + "@CompRequirements2 minutes60 minutes100 %"; 85 | string postData = "taskGuid=" + taskGuid + "&executionName=" + executionName + "&inputParameters=" + scheduleXml; 86 | 87 | string requestOutput = HttpRequest(finalUrl, postData, username, password); 88 | Console.WriteLine(requestOutput); 89 | Console.WriteLine("[+] Task Executed successfully"); 90 | } 91 | 92 | public static void GetTaskStatus(string notificationServer, string taskExecutionGuid, string username = null, string password = null) 93 | { 94 | string webserviceUrl = "/altiris/ASDK.Task/TaskManagementService.asmx/GetTaskStatus?taskGuid=" + taskExecutionGuid; 95 | string finalUrl = notificationServer + webserviceUrl; 96 | 97 | string requestOutput = HttpRequest(finalUrl, null, username, password); 98 | Console.WriteLine(requestOutput); 99 | } 100 | 101 | public static void GetTaskOutput(string notificationServer, string taskExecutionGuid, string computerGuid, string username = null, string password = null) 102 | { 103 | string webserviceUrl = "/altiris/ASDK.Task/TaskManagementService.asmx/GetTaskResourceStatus?taskInstanceGuid=" + taskExecutionGuid + "&resourceGuid=" + computerGuid; 104 | string finalUrl = notificationServer + webserviceUrl; 105 | 106 | string requestOutput = HttpRequest(finalUrl, null, username, password); 107 | Console.WriteLine(requestOutput); 108 | } 109 | 110 | static void Main(string[] args) 111 | { 112 | string func = args[0].ToLower(); 113 | int argsLen = args.Length - 1; 114 | 115 | switch(func) 116 | { 117 | case "findusercomputer": 118 | if (argsLen == 2) 119 | FindUserComputer(args[1], args[2]); 120 | else 121 | FindUserComputer(args[1], args[2], args[3], args[4]); 122 | break; 123 | case "getitemdetailsbyguid": 124 | if (argsLen == 2) 125 | GetItemDetailsByGuid(args[1], args[2]); 126 | else 127 | GetItemDetailsByGuid(args[1], args[2], args[3], args[4]); 128 | break; 129 | case "getcomputerguidbyname": 130 | if (argsLen == 2) 131 | GetComputerGuidByName(args[1], args[2]); 132 | else 133 | GetComputerGuidByName(args[1], args[2], args[3], args[4]); 134 | break; 135 | case "getscripttasks": 136 | if (argsLen == 1) 137 | GetScriptTasks(args[1]); 138 | else 139 | GetScriptTasks(args[1], args[2], args[3]); 140 | break; 141 | case "getscripttaskxml": 142 | if (argsLen == 2) 143 | GetScriptTaskXml(args[1], args[2]); 144 | else 145 | GetScriptTaskXml(args[1], args[2], args[3], args[4]); 146 | break; 147 | case "importscriptxmlstring": 148 | if(argsLen == 2) 149 | ImportScriptXmlString(args[1], args[2]); 150 | else 151 | ImportScriptXmlString(args[1], args[2], args[3], args[4]); 152 | break; 153 | case "scheduletask": 154 | if (argsLen == 4) 155 | ScheduleTask(args[1], args[2], args[3], args[4]); 156 | else 157 | ScheduleTask(args[1], args[2], args[3], args[4], args[5], args[6]); 158 | break; 159 | case "gettaskstatus": 160 | if (argsLen == 2) 161 | GetTaskStatus(args[1], args[2]); 162 | else 163 | GetTaskStatus(args[1], args[2], args[3], args[4]); 164 | break; 165 | case "gettaskoutput": 166 | if (argsLen == 3) 167 | GetTaskOutput(args[1], args[2], args[3]); 168 | else 169 | GetTaskOutput(args[1], args[2], args[3], args[4], args[5]); 170 | break; 171 | default: 172 | Console.WriteLine("[x] Unknown Function"); 173 | break; 174 | } 175 | } 176 | 177 | 178 | private static string HttpRequest(string url, string data = null, string user = null, string password = null) 179 | { 180 | // Configure connection 181 | ServicePointManager.Expect100Continue = true; 182 | ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(AcceptAllCertificates); 183 | ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls; 184 | 185 | foreach (var protocol in Enum.GetValues(typeof(SecurityProtocolType))) 186 | { 187 | ServicePointManager.SecurityProtocol |= (SecurityProtocolType)protocol; 188 | } 189 | 190 | HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); 191 | HttpWebResponse response; 192 | request.AllowAutoRedirect = false; 193 | request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"; 194 | 195 | if (user != null) 196 | request.Credentials = new NetworkCredential(user, password); 197 | else 198 | request.Credentials = CredentialCache.DefaultCredentials; 199 | 200 | 201 | try 202 | { 203 | if (data != null) 204 | { 205 | var body = Encoding.ASCII.GetBytes(data); 206 | request.Method = "POST"; 207 | request.ContentType = "application/x-www-form-urlencoded"; 208 | request.ContentLength = body.Length; 209 | 210 | using (Stream dataStream = request.GetRequestStream()) 211 | { 212 | dataStream.Write(body, 0, body.Length); 213 | } 214 | 215 | 216 | response = (HttpWebResponse)request.GetResponse(); 217 | } 218 | else 219 | { 220 | response = (HttpWebResponse)request.GetResponse(); 221 | 222 | } 223 | } 224 | catch (WebException e) 225 | { 226 | response = e.Response as HttpWebResponse; 227 | if (response == null) 228 | { 229 | Console.Error.WriteLine(e.Message); 230 | return null; 231 | } 232 | } 233 | catch (Exception e) 234 | { 235 | Console.Error.WriteLine(e.Message); 236 | return null; 237 | } 238 | 239 | 240 | using (Stream dataStream = response.GetResponseStream()) 241 | { 242 | StreamReader reader = new StreamReader(dataStream); 243 | Console.WriteLine(); 244 | string output = reader.ReadToEnd(); 245 | return output; 246 | } 247 | 248 | } 249 | 250 | private static void IgnoreBadCertificates() 251 | { 252 | 253 | } 254 | 255 | private static bool AcceptAllCertificates(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certification, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors) 256 | { 257 | return true; 258 | } 259 | } 260 | } 261 | -------------------------------------------------------------------------------- /SharpAltiris/SharpAltiris.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net48 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | --------------------------------------------------------------------------------