|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "source": [ |
| 6 | + "# Directory Scanning\n", |
| 7 | + "This notebook contains and example of how to use the ReversingLabs SDK to **collect files from a local directory and send them for analysis on TitaniumCloud and A1000**." |
| 8 | + ], |
| 9 | + "metadata": { |
| 10 | + "collapsed": false |
| 11 | + }, |
| 12 | + "id": "b8d2177c5214b66a" |
| 13 | + }, |
| 14 | + { |
| 15 | + "cell_type": "markdown", |
| 16 | + "source": [ |
| 17 | + "### Used TitaniumCloud classes\n", |
| 18 | + "- **FileUpload** (*TCA-0202-0203 - File Upload*)\n", |
| 19 | + "\n", |
| 20 | + "### Used A1000 functions\n", |
| 21 | + "- **upload_sample_from_path**\n", |
| 22 | + "\n", |
| 23 | + "### Credentials\n", |
| 24 | + "Credentials are loaded from a local file instead of being written here in plain text.\n", |
| 25 | + "To learn how to creat the credentials file, see the **Storing and using the credentials** section in the [README file](./README.md)" |
| 26 | + ], |
| 27 | + "metadata": { |
| 28 | + "collapsed": false |
| 29 | + }, |
| 30 | + "id": "3c66cec58fcbe655" |
| 31 | + }, |
| 32 | + { |
| 33 | + "cell_type": "markdown", |
| 34 | + "source": [ |
| 35 | + "### 1. Scanning the files with TitaniumCloud\n", |
| 36 | + "To collect files from a local directory and send them for analysis on TitaniumCloud, see the following code example. " |
| 37 | + ], |
| 38 | + "metadata": { |
| 39 | + "collapsed": false |
| 40 | + }, |
| 41 | + "id": "67ada420ce3509a" |
| 42 | + }, |
| 43 | + { |
| 44 | + "cell_type": "code", |
| 45 | + "execution_count": null, |
| 46 | + "outputs": [], |
| 47 | + "source": [ |
| 48 | + "import json\n", |
| 49 | + "import os\n", |
| 50 | + "from ReversingLabs.SDK.ticloud import FileUpload\n", |
| 51 | + "\n", |
| 52 | + "# Linux and Unix systems - Edit before use\n", |
| 53 | + "FOLDER_PATH_LINUX = \"/full/path/to/folder\"\n", |
| 54 | + "\n", |
| 55 | + "# Windows systems - Edit before use\n", |
| 56 | + "FOLDER_PATH_WINDOWS = \"C:\\\\full\\\\path\\\\to\\\\folder\"\n", |
| 57 | + "\n", |
| 58 | + "# Change this so the FOLDER_PATH variable fits your local system\n", |
| 59 | + "FOLDER_PATH = FOLDER_PATH_LINUX\n", |
| 60 | + "\n", |
| 61 | + "CREDENTIALS = json.load(open(\"credentials.json\"))\n", |
| 62 | + "USERNAME = CREDENTIALS.get(\"ticloud\").get(\"username\")\n", |
| 63 | + "PASSWORD = CREDENTIALS.get(\"ticloud\").get(\"password\")\n", |
| 64 | + "\n", |
| 65 | + "\n", |
| 66 | + "file_upload = FileUpload(\n", |
| 67 | + " host=\"https://data.reversinglabs.com\",\n", |
| 68 | + " username=USERNAME,\n", |
| 69 | + " password=PASSWORD\n", |
| 70 | + ")\n", |
| 71 | + "\n", |
| 72 | + "# Files that should not be analyzed can be added to this list\n", |
| 73 | + "skip_files = [\"file_name_1\", \"file_name_2\"]\n", |
| 74 | + "\n", |
| 75 | + "\n", |
| 76 | + "for file_name in os.listdir(FOLDER_PATH):\n", |
| 77 | + " if file_name in skip_files:\n", |
| 78 | + " continue\n", |
| 79 | + " \n", |
| 80 | + " file_path = os.path.join(FOLDER_PATH, file_name)\n", |
| 81 | + " \n", |
| 82 | + " try:\n", |
| 83 | + " file_upload.upload_sample_from_path(file_path=file_path)\n", |
| 84 | + " \n", |
| 85 | + " except Exception as e:\n", |
| 86 | + " if hasattr(e, \"response_object\"):\n", |
| 87 | + " raise Exception(e.response_object.content)\n", |
| 88 | + " \n", |
| 89 | + " raise \n" |
| 90 | + ], |
| 91 | + "metadata": { |
| 92 | + "collapsed": false |
| 93 | + }, |
| 94 | + "id": "9c39940f6b968b5" |
| 95 | + }, |
| 96 | + { |
| 97 | + "cell_type": "markdown", |
| 98 | + "source": [ |
| 99 | + "### 2. Scanning the files with A1000\n", |
| 100 | + "To collect files from a local directory and send them for analysis on A1000, see the following code example." |
| 101 | + ], |
| 102 | + "metadata": { |
| 103 | + "collapsed": false |
| 104 | + }, |
| 105 | + "id": "987943a79bf60f06" |
| 106 | + }, |
| 107 | + { |
| 108 | + "cell_type": "code", |
| 109 | + "execution_count": null, |
| 110 | + "outputs": [], |
| 111 | + "source": [ |
| 112 | + "import json\n", |
| 113 | + "import os\n", |
| 114 | + "from ReversingLabs.SDK.a1000 import A1000\n", |
| 115 | + "\n", |
| 116 | + "# Linux and Unix systems - Edit before use\n", |
| 117 | + "FOLDER_PATH_LINUX = \"/full/path/to/folder\"\n", |
| 118 | + "\n", |
| 119 | + "# Windows systems - Edit before use\n", |
| 120 | + "FOLDER_PATH_WINDOWS = \"C:\\\\full\\\\path\\\\to\\\\folder\"\n", |
| 121 | + "\n", |
| 122 | + "# Change this so the FOLDER_PATH variable fits your local system\n", |
| 123 | + "FOLDER_PATH = FOLDER_PATH_LINUX\n", |
| 124 | + "\n", |
| 125 | + "CREDENTIALS = json.load(open(\"credentials.json\"))\n", |
| 126 | + "HOST = CREDENTIALS.get(\"a1000\").get(\"a1000_url\")\n", |
| 127 | + "TOKEN = CREDENTIALS.get(\"a1000\").get(\"token\")\n", |
| 128 | + "\n", |
| 129 | + "# Set the verify parameter to False if your A1000 instance doesn't have a valid CA certificate\n", |
| 130 | + "a1000 = A1000(\n", |
| 131 | + " host=HOST,\n", |
| 132 | + " token=TOKEN,\n", |
| 133 | + " verify=True\n", |
| 134 | + ")\n", |
| 135 | + "\n", |
| 136 | + "# Files that should not be analyzed can be added to this list\n", |
| 137 | + "skip_files = [\"file_name_1\", \"file_name_2\"]\n", |
| 138 | + "\n", |
| 139 | + "for file_name in os.listdir(FOLDER_PATH):\n", |
| 140 | + " if file_name in skip_files:\n", |
| 141 | + " continue\n", |
| 142 | + " \n", |
| 143 | + " file_path = os.path.join(FOLDER_PATH, file_name)\n", |
| 144 | + " \n", |
| 145 | + " try:\n", |
| 146 | + " a1000.upload_sample_from_path(file_path=file_path)\n", |
| 147 | + " \n", |
| 148 | + " except Exception as e:\n", |
| 149 | + " if hasattr(e, \"response_object\"):\n", |
| 150 | + " raise Exception(e.response_object.content)\n", |
| 151 | + " \n", |
| 152 | + " raise \n" |
| 153 | + ], |
| 154 | + "metadata": { |
| 155 | + "collapsed": false |
| 156 | + }, |
| 157 | + "id": "6b6774a15517020b" |
| 158 | + } |
| 159 | + ], |
| 160 | + "metadata": { |
| 161 | + "kernelspec": { |
| 162 | + "display_name": "Python 3", |
| 163 | + "language": "python", |
| 164 | + "name": "python3" |
| 165 | + }, |
| 166 | + "language_info": { |
| 167 | + "codemirror_mode": { |
| 168 | + "name": "ipython", |
| 169 | + "version": 2 |
| 170 | + }, |
| 171 | + "file_extension": ".py", |
| 172 | + "mimetype": "text/x-python", |
| 173 | + "name": "python", |
| 174 | + "nbconvert_exporter": "python", |
| 175 | + "pygments_lexer": "ipython2", |
| 176 | + "version": "2.7.6" |
| 177 | + } |
| 178 | + }, |
| 179 | + "nbformat": 4, |
| 180 | + "nbformat_minor": 5 |
| 181 | +} |
0 commit comments