{"id":12750,"date":"2016-03-15T10:15:53","date_gmt":"2016-03-15T17:15:53","guid":{"rendered":"https:\/\/www.paloaltonetworks.com\/blog\/?p=12750"},"modified":"2016-03-15T10:29:14","modified_gmt":"2016-03-15T17:29:14","slug":"now-available-open-sourced-autofocus-python-client-library","status":"publish","type":"post","link":"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/2016\/03\/now-available-open-sourced-autofocus-python-client-library\/","title":{"rendered":"Now Available: Open-Sourced AutoFocus Python Client Library"},"content":{"rendered":"<p>Palo Alto Networks is proud to announce the public release of a <a href=\"https:\/\/github.com\/PaloAltoNetworks\/autofocus-client-library\" rel=\"nofollow,noopener\"  target=\"_blank\">Python client library<\/a> for interacting with our AutoFocus API.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/products\/secure-the-network\/subscriptions\/autofocus.html\" target=\"_blank\">AutoFocus<\/a> was released last year to provide actionable threat intelligence and prioritized alerts for organizations by combining data collected from thousands of <a href=\"https:\/\/www.paloaltonetworks.com\/products\/secure-the-network\/subscriptions\/wildfire.html\">WildFire<\/a> customers, Unit 42 threat research, and other cyber security intelligence feeds drawn from vendor and other third party partnerships.<\/p>\n<p>For many of you currently subscribed to AutoFocus, previous interaction with the service may have been purely through our user interface and alert notifications. However, it is important to remember that data is also exposed via an <a href=\"https:\/\/www.paloaltonetworks.com\/documentation\/autofocus\/autofocus\/autofocus_api\/about-the-autofocus-api.html\" target=\"_blank\">API<\/a>. After our own internal research usage of querying the API, we realized the importance of creating an object-oriented library to simplify querying the data and work with the results, which led to the creation of this library. It provides a quick way to begin interacting with the AutoFocus API without requiring a detailed understanding of the API service calls, response formats and parsing, error handling, or other steps.<\/p>\n<p>Here\u2019s how to get started with the API so you can easily integrate AutoFocus intelligence into your own systems and applications.<\/p>\n<p><!--more--><\/p>\n<p>First, you will need an API key. You can find and manage your AutoFocus API key by <a href=\"https:\/\/autofocus.paloaltonetworks.com\" target=\"_blank\">logging in<\/a> and clicking \u2018Settings\u2019 from the navigation menu.<\/p>\n<p><a href=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/03\/AutoFocus-Python-1-1.png\" rel=\"attachment wp-att-12760\"><div style=\"max-width:100%\" data-width=\"367\"><span class=\"ar-custom\" style=\"padding-bottom:82.83%;\"><img loading=\"lazy\" decoding=\"async\"  class=\"aligncenter size-full wp-image-12760 lozad\"  data-src=\"https:\/\/www.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/03\/AutoFocus-Python-1-1.png\" alt=\"AutoFocus Python 1\" width=\"367\" height=\"304\" srcset=\"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/03\/AutoFocus-Python-1-1.png 367w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/03\/AutoFocus-Python-1-1-230x191.png 230w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/03\/AutoFocus-Python-1-1-362x300.png 362w, https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-content\/uploads\/2016\/03\/AutoFocus-Python-1-1-48x40.png 48w\" sizes=\"auto, (max-width: 367px) 100vw, 367px\" \/><\/span><\/div><\/a><\/p>\n<p style=\"text-align: center;\">Figure 1 Identifying your AutoFocus API key from the UI<\/p>\n<pre class=\"lang:default decode:true \">[autofocus]\r\napikey=&lt;your_api_key&gt;\r\n<\/pre>\n<p>You can alternatively add your API key within any script you write rather than loading from a configuration file.<\/p>\n<pre class=\"lang:default decode:true \">from autofocus import AutoFocusAPI\r\nAutoFocusAPI.api_key = \u201c&lt;your_api_key&gt;\u201d\r\n<\/pre>\n<p>Finally, install the library and you are all set.<\/p>\n<pre class=\"lang:default decode:true \">git clone https:\/\/github.com\/PaloAltoNetworks\/autofocus-client-library\r\ncd autofocus-client-library\r\npython setup.py install\r\n<\/pre>\n<p>We will demonstrate usage through a simple but fully working Python example utilizing the client. This example will begin by querying for a specific sample using the sample\u2019s SHA256 hash. It continues to provide information about the file, such as the file type, WildFire verdict, and DNS queries made by the sample within the WildFire sandbox. Finally, a very simplistic search is performed to identify malicious samples found within AutoFocus.<\/p>\n<pre class=\"lang:default decode:true \">from autofocus import AutoFocusAPI, AFSample, AFSampleAbsent, AFDnsActivity\r\nAutoFocusAPI.api_key = \"&lt;your_api_key&gt;\"\r\n\r\n# Query for a sample and pull DNS activity associated with it\r\ntry:\r\n  sample = AFSample.get(\"7f38fd3e55a4139d788a4475ab0a5d83bf7686a37ef5e54a65364a0d781b523c\")\r\n\r\n  # Print some data that's available\r\n  print sample.sha256\r\n  print sample.file_type\r\n  if sample.malware:\r\n    print \"This is a malicious file\"\r\n\r\n  # Extract any DNS queries seen across WildFire analysis jobs for sample\r\n  for dns in sample.get_analyses(AFDnsActivity):\r\n    print \"Query: {0}\".format(dns.query)\r\n\r\nexcept AFSampleAbsent:\r\n  print \"That sample wasn't found.\"\r\n\r\n# Run AutoFocus search to discover samples matching criteria\r\n# See AF documentation for query format, or export a query via UI to get started\r\nquery = '{\"operator\": \"all\", \"children\": [{\"field\": \"sample.malware\", \"operator\": \"is\", \"value\": 1}]}'\r\n\r\nfor sample in AFSample.search(query):\r\n  print sample.sha256\r\n<\/pre>\n<p>This is a basic example, but it demonstrates the ease of using the API and working with the results. Through the library, you can also search AutoFocus session data (AFSession object) just as easily using a similar syntax. Behind the scenes, the library will handle authenticating to the web service, parsing responses into objects, creation of exceptions, and more. More examples and details on the library can be found on <a href=\"https:\/\/github.com\/PaloAltoNetworks\/autofocus-client-library\/tree\/master\/examples\" rel=\"nofollow,noopener\"  target=\"_blank\">GitHub<\/a>.<\/p>\n<p>We invite you to begin using the tool to further automate your own internal processes and usage of the <a href=\"https:\/\/github.com\/PaloAltoNetworks\/autofocus-client-library\" rel=\"nofollow,noopener\" >AutoFocus API<\/a>.<\/p>\n<p>For more information, please visit the\u00a0<a href=\"https:\/\/www.paloaltonetworks.com\/products\/secure-the-network\/subscriptions\/autofocus\" target=\"_blank\">AutoFocus website<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Palo Alto Networks is proud to announce the public release of a Python client library for interacting with our AutoFocus API. AutoFocus was released last year to provide actionable threat intelligence and &hellip;<\/p>\n","protected":false},"author":40,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[308,416,566],"tags":[1132,1684,1756,1832],"coauthors":[1833,1834],"class_list":["post-12750","post","type-post","status-publish","format-standard","hentry","category-announcement","category-financial-services","category-scada-ics","tag-autofocus","tag-autofocus-api","tag-python","tag-wildfi"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-json\/wp\/v2\/posts\/12750","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-json\/wp\/v2\/users\/40"}],"replies":[{"embeddable":true,"href":"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-json\/wp\/v2\/comments?post=12750"}],"version-history":[{"count":4,"href":"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-json\/wp\/v2\/posts\/12750\/revisions"}],"predecessor-version":[{"id":12759,"href":"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-json\/wp\/v2\/posts\/12750\/revisions\/12759"}],"wp:attachment":[{"href":"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-json\/wp\/v2\/media?parent=12750"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-json\/wp\/v2\/categories?post=12750"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-json\/wp\/v2\/tags?post=12750"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/origin-researchcenter.paloaltonetworks.com\/blog\/wp-json\/wp\/v2\/coauthors?post=12750"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}