|
2 | 2 | "cells": [
|
3 | 3 | {
|
4 | 4 | "cell_type": "markdown",
|
| 5 | + "id": "9d7f1f15771d055c", |
| 6 | + "metadata": { |
| 7 | + "collapsed": false |
| 8 | + }, |
5 | 9 | "source": [
|
6 | 10 | "# A1000 dynamic analysis API\n",
|
7 | 11 | "This notebook explains how to fetch the dynamic analysis results from your instance of A1000. This API only fetches the analysis results. To submit a file for dynamic analysis on A1000, do so while uploading the file or while reanalyzing it. \n",
|
8 | 12 | "**NOTE:** If pasted into a Python file in the displayed order, all code cells can also work as a Python script."
|
9 |
| - ], |
10 |
| - "metadata": { |
11 |
| - "collapsed": false |
12 |
| - }, |
13 |
| - "id": "9d7f1f15771d055c" |
| 13 | + ] |
14 | 14 | },
|
15 | 15 | {
|
16 | 16 | "cell_type": "markdown",
|
| 17 | + "id": "fa10448d71096650", |
| 18 | + "metadata": { |
| 19 | + "collapsed": false |
| 20 | + }, |
17 | 21 | "source": [
|
18 | 22 | "### Credentials\n",
|
19 | 23 | "Credentials are loaded from a local file instead of being written here in plain text.\n",
|
20 | 24 | "To learn how to creat the credentials file, see the **Storing and using the credentials** section in the [README file](./README.md) "
|
21 |
| - ], |
22 |
| - "metadata": { |
23 |
| - "collapsed": false |
24 |
| - }, |
25 |
| - "id": "fa10448d71096650" |
| 25 | + ] |
26 | 26 | },
|
27 | 27 | {
|
28 | 28 | "cell_type": "markdown",
|
29 |
| - "source": [ |
30 |
| - "### 1. Import the A1000 class" |
31 |
| - ], |
| 29 | + "id": "cf14d328ce34f928", |
32 | 30 | "metadata": {
|
33 | 31 | "collapsed": false
|
34 | 32 | },
|
35 |
| - "id": "cf14d328ce34f928" |
| 33 | + "source": [ |
| 34 | + "### 1. Import the A1000 class" |
| 35 | + ] |
36 | 36 | },
|
37 | 37 | {
|
38 | 38 | "cell_type": "code",
|
39 | 39 | "execution_count": null,
|
| 40 | + "id": "13ba76c5b7e61c6e", |
| 41 | + "metadata": {}, |
40 | 42 | "outputs": [],
|
41 | 43 | "source": [
|
42 | 44 | "from ReversingLabs.SDK.a1000 import A1000"
|
43 |
| - ], |
44 |
| - "metadata": { |
45 |
| - "collapsed": false |
46 |
| - }, |
47 |
| - "id": "13ba76c5b7e61c6e" |
| 45 | + ] |
48 | 46 | },
|
49 | 47 | {
|
50 | 48 | "cell_type": "markdown",
|
| 49 | + "id": "ef3b6b1a2b1a61b1", |
| 50 | + "metadata": { |
| 51 | + "collapsed": false |
| 52 | + }, |
51 | 53 | "source": [
|
52 | 54 | "### 2. Loading the credentials\n",
|
53 | 55 | "Next, we will load our A1000 credentials and host URL from the local `a1000_credentials.json` file.\n",
|
54 | 56 | "**NOTE: Instead of doing this step, you can paste your credentials while creating the Python object in the following step.**"
|
55 |
| - ], |
56 |
| - "metadata": { |
57 |
| - "collapsed": false |
58 |
| - }, |
59 |
| - "id": "ef3b6b1a2b1a61b1" |
| 57 | + ] |
60 | 58 | },
|
61 | 59 | {
|
62 | 60 | "cell_type": "code",
|
63 | 61 | "execution_count": null,
|
| 62 | + "id": "d2992f910f3e1562", |
| 63 | + "metadata": {}, |
64 | 64 | "outputs": [],
|
65 | 65 | "source": [
|
66 | 66 | "import json\n",
|
|
69 | 69 | "CREDENTIALS = json.load(open(\"a1000_credentials.json\"))\n",
|
70 | 70 | "HOST = CREDENTIALS.get(\"host\")\n",
|
71 | 71 | "TOKEN = CREDENTIALS.get(\"token\")\n",
|
72 |
| - "USER_AGENT = \"ReversingLabs SDK Cookbook v1.0.2\"" |
73 |
| - ], |
74 |
| - "metadata": { |
75 |
| - "collapsed": false |
76 |
| - }, |
77 |
| - "id": "d2992f910f3e1562" |
| 72 | + "USER_AGENT = json.load(open('../user_agent.json'))[\"user_agent\"]" |
| 73 | + ] |
78 | 74 | },
|
79 | 75 | {
|
80 | 76 | "cell_type": "markdown",
|
| 77 | + "id": "ab56f879c48f8bd1", |
| 78 | + "metadata": { |
| 79 | + "collapsed": false |
| 80 | + }, |
81 | 81 | "source": [
|
82 | 82 | "#### 3. Creating an A1000 object\n",
|
83 | 83 | "First let us create an object out of the A1000 class. Unlike the `ticloud` module, the `a1000` module has only one class for all its methods (API-s).\n",
|
84 | 84 | "Having that in mind, we will create our A1000 object:"
|
85 |
| - ], |
86 |
| - "metadata": { |
87 |
| - "collapsed": false |
88 |
| - }, |
89 |
| - "id": "ab56f879c48f8bd1" |
| 85 | + ] |
90 | 86 | },
|
91 | 87 | {
|
92 | 88 | "cell_type": "code",
|
93 | 89 | "execution_count": null,
|
| 90 | + "id": "5e1223dba726bae7", |
| 91 | + "metadata": {}, |
94 | 92 | "outputs": [],
|
95 | 93 | "source": [
|
96 | 94 | "a1000 = A1000(\n",
|
|
99 | 97 | " verify=False,\n",
|
100 | 98 | " user_agent=USER_AGENT\n",
|
101 | 99 | ")"
|
102 |
| - ], |
103 |
| - "metadata": { |
104 |
| - "collapsed": false |
105 |
| - }, |
106 |
| - "id": "5e1223dba726bae7" |
| 100 | + ] |
107 | 101 | },
|
108 | 102 | {
|
109 | 103 | "cell_type": "markdown",
|
110 |
| - "source": [ |
111 |
| - "**NOTE:** Set the `verify` parameter to `True` or `False` depending on whether you want your server certificates to be validated or ignored." |
112 |
| - ], |
| 104 | + "id": "d18c338fedb2fd8a", |
113 | 105 | "metadata": {
|
114 | 106 | "collapsed": false
|
115 | 107 | },
|
116 |
| - "id": "d18c338fedb2fd8a" |
| 108 | + "source": [ |
| 109 | + "**NOTE:** Set the `verify` parameter to `True` or `False` depending on whether you want your server certificates to be validated or ignored." |
| 110 | + ] |
117 | 111 | },
|
118 | 112 | {
|
119 | 113 | "cell_type": "markdown",
|
| 114 | + "id": "30bf83a9c10f8058", |
| 115 | + "metadata": { |
| 116 | + "collapsed": false |
| 117 | + }, |
120 | 118 | "source": [
|
121 | 119 | "### 4. Getting the dynamic analysis results\n",
|
122 | 120 | "To get the dynamic analysis results for a file from A1000, we have three steps:\n",
|
123 | 121 | "- Requesting a report and its format (PDF or HTML)\n",
|
124 | 122 | "- Checking the report creation status\n",
|
125 | 123 | "- Downloading the report"
|
126 |
| - ], |
127 |
| - "metadata": { |
128 |
| - "collapsed": false |
129 |
| - }, |
130 |
| - "id": "30bf83a9c10f8058" |
| 124 | + ] |
131 | 125 | },
|
132 | 126 | {
|
133 | 127 | "cell_type": "markdown",
|
134 |
| - "source": [ |
135 |
| - "#### Requesting a report\n", |
136 |
| - "First we need to request a report creation task and define the report format that we want." |
137 |
| - ], |
| 128 | + "id": "7f40c39da72ad6de", |
138 | 129 | "metadata": {
|
139 | 130 | "collapsed": false
|
140 | 131 | },
|
141 |
| - "id": "7f40c39da72ad6de" |
| 132 | + "source": [ |
| 133 | + "#### Requesting a report\n", |
| 134 | + "First we need to request a report creation task and define the report format that we want." |
| 135 | + ] |
142 | 136 | },
|
143 | 137 | {
|
144 | 138 | "cell_type": "code",
|
145 | 139 | "execution_count": null,
|
| 140 | + "id": "de98440b912ff8e1", |
| 141 | + "metadata": {}, |
146 | 142 | "outputs": [],
|
147 | 143 | "source": [
|
148 | 144 | "response = a1000.create_dynamic_analysis_report(\n",
|
|
151 | 147 | ")\n",
|
152 | 148 | "\n",
|
153 | 149 | "print(response.text)"
|
154 |
| - ], |
155 |
| - "metadata": { |
156 |
| - "collapsed": false |
157 |
| - }, |
158 |
| - "id": "de98440b912ff8e1" |
| 150 | + ] |
159 | 151 | },
|
160 | 152 | {
|
161 | 153 | "cell_type": "markdown",
|
| 154 | + "id": "fc224ffe106193bd", |
| 155 | + "metadata": { |
| 156 | + "collapsed": false |
| 157 | + }, |
162 | 158 | "source": [
|
163 | 159 | "In our example, we requested a PDF report.\n",
|
164 | 160 | "\n",
|
165 | 161 | "\n",
|
166 | 162 | "#### Checking the report creation status\n",
|
167 | 163 | "Next, we can check the status of our report creation task. This step is not mandatory but is useful for knowing if our report is ready or not."
|
168 |
| - ], |
169 |
| - "metadata": { |
170 |
| - "collapsed": false |
171 |
| - }, |
172 |
| - "id": "fc224ffe106193bd" |
| 164 | + ] |
173 | 165 | },
|
174 | 166 | {
|
175 | 167 | "cell_type": "code",
|
176 | 168 | "execution_count": null,
|
| 169 | + "id": "78cf3e1a71f9a7e8", |
| 170 | + "metadata": {}, |
177 | 171 | "outputs": [],
|
178 | 172 | "source": [
|
179 | 173 | "response = a1000.check_dynamic_analysis_report_status(\n",
|
|
182 | 176 | ")\n",
|
183 | 177 | "\n",
|
184 | 178 | "print(response.text)"
|
185 |
| - ], |
186 |
| - "metadata": { |
187 |
| - "collapsed": false |
188 |
| - }, |
189 |
| - "id": "78cf3e1a71f9a7e8" |
| 179 | + ] |
190 | 180 | },
|
191 | 181 | {
|
192 | 182 | "cell_type": "markdown",
|
| 183 | + "id": "7ce55b15cbf69400", |
| 184 | + "metadata": { |
| 185 | + "collapsed": false |
| 186 | + }, |
193 | 187 | "source": [
|
194 | 188 | "By printing out the response message, we can see the status of our report creation task. \n",
|
195 | 189 | "\n",
|
196 | 190 | "\n",
|
197 | 191 | "#### Downloading the report\n",
|
198 | 192 | "If the report is ready, we can proceed to downloading it."
|
199 |
| - ], |
200 |
| - "metadata": { |
201 |
| - "collapsed": false |
202 |
| - }, |
203 |
| - "id": "7ce55b15cbf69400" |
| 193 | + ] |
204 | 194 | },
|
205 | 195 | {
|
206 | 196 | "cell_type": "code",
|
207 | 197 | "execution_count": null,
|
| 198 | + "id": "1505a364a3325af8", |
| 199 | + "metadata": {}, |
208 | 200 | "outputs": [],
|
209 | 201 | "source": [
|
210 | 202 | "response = a1000.download_dynamic_analysis_report(\n",
|
|
214 | 206 | "\n",
|
215 | 207 | "with open(\"report.pdf\", \"wb\") as file_handle:\n",
|
216 | 208 | " file_handle.write(response.content)"
|
217 |
| - ], |
218 |
| - "metadata": { |
219 |
| - "collapsed": false |
220 |
| - }, |
221 |
| - "id": "1505a364a3325af8" |
| 209 | + ] |
222 | 210 | },
|
223 | 211 | {
|
224 | 212 | "cell_type": "markdown",
|
225 |
| - "source": [ |
226 |
| - "Here we had to open a new empty PDF file and write the report's binary contents into it." |
227 |
| - ], |
| 213 | + "id": "bbdc335c300acfec", |
228 | 214 | "metadata": {
|
229 | 215 | "collapsed": false
|
230 | 216 | },
|
231 |
| - "id": "bbdc335c300acfec" |
| 217 | + "source": [ |
| 218 | + "Here we had to open a new empty PDF file and write the report's binary contents into it." |
| 219 | + ] |
232 | 220 | }
|
233 | 221 | ],
|
234 | 222 | "metadata": {
|
235 |
| - "kernelspec": { |
236 |
| - "display_name": "Python 3", |
237 |
| - "language": "python", |
238 |
| - "name": "python3" |
239 |
| - }, |
240 | 223 | "language_info": {
|
241 |
| - "codemirror_mode": { |
242 |
| - "name": "ipython", |
243 |
| - "version": 2 |
244 |
| - }, |
245 |
| - "file_extension": ".py", |
246 |
| - "mimetype": "text/x-python", |
247 |
| - "name": "python", |
248 |
| - "nbconvert_exporter": "python", |
249 |
| - "pygments_lexer": "ipython2", |
250 |
| - "version": "2.7.6" |
| 224 | + "name": "python" |
251 | 225 | }
|
252 | 226 | },
|
253 | 227 | "nbformat": 4,
|
|
0 commit comments