Azure-Sentinel icon indicating copy to clipboard operation
Azure-Sentinel copied to clipboard

Problem with Sentinel PB Fortigate - Function Fortinet-GetEntityDetails

Open Joaquin1912 opened this issue 4 years ago • 17 comments

Describe the bug When I try to run the PB to find if the IP is created in the Forti I get the error "The remote certificate is invalid according to the validation procedure." and I can't get past this step. If I just execute the function, the same thing happens to me.

To Reproduce I execute this code: image

Screenshots Error image

Can you help me?

Joaquin1912 avatar Jan 26 '22 12:01 Joaquin1912

Thank you for submitting an Issue to the Azure Sentinel GitHub repo! You should expect an initial response to your Issue from the team within 5 business days. Note that this response may be delayed during holiday periods. For urgent, production-affecting issues please raise a support ticket via the Azure Portal.

github-actions[bot] avatar Jan 26 '22 12:01 github-actions[bot]

To me it looks like the error is with your authentication. Maybe try using this outdated method that I wrote:

Function for getting token - use the correct API values etc, would be good to first test values using Postman. The current values for the GetToken() fucntion are for a connection to a Log Analytics workspace.

private static string GetToken(){
    var request = (HttpWebRequest)WebRequest.Create("REQUEST TO LA");

        var postData = "grant_type=" + Uri.EscapeDataString("client_credentials");
            postData += "&client_id=" + Uri.EscapeDataString(""); //add client ID
            postData += "&client_secret=" + Uri.EscapeDataString(""); //add client secret
            postData += "&resource=" + Uri.EscapeDataString("https://api.loganalytics.io");
        var data = Encoding.ASCII.GetBytes(postData);

        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        request.ContentLength = data.Length;

        using (var stream = request.GetRequestStream())
        {
            stream.Write(data, 0, data.Length);
        }

        var response = (HttpWebResponse)request.GetResponse();
        var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

        //convert token to string
        dynamic stuff = JsonConvert.DeserializeObject(responseString);
        string token = stuff.access_token;

        return token;

}

Perform the request using the token that you just got. Remember to fill in the correct accept and other values for the request.

private static string Request() {
    
    var access = GetToken();
    var request = (HttpWebRequest)WebRequest.Create("REQUESTHERE");
    
    request.Method = "GET";
    request.Accept = "application/json";
    request.Headers["Authorization"] = "Bearer "+access;
    

    var response = (HttpWebResponse)request.GetResponse();
    var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

    //convert token to string
    dynamic results = JsonConvert.DeserializeObject(responseString);
    
    return results.ToString(); //I'm returing this in a string format, but if you can parse it and think of a better way, please do make the change
}

Lodewyk-Git avatar Jan 27 '22 12:01 Lodewyk-Git

Sorry, but I don't quite understand your code. I explain to you, this function in the photo is used to connect via API to a FortiGate using the key that we have added in the key vault and the predefined values in the APP(Picture) function. I don't know why my code fails and I don't know if yours is compatible with what I want to do. I can't use PostMan due to permission issues. Can you help me? Thank you. image

Joaquin1912 avatar Jan 31 '22 16:01 Joaquin1912

Thank you for submitting an Issue to the Azure Sentinel GitHub repo! You should expect an initial response to your Issue from the team within 5 business days. Note that this response may be delayed during holiday periods. For urgent, production-affecting issues please raise a support ticket via the Azure Portal.

github-actions[bot] avatar Feb 09 '22 21:02 github-actions[bot]

Any updates??

Joaquin1912 avatar Feb 11 '22 09:02 Joaquin1912

Hello?

Joaquin1912 avatar Feb 22 '22 09:02 Joaquin1912

Any updates?

Joaquin1912 avatar Mar 09 '22 10:03 Joaquin1912

Hi @Joaquin1912 - Sorry for delay in responding. We are not able to replicate this issue, but I am thinking this might be caused by 2 reasons 1) Invalid Key 2) Your host is not enabled with SSL certificate. Since you have mentioned that you can't use postman, can you please try with curl ? Sample API call is given below, you can replace with your fortigate host details

curl -X POST "https://'fwurl'/api/v2/cmdb/firewall/address" -H "accept: application/json" -H "Authorization: Bearer 'api key'" -H "Content-Type: application/json" -d "{ "name": "test1000", "type": "iprange", "start-ip": "20.1.1.12", "end-ip": "20.1.1.12"}"

anki-narravula avatar Mar 09 '22 17:03 anki-narravula

image Hello!! Thanks for the reply, I get this above when I run it

Regards

Joaquin1912 avatar Mar 10 '22 11:03 Joaquin1912

Hi @Joaquin1912 - Thanks for checking. So based on this, it clearly indicates that these is an issue with Fortigate hosts SSL configuration. This is generic issue and nothing to do with this Playbook or Sentinel. So please try to address this issue by contacting system administrator or fortigate team.

image

anki-narravula avatar Mar 11 '22 07:03 anki-narravula

Hi all, Greetings !!!

I just wanted to create a playbook in sentinel for auto-blocking an IP address in FortiGate Firewall. by using the below link. could anyone tell me the step by step how i can achieve it.

like we need function app, custom connector and API key. but how playbook will communicate with On-Prem Fortigate firewall. what configuration we have to do in FortiGate Firewall side.

https://github.com/Azure/Azure-Sentinel/tree/master/Playbooks/Fortinet-FortiGate

Regards

raj009970 avatar Mar 24 '22 09:03 raj009970

Thank you for submitting an Issue to the Azure Sentinel GitHub repo! You should expect an initial response to your Issue from the team within 5 business days. Note that this response may be delayed during holiday periods. For urgent, production-affecting issues please raise a support ticket via the Azure Portal.

github-actions[bot] avatar Jul 01 '22 09:07 github-actions[bot]

Hi @raj009970, Thank you for your comment. Can you please create a new issue as this issue is not related to the actual issue opened here.

v-amolpatil avatar Jan 30 '23 17:01 v-amolpatil

Hi @Joaquin1912, As per earlier comment this issue is from Fortinet hosts SSL so closing this issue as it is not related to playbook or Sentinel.

v-amolpatil avatar Jan 30 '23 17:01 v-amolpatil

Thank you for submitting an Issue to the Azure Sentinel GitHub repo! You should expect an initial response to your Issue from the team within 5 business days. Note that this response may be delayed during holiday periods. For urgent, production-affecting issues please raise a support ticket via the Azure Portal.

github-actions[bot] avatar Jan 30 '23 17:01 github-actions[bot]

Hello,

I resolved the issue on the run.csx of the function please update by writing this code :

#r "Newtonsoft.Json" #r "System.Net.Http" using System.Net; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Primitives; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System.Security.Cryptography.X509Certificates; public static async Task Run(HttpRequest req, ILogger log) { HttpClientHandler handler = new HttpClientHandler(); handler.ServerCertificateCustomValidationCallback +=(sender,cert,chain,sslPolicyErrors) => true; log.LogInformation("HTTP request received."); var entity = req.Query["entity"]; var filter = req.Query["filter"]; var key = Environment.GetEnvironmentVariable("Authorization", EnvironmentVariableTarget.Process); var endpointURL = Environment.GetEnvironmentVariable("EndpointURL", EnvironmentVariableTarget.Process); var baseURL = Environment.GetEnvironmentVariable("BaseURL", EnvironmentVariableTarget.Process); JToken results = null; log.LogInformation(filter); log.LogInformation(entity); log.LogInformation(baseURL); var httpclient = new HttpClient(handler); var httpRequest = new HttpRequestMessage(HttpMethod.Get, new Uri(endpointURL + baseURL + entity + "?" + filter )); log.LogInformation(httpRequest.RequestUri.ToString()); if (key.StartsWith("Bearer", StringComparison.InvariantCultureIgnoreCase)) {key = key.ToString(); log.LogInformation(key);} else {key = "Bearer" + key.ToString();} httpRequest.Headers.Add("Authorization", key.ToString()); log.LogInformation(key); log.LogInformation(httpRequest.ToString()); var response = httpclient.SendAsync(httpRequest).Result;

//response = response.ToString() var responseJson = response.Content.ReadAsStringAsync().Result; if (responseJson != null) { JObject json = new JObject(); dynamic obj = JsonConvert.DeserializeObject(responseJson); json = (JObject)obj; results = json.SelectToken("results"); return new OkObjectResult(results); } return new OkObjectResult(results); }

NinaSec avatar Mar 15 '23 11:03 NinaSec

Hi @NinaSec, thank you very much for the code you provided; it has been extremely helpful to us! May I inquire which template you are using? We are utilizing this Fortinet SOAR: https://github.com/Azure/Azure-Sentinel/tree/master/Solutions/Fortinet%20FortiGate%20Next-Generation%20Firewall%20connector%20for%20Microsoft%20Sentinel/Playbooks/FortinetFortigateFunctionApp. However, its runtime version is 3.2, which is already out of support.

cryanskl avatar Dec 08 '23 04:12 cryanskl