├── .gitignore ├── LICENSE ├── README.md ├── build_grpc.sh ├── pcap_processor ├── __init__.py ├── __main__.py ├── commons.py ├── grpc │ ├── WisdomGrpcService_pb2.py │ ├── WisdomGrpcService_pb2_grpc.py │ └── __init__.py ├── map_manager.py ├── plugin.py ├── plugin_manager.py ├── plugins │ ├── __init__.py │ ├── console_sink.py │ ├── csv_sink.py │ ├── grpc_sink.py │ ├── http_sink.py │ ├── kafka_sink.py │ ├── length_mapper.py │ └── protocol_mapper.py ├── reader.py ├── resources │ └── logging.yaml └── sink.py ├── proto └── WisdomGrpcService.proto ├── requirements.txt ├── samples ├── cicids_2017.csv ├── cicids_2017.pcap ├── darpa_99.csv └── darpa_99.pcap └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | 49 | # Translations 50 | *.mo 51 | *.pot 52 | 53 | # Django stuff: 54 | *.log 55 | local_settings.py 56 | 57 | # Flask stuff: 58 | instance/ 59 | .webassets-cache 60 | 61 | # Scrapy stuff: 62 | .scrapy 63 | 64 | # Sphinx documentation 65 | docs/_build/ 66 | 67 | # PyBuilder 68 | target/ 69 | 70 | # Jupyter Notebook 71 | .ipynb_checkpoints 72 | 73 | # pyenv 74 | .python-version 75 | 76 | # celery beat schedule file 77 | celerybeat-schedule 78 | 79 | # SageMath parsed files 80 | *.sage.py 81 | 82 | # dotenv 83 | .env 84 | 85 | # virtualenv 86 | .venv 87 | venv/ 88 | ENV/ 89 | 90 | # Spyder project settings 91 | .spyderproject 92 | .spyproject 93 | 94 | # Rope project settings 95 | .ropeproject 96 | 97 | # mkdocs documentation 98 | /site 99 | 100 | # mypy 101 | .mypy_cache/ 102 | 103 | # PyCharm 104 | .idea/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pcap Processor 2 | Read and process pcap files using this nifty tool. 3 | 4 | This tool can read pcap files, process them internally and write them to one or more sinks. 5 | Currently there are mappers written for pcap length conversion and protocol normalization. 6 | I also have written sinks to write the pcap file to console, csv file or http endpoint. 7 | 8 | ```text 9 | usage: pcap-processor [-h] [--map {length,protocol}] 10 | [--sink {console,kafka,http,csv,grpc}] [--version] 11 | file [file ...] 12 | 13 | Read and process pcap files using this nifty tool. 14 | 15 | positional arguments: 16 | file pcap file to read 17 | 18 | optional arguments: 19 | -h, --help show this help message and exit 20 | --map {length,protocol} 21 | enable a mapper with the given name. You can use this 22 | option multiple times to enable more than one mappers 23 | --sink {console,kafka,http,csv,grpc} 24 | enable a sink with the given name. You can use this 25 | option multiple times to enable more than one sinks 26 | --version show program's version number and exit 27 | ``` 28 | 29 | ## Note 30 | 31 | Currently the `pcap-processor` reads only packets with IP or IPV6 layers. Feel free to modify the code based on your requirement. If you find any enhancement, please send a Pull Request. 32 | 33 | ## Requirements 34 | 35 | pcap-reader relies on external command line tool: `tshark` and some Python modules. 36 | 37 | Install `tshark` using the following command in Ubuntu and its derivatives: 38 | 39 | ```bash 40 | sudo apt install tshark 41 | ``` 42 | 43 | Install Python dependencies using the following command: 44 | 45 | ```bash 46 | pip3 install -r requirements.txt 47 | ``` 48 | 49 | ## Research Work 50 | This tool is developed as part of my research project. If you are using this tool in your research, 51 | please cite the following paper: 52 | 53 | **Citation:** 54 | 55 | ```text 56 | Loganathan, G., Samarabandu, J., & Wang, X. (2018). Sequence to Sequence Pattern Learning Algorithm for Real-time Anomaly Detection in Network Traffic. In 2018 IEEE Canadian Conference on Electrical & Computer Engineering (CCECE) (CCECE 2018). Quebec City, Canada. 57 | ``` 58 | 59 | **BibTex** 60 | 61 | ```bibtex 62 | @INPROCEEDINGS{Loga1805:Sequence, 63 | AUTHOR="Gobinath Loganathan and Jagath Samarabandu and Xianbin Wang", 64 | TITLE="Sequence to Sequence Pattern Learning Algorithm for Real-time Anomaly 65 | Detection in Network Traffic", 66 | BOOKTITLE="2018 IEEE Canadian Conference on Electrical \& Computer Engineering (CCECE) 67 | (CCECE 2018)", 68 | ADDRESS="Quebec City, Canada", 69 | DAYS=13, 70 | MONTH=may, 71 | YEAR=2018, 72 | KEYWORDS="Seq2Seq; Anomaly Detection", 73 | ABSTRACT="Network intrusions can be modeled as anomalies in network traffic in which 74 | the expected order of packets and their attributes deviate from regular 75 | traffic. Algorithms that predict the next sequence of events based on 76 | previous sequences are a promising avenue for detecting such anomalies. In 77 | this paper, we present a novel multi-attribute model for predicting a 78 | network packet sequence based on previous packets using a 79 | sequence-to-sequence (Seq2Seq) encoder-decoder model. This model is trained 80 | on an attack-free dataset to learn the normal sequence of packets in TCP 81 | connections and then it is used to detect anomalous packets in TCP traffic. 82 | We show that in DARPA 1999 dataset, the proposed multi-attribute Seq2Seq 83 | model detects anomalous raw TCP packets which are part of intrusions with 84 | 97\% accuracy. Also, it can detect selected intrusions in real-time with 85 | 100\% accuracy and outperforms existing algorithms based on recurrent 86 | neural network models such as LSTM." 87 | } 88 | ``` 89 | 90 | ## Use Cases 91 | 92 | Read a pcap file and send all packets to Apache Kafka: 93 | 94 | ```bash 95 | python3 -m pcap_processor --sink kafka samples/cicids_2017.pcap 96 | ``` 97 | 98 | Read a pcap file, map protocols and write them to a CSV file: 99 | 100 | ```bash 101 | python3 -m pcap_processor --map protocol --sink csv samples/cicids_2017.pcap 102 | ``` 103 | 104 | Mappers and sinks have their own properties. Please modify them in the relevant `plugins/.py`. 105 | 106 | For example, to change the output CSV file location, modify the `self.path = "packets.csv"` in `pcap_processor/plugins/csv_sink.py`. -------------------------------------------------------------------------------- /build_grpc.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | python3 -m grpc_tools.protoc -I proto --python_out=pcap_processor/grpc --grpc_python_out=pcap_processor/grpc proto/WisdomGrpcService.proto -------------------------------------------------------------------------------- /pcap_processor/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # pcap-reader - Read and process pcap files using this nifty tool. 3 | 4 | # Copyright (C) 2018 Gobinath 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | import os 20 | 21 | BIN_DIRECTORY = os.path.dirname(os.path.realpath(__file__)) 22 | -------------------------------------------------------------------------------- /pcap_processor/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # pcap-reader - Read and process pcap files using this nifty tool. 3 | 4 | # Copyright (C) 2018 Gobinath 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | import argparse 20 | import os 21 | 22 | from pcap_processor import plugin_manager, commons 23 | from pcap_processor.reader import PcapReader 24 | 25 | 26 | def file_type(path): 27 | """ArgParse callable to validate positional add-on arguments 28 | 29 | Arguments: 30 | path {string} -- user defined argument 31 | 32 | Raises: 33 | argparse.ArgumentTypeError -- thrown when user input is not a directory or does not contain addon.xml 34 | 35 | Returns: 36 | string -- absolute path of the input directory 37 | """ 38 | if not os.path.exists(path): 39 | raise argparse.ArgumentTypeError( 40 | "Pcap file or directory %s does not exist" % path) 41 | return os.path.abspath(path) 42 | 43 | 44 | def main(): 45 | commons.setup_logging() 46 | plugin_manager.load_plugins() 47 | parser = argparse.ArgumentParser(prog="pcap-processor", 48 | description="Read and process pcap files using this nifty tool.") 49 | plugin_manager.fill_cmd_args(parser) 50 | parser.add_argument("--version", action="version", 51 | version="%(prog)s 0.0.1") 52 | parser.add_argument("file", type=file_type, nargs="+", help="pcap file to read") 53 | 54 | args = parser.parse_args() 55 | 56 | pcap_file = args.file 57 | plugin_manager.process_config(args) 58 | reader = PcapReader(pcap_file) 59 | reader.read() 60 | 61 | 62 | if __name__ == '__main__': 63 | main() 64 | -------------------------------------------------------------------------------- /pcap_processor/commons.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # pcap-reader - Read and process pcap files using this nifty tool. 3 | 4 | # Copyright (C) 2018 Gobinath 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | import logging 20 | import logging.config 21 | import os 22 | 23 | import yaml 24 | 25 | from pcap_processor import BIN_DIRECTORY 26 | 27 | DEFAULT_LOG_CONFIG = os.path.join(BIN_DIRECTORY, 'resources/logging.yaml') 28 | 29 | 30 | def colorPrint(message, color): 31 | print("\033[%sm%s\033[0m" % (color, message)) 32 | 33 | 34 | def info(message): 35 | colorPrint(message, "34") 36 | 37 | 38 | def warn(message): 39 | colorPrint(message, "35") 40 | 41 | 42 | def error(message): 43 | colorPrint(message, "31") 44 | 45 | 46 | def setup_logging(default_path=DEFAULT_LOG_CONFIG, default_level=logging.INFO, env_key='LOG_CFG'): 47 | """ 48 | Setup logging configuration 49 | """ 50 | path = default_path 51 | value = os.getenv(env_key, None) 52 | if value: 53 | path = value 54 | if os.path.exists(path): 55 | with open(path, 'rt') as f: 56 | config = yaml.safe_load(f.read()) 57 | logging.config.dictConfig(config) 58 | else: 59 | logging.basicConfig(level=default_level) 60 | -------------------------------------------------------------------------------- /pcap_processor/grpc/WisdomGrpcService_pb2.py: -------------------------------------------------------------------------------- 1 | # Generated by the protocol buffer compiler. DO NOT EDIT! 2 | # source: WisdomGrpcService.proto 3 | 4 | import sys 5 | 6 | _b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode('latin1')) 7 | from google.protobuf import descriptor as _descriptor 8 | from google.protobuf import message as _message 9 | from google.protobuf import reflection as _reflection 10 | from google.protobuf import symbol_database as _symbol_database 11 | from google.protobuf import descriptor_pb2 12 | 13 | # @@protoc_insertion_point(imports) 14 | 15 | _sym_db = _symbol_database.Default() 16 | 17 | DESCRIPTOR = _descriptor.FileDescriptor( 18 | name='WisdomGrpcService.proto', 19 | package='com.javahelps.wisdom.service.gprc', 20 | syntax='proto3', 21 | serialized_pb=_b( 22 | '\n\x17WisdomGrpcService.proto\x12!com.javahelps.wisdom.service.gprc\"\x15\n\x05\x45vent\x12\x0c\n\x04\x64\x61ta\x18\x01 \x01(\t2\xa3\x02\n\x06Wisdom\x12Z\n\x04send\x12(.com.javahelps.wisdom.service.gprc.Event\x1a(.com.javahelps.wisdom.service.gprc.Event\x12\\\n\x04\x66\x65\x65\x64\x12(.com.javahelps.wisdom.service.gprc.Event\x1a(.com.javahelps.wisdom.service.gprc.Event(\x01\x12_\n\x07receive\x12(.com.javahelps.wisdom.service.gprc.Event\x1a(.com.javahelps.wisdom.service.gprc.Event0\x01\x62\x06proto3') 23 | ) 24 | 25 | _EVENT = _descriptor.Descriptor( 26 | name='Event', 27 | full_name='com.javahelps.wisdom.service.gprc.Event', 28 | filename=None, 29 | file=DESCRIPTOR, 30 | containing_type=None, 31 | fields=[ 32 | _descriptor.FieldDescriptor( 33 | name='data', full_name='com.javahelps.wisdom.service.gprc.Event.data', index=0, 34 | number=1, type=9, cpp_type=9, label=1, 35 | has_default_value=False, default_value=_b("").decode('utf-8'), 36 | message_type=None, enum_type=None, containing_type=None, 37 | is_extension=False, extension_scope=None, 38 | options=None, file=DESCRIPTOR), 39 | ], 40 | extensions=[ 41 | ], 42 | nested_types=[], 43 | enum_types=[ 44 | ], 45 | options=None, 46 | is_extendable=False, 47 | syntax='proto3', 48 | extension_ranges=[], 49 | oneofs=[ 50 | ], 51 | serialized_start=62, 52 | serialized_end=83, 53 | ) 54 | 55 | DESCRIPTOR.message_types_by_name['Event'] = _EVENT 56 | _sym_db.RegisterFileDescriptor(DESCRIPTOR) 57 | 58 | Event = _reflection.GeneratedProtocolMessageType('Event', (_message.Message,), dict( 59 | DESCRIPTOR=_EVENT, 60 | __module__='WisdomGrpcService_pb2' 61 | # @@protoc_insertion_point(class_scope:com.javahelps.wisdom.service.gprc.Event) 62 | )) 63 | _sym_db.RegisterMessage(Event) 64 | 65 | _WISDOM = _descriptor.ServiceDescriptor( 66 | name='Wisdom', 67 | full_name='com.javahelps.wisdom.service.gprc.Wisdom', 68 | file=DESCRIPTOR, 69 | index=0, 70 | options=None, 71 | serialized_start=86, 72 | serialized_end=377, 73 | methods=[ 74 | _descriptor.MethodDescriptor( 75 | name='send', 76 | full_name='com.javahelps.wisdom.service.gprc.Wisdom.send', 77 | index=0, 78 | containing_service=None, 79 | input_type=_EVENT, 80 | output_type=_EVENT, 81 | options=None, 82 | ), 83 | _descriptor.MethodDescriptor( 84 | name='feed', 85 | full_name='com.javahelps.wisdom.service.gprc.Wisdom.feed', 86 | index=1, 87 | containing_service=None, 88 | input_type=_EVENT, 89 | output_type=_EVENT, 90 | options=None, 91 | ), 92 | _descriptor.MethodDescriptor( 93 | name='receive', 94 | full_name='com.javahelps.wisdom.service.gprc.Wisdom.receive', 95 | index=2, 96 | containing_service=None, 97 | input_type=_EVENT, 98 | output_type=_EVENT, 99 | options=None, 100 | ), 101 | ]) 102 | _sym_db.RegisterServiceDescriptor(_WISDOM) 103 | 104 | DESCRIPTOR.services_by_name['Wisdom'] = _WISDOM 105 | 106 | # @@protoc_insertion_point(module_scope) 107 | -------------------------------------------------------------------------------- /pcap_processor/grpc/WisdomGrpcService_pb2_grpc.py: -------------------------------------------------------------------------------- 1 | # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! 2 | import grpc 3 | 4 | from pcap_processor.grpc import WisdomGrpcService_pb2 as WisdomGrpcService__pb2 5 | 6 | 7 | class WisdomStub(object): 8 | # missing associated documentation comment in .proto file 9 | pass 10 | 11 | def __init__(self, channel): 12 | """Constructor. 13 | 14 | Args: 15 | channel: A grpc.Channel. 16 | """ 17 | self.send = channel.unary_unary( 18 | '/com.javahelps.wisdom.service.gprc.Wisdom/send', 19 | request_serializer=WisdomGrpcService__pb2.Event.SerializeToString, 20 | response_deserializer=WisdomGrpcService__pb2.Event.FromString, 21 | ) 22 | self.feed = channel.stream_unary( 23 | '/com.javahelps.wisdom.service.gprc.Wisdom/feed', 24 | request_serializer=WisdomGrpcService__pb2.Event.SerializeToString, 25 | response_deserializer=WisdomGrpcService__pb2.Event.FromString, 26 | ) 27 | self.receive = channel.unary_stream( 28 | '/com.javahelps.wisdom.service.gprc.Wisdom/receive', 29 | request_serializer=WisdomGrpcService__pb2.Event.SerializeToString, 30 | response_deserializer=WisdomGrpcService__pb2.Event.FromString, 31 | ) 32 | 33 | 34 | class WisdomServicer(object): 35 | # missing associated documentation comment in .proto file 36 | pass 37 | 38 | def send(self, request, context): 39 | # missing associated documentation comment in .proto file 40 | pass 41 | context.set_code(grpc.StatusCode.UNIMPLEMENTED) 42 | context.set_details('Method not implemented!') 43 | raise NotImplementedError('Method not implemented!') 44 | 45 | def feed(self, request_iterator, context): 46 | # missing associated documentation comment in .proto file 47 | pass 48 | context.set_code(grpc.StatusCode.UNIMPLEMENTED) 49 | context.set_details('Method not implemented!') 50 | raise NotImplementedError('Method not implemented!') 51 | 52 | def receive(self, request, context): 53 | # missing associated documentation comment in .proto file 54 | pass 55 | context.set_code(grpc.StatusCode.UNIMPLEMENTED) 56 | context.set_details('Method not implemented!') 57 | raise NotImplementedError('Method not implemented!') 58 | 59 | 60 | def add_WisdomServicer_to_server(servicer, server): 61 | rpc_method_handlers = { 62 | 'send': grpc.unary_unary_rpc_method_handler( 63 | servicer.send, 64 | request_deserializer=WisdomGrpcService__pb2.Event.FromString, 65 | response_serializer=WisdomGrpcService__pb2.Event.SerializeToString, 66 | ), 67 | 'feed': grpc.stream_unary_rpc_method_handler( 68 | servicer.feed, 69 | request_deserializer=WisdomGrpcService__pb2.Event.FromString, 70 | response_serializer=WisdomGrpcService__pb2.Event.SerializeToString, 71 | ), 72 | 'receive': grpc.unary_stream_rpc_method_handler( 73 | servicer.receive, 74 | request_deserializer=WisdomGrpcService__pb2.Event.FromString, 75 | response_serializer=WisdomGrpcService__pb2.Event.SerializeToString, 76 | ), 77 | } 78 | generic_handler = grpc.method_handlers_generic_handler( 79 | 'com.javahelps.wisdom.service.gprc.Wisdom', rpc_method_handlers) 80 | server.add_generic_rpc_handlers((generic_handler,)) 81 | -------------------------------------------------------------------------------- /pcap_processor/grpc/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # pcap-reader - Read and process pcap files using this nifty tool. 3 | 4 | # Copyright (C) 2018 Gobinath 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | -------------------------------------------------------------------------------- /pcap_processor/map_manager.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # pcap-reader - Read and process pcap files using this nifty tool. 3 | 4 | # Copyright (C) 2018 Gobinath 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | import inspect 20 | from abc import ABC 21 | 22 | from pcap_processor.plugin import Plugin 23 | 24 | 25 | class Map(ABC): 26 | 27 | def map(self, packet: dict): 28 | return packet 29 | 30 | 31 | class MapperManager(object): 32 | mappers = {} 33 | 34 | @classmethod 35 | def register(cls, mapper_clazz: Map, name, enabled): 36 | cls.mappers[name] = Plugin(mapper_clazz, enabled) 37 | 38 | @classmethod 39 | def enable(cls, names): 40 | """ 41 | Enable only the given list of names and disable the rest. 42 | :param names: list of reporter names 43 | :return: None 44 | """ 45 | for name, plugin in cls.mappers.items(): 46 | plugin.enabled = name in names 47 | 48 | @classmethod 49 | def map(cls, packet: dict): 50 | for plugin in cls.mappers.values(): 51 | if plugin.enabled: 52 | packet = plugin.instance.map(packet) 53 | return packet 54 | 55 | 56 | def mapper(name, enabled=False): 57 | def _mapper(clazz): 58 | if inspect.isclass(clazz): 59 | if not hasattr(clazz, "map") or len(inspect.signature(getattr(clazz, "map")).parameters.items()) != 2: 60 | raise RuntimeError("Map must have a function 'map(self, packet: dict)") 61 | else: 62 | raise RuntimeError("Map must be a class") 63 | 64 | # Register the mapper 65 | MapperManager.register(clazz, name, enabled) 66 | return clazz 67 | 68 | return _mapper 69 | -------------------------------------------------------------------------------- /pcap_processor/plugin.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # pcap-reader - Read and process pcap files using this nifty tool. 3 | 4 | # Copyright (C) 2018 Gobinath 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | class Plugin: 20 | def __init__(self, clazz, enabled=False): 21 | self.enabled = enabled 22 | self.clazz = clazz 23 | self.instance = clazz() 24 | -------------------------------------------------------------------------------- /pcap_processor/plugin_manager.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # pcap-reader - Read and process pcap files using this nifty tool. 3 | 4 | # Copyright (C) 2018 Gobinath 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | import importlib 20 | import os 21 | import pkgutil 22 | import sys 23 | from argparse import ArgumentParser 24 | 25 | from pcap_processor.map_manager import MapperManager 26 | from pcap_processor.sink import SinkManager 27 | 28 | 29 | def load_plugins(): 30 | plugins_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "plugins") 31 | sys.path.append(plugins_dir) 32 | for importer, package_name, _ in pkgutil.iter_modules([plugins_dir]): 33 | if "test_" not in package_name: 34 | importlib.import_module(package_name) 35 | 36 | 37 | def fill_cmd_args(parser: ArgumentParser): 38 | # Add --map 39 | parser.add_argument("--map", action="append", choices=list(MapperManager.mappers.keys()), 40 | help="""enable a mapper with the given name. 41 | You can use this option multiple times to enable more than one mappers""") 42 | parser.add_argument("--sink", action="append", choices=list(SinkManager.sinks.keys()), 43 | help="""enable a sink with the given name. 44 | You can use this option multiple times to enable more than one sinks""") 45 | 46 | 47 | def process_config(config): 48 | mappers = config.map 49 | sinks = config.sink 50 | if mappers is not None: 51 | MapperManager.enable(mappers) 52 | if sinks is not None: 53 | SinkManager.enable(sinks) 54 | -------------------------------------------------------------------------------- /pcap_processor/plugins/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # pcap-reader - Read and process pcap files using this nifty tool. 3 | 4 | # Copyright (C) 2018 Gobinath 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | -------------------------------------------------------------------------------- /pcap_processor/plugins/console_sink.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # pcap-reader - Read and process pcap files using this nifty tool. 3 | 4 | # Copyright (C) 2018 Gobinath 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | from pcap_processor.sink import sink, Sink 20 | 21 | 22 | @sink(name="console", enabled=True) 23 | class ConsoleSink(Sink): 24 | 25 | def write(self, packet: dict): 26 | print(packet) 27 | 28 | def close(self): 29 | pass 30 | -------------------------------------------------------------------------------- /pcap_processor/plugins/csv_sink.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # pcap-reader - Read and process pcap files using this nifty tool. 3 | 4 | # Copyright (C) 2018 Gobinath 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | import csv 20 | 21 | from pcap_processor.sink import sink, Sink 22 | 23 | 24 | @sink(name="csv", enabled=False) 25 | class CsvSink(Sink): 26 | 27 | def __init__(self): 28 | self.attributes = ['highest_layer', 'transport_layer', 'src_ip', 'dst_ip', 'src_port', 'dst_port', 29 | 'ip_flag', 'packet_length', 'transport_flag', 'time', 'timestamp', 'geo_country', 'data'] 30 | self.path = "packets.csv" 31 | 32 | def init(self): 33 | columns = ",".join(self.attributes) 34 | columns += "\r\n" 35 | with open(self.path, 'w') as fp: 36 | fp.write(columns) 37 | 38 | def write(self, packet: dict): 39 | with open(self.path, 'a') as output: 40 | writer = csv.writer(output, lineterminator='\n') 41 | row = [packet[attr] for attr in self.attributes] 42 | writer.writerow(row) 43 | 44 | def close(self): 45 | pass 46 | -------------------------------------------------------------------------------- /pcap_processor/plugins/grpc_sink.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # pcap-reader - Read and process pcap files using this nifty tool. 3 | 4 | # Copyright (C) 2018 Gobinath 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | import json 20 | 21 | import grpc 22 | 23 | from pcap_processor.grpc import WisdomGrpcService_pb2 24 | from pcap_processor.grpc import WisdomGrpcService_pb2_grpc 25 | from pcap_processor.sink import sink, Sink 26 | 27 | 28 | @sink(name="grpc", enabled=False) 29 | class GrpcSink(Sink): 30 | 31 | def __init__(self): 32 | self.endpoint = "localhost:8081" 33 | self.channel = None 34 | self.stub = None 35 | 36 | def init(self): 37 | self.channel = grpc.insecure_channel(self.endpoint) 38 | self.stub = WisdomGrpcService_pb2_grpc.WisdomStub(self.channel) 39 | 40 | def write(self, packet: dict): 41 | self.stub.send(WisdomGrpcService_pb2.Event(data=json.dumps(packet))) 42 | 43 | def close(self): 44 | self.stub = None 45 | self.channel = None 46 | -------------------------------------------------------------------------------- /pcap_processor/plugins/http_sink.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # pcap-reader - Read and process pcap files using this nifty tool. 3 | 4 | # Copyright (C) 2018 Gobinath 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | import http.client 20 | import json 21 | 22 | from pcap_processor.sink import sink, Sink 23 | 24 | 25 | @sink(name="http", enabled=False) 26 | class HttpSink(Sink): 27 | 28 | def __init__(self): 29 | self.host = "localhost" 30 | self.port = 8080 31 | self.headers = {"Content-type": "application/json"} 32 | self.endpoint = "/" 33 | self.connection = None 34 | 35 | def init(self): 36 | self.connection = http.client.HTTPConnection(self.host, self.port) 37 | 38 | def write(self, packet: dict): 39 | self.connection.request("POST", self.endpoint, json.dumps(packet), self.headers) 40 | self.connection.getresponse().close() 41 | 42 | def close(self): 43 | self.connection.close() 44 | -------------------------------------------------------------------------------- /pcap_processor/plugins/kafka_sink.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # pcap-reader - Read and process pcap files using this nifty tool. 3 | 4 | # Copyright (C) 2018 Gobinath 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | import json 20 | 21 | from kafka import KafkaProducer 22 | 23 | from pcap_processor.sink import sink, Sink 24 | 25 | 26 | @sink(name="kafka", enabled=False) 27 | class KafkaSink(Sink): 28 | 29 | def __init__(self): 30 | self.bootstrap = "localhost:9092" 31 | self.topic = "PacketStream" 32 | self.key = "pcap-processor" 33 | self.producer = None 34 | 35 | def init(self): 36 | self.producer = KafkaProducer(bootstrap_servers=self.bootstrap, key_serializer=str.encode, 37 | value_serializer=lambda v: json.dumps(v).encode('utf-8')) 38 | 39 | def write(self, packet: dict): 40 | self.producer.send(self.topic, key=self.key, value=packet) 41 | 42 | def close(self): 43 | self.producer.close() 44 | -------------------------------------------------------------------------------- /pcap_processor/plugins/length_mapper.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # pcap-reader - Read and process pcap files using this nifty tool. 3 | 4 | # Copyright (C) 2018 Gobinath 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | from pcap_processor.map_manager import Map, mapper 20 | 21 | 22 | @mapper(name="length", enabled=True) 23 | class LengthMap(Map): 24 | 25 | def map(self, packet: dict): 26 | packet["packet_length"] = int(packet["packet_length"] / 128) 27 | return packet 28 | -------------------------------------------------------------------------------- /pcap_processor/plugins/protocol_mapper.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # pcap-reader - Read and process pcap files using this nifty tool. 3 | 4 | # Copyright (C) 2018 Gobinath 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | from pcap_processor.map_manager import Map, mapper 20 | 21 | 22 | @mapper(name="protocol", enabled=False) 23 | class ProtocolMap(Map): 24 | 25 | def map(self, packet: dict): 26 | highest_layer = packet["highest_layer"] 27 | if highest_layer in ["XML", "JSON", "DATA-TEXT-LINES"]: 28 | packet["highest_layer"] = "TEXT" 29 | elif highest_layer in ["PNG", "MP4", "MEDIA", "IMAGE-JFIF", "IMAGE-GIF"]: 30 | packet["highest_layer"] = "BINARY" 31 | elif highest_layer in ["BJNP", "MDNS"]: 32 | packet["highest_layer"] = "LAN_DISCOVERY" 33 | elif highest_layer in ["DCERPC", "LSARPC", "RPC_NETLOGON"]: 34 | packet["highest_layer"] = "RPC" 35 | elif highest_layer in ["IGMP", "ICMPV6"]: 36 | packet["highest_layer"] = "ICMP" 37 | elif highest_layer == "SMB2": 38 | packet["highest_layer"] = "SMB" 39 | elif highest_layer == "URLENCODED-FORM": 40 | packet["highest_layer"] = "HTTP" 41 | return packet 42 | -------------------------------------------------------------------------------- /pcap_processor/reader.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # pcap-reader - Read and process pcap files using this nifty tool. 3 | 4 | # Copyright (C) 2018 Gobinath 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | import logging 20 | import os 21 | 22 | import pyshark 23 | from pyshark.capture.capture import TSharkCrashException 24 | 25 | from pcap_processor import commons 26 | from pcap_processor.map_manager import MapperManager 27 | from pcap_processor.sink import SinkManager 28 | 29 | logger = logging.getLogger(__name__) 30 | 31 | 32 | class PcapReader: 33 | def __init__(self, path): 34 | self.path = path 35 | self.active = False 36 | 37 | def _read_pcap(self, path): 38 | logger.debug("Reading pcap file: %s", path) 39 | packets = pyshark.FileCapture(path) 40 | for pcap in packets: 41 | has_transport = pcap.transport_layer is not None 42 | packet_time = float(pcap.sniff_timestamp) 43 | packet_dict = dict() 44 | highest_layer = pcap.highest_layer.upper() 45 | packet_dict["highest_layer"] = highest_layer 46 | if has_transport: 47 | packet_dict["transport_layer"] = pcap.transport_layer.upper() 48 | else: 49 | packet_dict["transport_layer"] = "NONE" 50 | packet_dict["src_port"] = -1 51 | packet_dict["dst_port"] = -1 52 | packet_dict["transport_flag"] = -1 53 | 54 | packet_dict["timestamp"] = int(packet_time * 1000) 55 | packet_dict["time"] = str(pcap.sniff_time) 56 | packet_dict["packet_length"] = int(pcap.length) 57 | packet_dict["data"] = "" 58 | 59 | for layer in pcap.layers: 60 | layer_name = layer.layer_name.upper() 61 | if "IP" == layer_name or "IPV6" == layer_name: 62 | packet_dict["src_ip"] = str(layer.src) 63 | packet_dict["dst_ip"] = str(layer.dst) 64 | if hasattr(layer, "flags"): 65 | packet_dict["ip_flag"] = int(layer.flags, 16) 66 | else: 67 | packet_dict["ip_flag"] = -1 68 | if hasattr(layer, "geocountry"): 69 | packet_dict["geo_country"] = str(layer.geocountry) 70 | else: 71 | packet_dict["geo_country"] = "Unknown" 72 | 73 | elif has_transport and layer_name == pcap.transport_layer: 74 | packet_dict["src_port"] = int(layer.srcport) 75 | packet_dict["dst_port"] = int(layer.dstport) 76 | if hasattr(layer, "flags"): 77 | packet_dict["transport_flag"] = int(layer.flags, 16) 78 | else: 79 | packet_dict["transport_flag"] = -1 80 | 81 | elif "FTP" == layer_name: 82 | packet_dict["data"] = str(layer._all_fields) 83 | if "src_ip" not in packet_dict: 84 | continue 85 | # Map packet attributes 86 | packet_dict = MapperManager.map(packet_dict) 87 | SinkManager.write(packet_dict) 88 | 89 | def _read_path(self, path): 90 | if os.path.isfile(path): 91 | try: 92 | self._read_pcap(path) 93 | except TSharkCrashException as ex: 94 | commons.error("Error in parsing %s pcap file" % path) 95 | elif os.path.isdir(path): 96 | # Iterate through all csv files in the directory 97 | files = os.listdir(path) 98 | for file in files: 99 | if file.lower().endswith(".pcap"): 100 | pcap_file = os.path.join(path, file) 101 | try: 102 | self._read_pcap(pcap_file) 103 | except TSharkCrashException: 104 | commons.error( 105 | "Error in parsing %s pcap file" % pcap_file) 106 | else: 107 | commons.error( 108 | "Path %s is neither a file nor a directory" % self.path) 109 | 110 | def read(self): 111 | self.active = True 112 | SinkManager.init() 113 | try: 114 | if type(self.path) is list: 115 | for file in self.path: 116 | self._read_path(file) 117 | else: 118 | self._read_path(self.path) 119 | except KeyboardInterrupt: 120 | print("Stop the reader") 121 | pass 122 | SinkManager.close() 123 | 124 | def stop(self): 125 | self.active = False 126 | -------------------------------------------------------------------------------- /pcap_processor/resources/logging.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | version: 1 3 | disable_existing_loggers: False 4 | formatters: 5 | simple: 6 | format: "%(asctime)s - %(levelname)s - %(filename)s - %(message)s" 7 | datefmt: "%Y-%m-%d %H:%M:%S" 8 | 9 | handlers: 10 | console: 11 | class: logging.StreamHandler 12 | level: DEBUG 13 | formatter: simple 14 | stream: ext://sys.stdout 15 | 16 | # info_file_handler: 17 | # class: logging.handlers.RotatingFileHandler 18 | # level: INFO 19 | # formatter: simple 20 | # filename: info.log 21 | # maxBytes: 1024 # 1MB 22 | # backupCount: 20 23 | # encoding: utf8 24 | # 25 | # error_file_handler: 26 | # class: logging.handlers.RotatingFileHandler 27 | # level: ERROR 28 | # formatter: simple 29 | # filename: errors.log 30 | # maxBytes: 1024 # 1MB 31 | # backupCount: 20 32 | # encoding: utf8 33 | 34 | loggers: 35 | root: 36 | level: INFO 37 | handlers: [console] 38 | propagate: no 39 | 40 | #root: 41 | # level: INFO 42 | # handlers: [console] 43 | ... 44 | -------------------------------------------------------------------------------- /pcap_processor/sink.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # pcap-reader - Read and process pcap files using this nifty tool. 3 | 4 | # Copyright (C) 2018 Gobinath 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | import inspect 20 | from abc import ABC 21 | 22 | from pcap_processor.plugin import Plugin 23 | 24 | 25 | class Sink(ABC): 26 | 27 | def write(self, packet: dict): 28 | pass 29 | 30 | def init(self): 31 | pass 32 | 33 | def close(self): 34 | pass 35 | 36 | 37 | class SinkManager(object): 38 | sinks = {} 39 | 40 | @classmethod 41 | def register(cls, mapper_clazz: Sink, name, enabled): 42 | cls.sinks[name] = Plugin(mapper_clazz, enabled) 43 | 44 | @classmethod 45 | def enable(cls, names): 46 | """ 47 | Enable only the given list of names and disable the rest. 48 | :param names: list of reporter names 49 | :return: None 50 | """ 51 | for name, plugin in cls.sinks.items(): 52 | plugin.enabled = name in names 53 | 54 | @classmethod 55 | def init(cls): 56 | for plugin in cls.sinks.values(): 57 | if plugin.enabled: 58 | plugin.instance.init() 59 | 60 | @classmethod 61 | def write(cls, packet: dict): 62 | for plugin in cls.sinks.values(): 63 | if plugin.enabled: 64 | plugin.instance.write(packet) 65 | 66 | @classmethod 67 | def close(cls): 68 | for plugin in cls.sinks.values(): 69 | if plugin.enabled: 70 | plugin.instance.close() 71 | 72 | 73 | def sink(name, enabled=False): 74 | def _sink(clazz): 75 | if inspect.isclass(clazz): 76 | if not hasattr(clazz, "write") or len(inspect.signature(getattr(clazz, "write")).parameters.items()) != 2: 77 | raise RuntimeError("Sink must have a function 'write(self, packet: dict)") 78 | if not hasattr(clazz, "init") or len(inspect.signature(getattr(clazz, "init")).parameters.items()) != 1: 79 | raise RuntimeError("Sink must have a function 'init(self)") 80 | if not hasattr(clazz, "close") or len(inspect.signature(getattr(clazz, "close")).parameters.items()) != 1: 81 | raise RuntimeError("Sink must have a function 'close(self)") 82 | else: 83 | raise RuntimeError("Sink must be a class") 84 | 85 | # Register the sink 86 | SinkManager.register(clazz, name, enabled) 87 | return clazz 88 | 89 | return _sink 90 | -------------------------------------------------------------------------------- /proto/WisdomGrpcService.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package com.javahelps.wisdom.service.gprc; 3 | 4 | service Wisdom { 5 | 6 | rpc send (Event) returns (Event); 7 | 8 | rpc feed (stream Event) returns (Event); 9 | 10 | rpc receive (Event) returns (stream Event); 11 | } 12 | 13 | message Event { 14 | string data = 1; 15 | } 16 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pyshark 2 | kafka-python 3 | grpcio 4 | grpcio-tools -------------------------------------------------------------------------------- /samples/cicids_2017.csv: -------------------------------------------------------------------------------- 1 | highest_layer,transport_layer,src_ip,dst_ip,src_port,dst_port,ip_flag,packet_length,transport_flag,time,timestamp,geo_country,data 2 | TCP,TCP,8.254.250.126,192.168.10.5,80,49188,0,0,17,2017-07-03 17:25:58.598308,1499082958598,Unknown, 3 | TCP,TCP,8.254.250.126,192.168.10.5,80,49188,0,0,17,2017-07-03 17:25:58.598312,1499082958598,Unknown, 4 | TCP,TCP,8.254.250.126,192.168.10.5,80,49188,0,0,17,2017-07-03 17:25:58.598313,1499082958598,Unknown, 5 | TCP,TCP,8.254.250.126,192.168.10.5,80,49188,0,0,17,2017-07-03 17:25:58.598314,1499082958598,Unknown, 6 | TCP,TCP,8.254.250.126,192.168.10.5,80,49188,0,0,17,2017-07-03 17:25:58.598315,1499082958598,Unknown, 7 | TCP,TCP,8.254.250.126,192.168.10.5,80,49188,0,0,17,2017-07-03 17:25:58.598316,1499082958598,Unknown, 8 | TCP,TCP,8.254.250.126,192.168.10.5,80,49188,0,0,17,2017-07-03 17:25:58.598317,1499082958598,Unknown, 9 | TCP,TCP,8.254.250.126,192.168.10.5,80,49188,0,0,17,2017-07-03 17:25:58.598318,1499082958598,Unknown, 10 | TCP,TCP,8.253.185.121,192.168.10.14,80,49486,0,0,17,2017-07-03 17:26:22.331018,1499082982331,Unknown, 11 | TCP,TCP,8.253.185.121,192.168.10.14,80,49486,0,0,17,2017-07-03 17:26:22.331021,1499082982331,Unknown, 12 | TCP,TCP,8.253.185.121,192.168.10.14,80,49486,0,0,17,2017-07-03 17:26:22.331022,1499082982331,Unknown, 13 | TCP,TCP,8.253.185.121,192.168.10.14,80,49486,0,0,17,2017-07-03 17:26:22.331023,1499082982331,Unknown, 14 | TCP,TCP,8.253.185.121,192.168.10.14,80,49486,0,0,17,2017-07-03 17:26:22.331024,1499082982331,Unknown, 15 | TCP,TCP,8.253.185.121,192.168.10.14,80,49486,0,0,17,2017-07-03 17:26:22.331025,1499082982331,Unknown, 16 | TCP,TCP,8.253.185.121,192.168.10.14,80,49486,0,0,17,2017-07-03 17:26:22.331026,1499082982331,Unknown, 17 | TCP,TCP,8.253.185.121,192.168.10.14,80,49486,0,0,17,2017-07-03 17:26:22.331027,1499082982331,Unknown, 18 | TCP,TCP,8.253.185.121,192.168.10.14,80,49486,0,0,17,2017-07-03 17:26:22.331028,1499082982331,Unknown, 19 | IGMP,NONE,192.168.10.9,224.0.0.22,-1,-1,0,0,-1,2017-07-03 17:26:37.567312,1499082997567,Unknown, 20 | IGMP,NONE,192.168.10.9,224.0.0.22,-1,-1,0,0,-1,2017-07-03 17:26:37.567472,1499082997567,Unknown, 21 | IGMP,NONE,192.168.10.9,224.0.0.22,-1,-1,0,0,-1,2017-07-03 17:26:37.568616,1499082997568,Unknown, 22 | LLMNR,UDP,192.168.10.9,224.0.0.252,60372,5355,0,0,-1,2017-07-03 17:26:37.568863,1499082997568,Unknown, 23 | LLMNR,UDP,192.168.10.9,224.0.0.252,60372,5355,0,0,-1,2017-07-03 17:26:37.568866,1499082997568,Unknown, 24 | LLMNR,UDP,192.168.10.9,224.0.0.252,60372,5355,0,0,-1,2017-07-03 17:26:37.568868,1499082997568,Unknown, 25 | LLMNR,UDP,192.168.10.9,224.0.0.252,60372,5355,0,0,-1,2017-07-03 17:26:37.568869,1499082997568,Unknown, 26 | LLMNR,UDP,192.168.10.9,224.0.0.252,60372,5355,0,0,-1,2017-07-03 17:26:37.568870,1499082997568,Unknown, 27 | LLMNR,UDP,192.168.10.9,224.0.0.252,60372,5355,0,0,-1,2017-07-03 17:26:37.568871,1499082997568,Unknown, 28 | LLMNR,UDP,192.168.10.9,224.0.0.252,60372,5355,0,0,-1,2017-07-03 17:26:37.568872,1499082997568,Unknown, 29 | LLMNR,UDP,192.168.10.9,224.0.0.252,60372,5355,0,0,-1,2017-07-03 17:26:37.568874,1499082997568,Unknown, 30 | LLMNR,UDP,192.168.10.9,224.0.0.252,60372,5355,0,0,-1,2017-07-03 17:26:37.568875,1499082997568,Unknown, 31 | IGMP,NONE,192.168.10.9,224.0.0.22,-1,-1,0,0,-1,2017-07-03 17:26:37.651836,1499082997651,Unknown, 32 | LLMNR,UDP,192.168.10.9,224.0.0.252,60372,5355,0,0,-1,2017-07-03 17:26:37.667494,1499082997667,Unknown, 33 | LLMNR,UDP,192.168.10.9,224.0.0.252,60372,5355,0,0,-1,2017-07-03 17:26:37.667499,1499082997667,Unknown, 34 | LLMNR,UDP,192.168.10.9,224.0.0.252,60372,5355,0,0,-1,2017-07-03 17:26:37.667500,1499082997667,Unknown, 35 | LLMNR,UDP,192.168.10.9,224.0.0.252,60372,5355,0,0,-1,2017-07-03 17:26:37.667501,1499082997667,Unknown, 36 | LLMNR,UDP,192.168.10.9,224.0.0.252,60372,5355,0,0,-1,2017-07-03 17:26:37.667502,1499082997667,Unknown, 37 | LLMNR,UDP,192.168.10.9,224.0.0.252,60372,5355,0,0,-1,2017-07-03 17:26:37.667503,1499082997667,Unknown, 38 | LLMNR,UDP,192.168.10.9,224.0.0.252,60372,5355,0,0,-1,2017-07-03 17:26:37.667504,1499082997667,Unknown, 39 | LLMNR,UDP,192.168.10.9,224.0.0.252,60372,5355,0,0,-1,2017-07-03 17:26:37.667506,1499082997667,Unknown, 40 | LLMNR,UDP,192.168.10.9,224.0.0.252,60372,5355,0,0,-1,2017-07-03 17:26:37.667507,1499082997667,Unknown, 41 | NBNS,UDP,192.168.10.9,192.168.10.3,137,137,0,0,-1,2017-07-03 17:26:37.897192,1499082997897,Unknown, 42 | NBNS,UDP,192.168.10.9,192.168.10.3,137,137,0,0,-1,2017-07-03 17:26:37.897196,1499082997897,Unknown, 43 | NBNS,UDP,192.168.10.3,192.168.10.9,137,137,0,0,-1,2017-07-03 17:26:37.897423,1499082997897,Unknown, 44 | NBNS,UDP,192.168.10.3,192.168.10.9,137,137,0,0,-1,2017-07-03 17:26:37.897427,1499082997897,Unknown, 45 | DNS,UDP,192.168.10.9,192.168.10.3,63683,53,0,0,-1,2017-07-03 17:26:37.908429,1499082997908,Unknown, 46 | -------------------------------------------------------------------------------- /samples/cicids_2017.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/slgobinath/pcap-processor/efd71a80208b1101c591910fa30e0a474eb9bbdc/samples/cicids_2017.pcap -------------------------------------------------------------------------------- /samples/darpa_99.csv: -------------------------------------------------------------------------------- 1 | highest_layer,transport_layer,src_ip,dst_ip,src_port,dst_port,ip_flag,packet_length,transport_flag,time,timestamp,geo_country,data 2 | DNS,UDP,172.16.112.20,192.168.1.20,53,53,0,0,-1,1999-03-08 19:00:00.498308,920898000498,Unknown, 3 | DNS,UDP,192.168.1.20,172.16.112.20,53,53,0,0,-1,1999-03-08 19:00:00.507439,920898000507,Unknown, 4 | DNS,UDP,172.16.112.20,192.168.1.10,53,53,0,0,-1,1999-03-08 19:00:00.508021,920898000508,Unknown, 5 | DNS,UDP,192.168.1.10,172.16.112.20,53,53,0,1,-1,1999-03-08 19:00:00.509870,920898000509,Unknown, 6 | TCP,TCP,172.16.114.148,197.218.177.69,1025,21,0,0,2,1999-03-08 19:00:00.510836,920898000510,Unknown, 7 | TCP,TCP,197.218.177.69,172.16.114.148,21,1025,0,0,18,1999-03-08 19:00:00.515528,920898000515,Unknown, 8 | TCP,TCP,172.16.114.148,197.218.177.69,1025,21,16384,0,16,1999-03-08 19:00:00.515710,920898000515,Unknown, 9 | DNS,UDP,192.168.1.10,172.16.112.20,53,53,0,0,-1,1999-03-08 19:00:00.672052,920898000672,Unknown, 10 | DNS,UDP,172.16.112.20,192.168.1.10,53,53,0,1,-1,1999-03-08 19:00:00.672630,920898000672,Unknown, 11 | DATA,TCP,197.218.177.69,172.16.114.148,21,1025,16384,1,24,1999-03-08 19:00:00.705139,920898000705,Unknown,"{'ftp.request': '0', 'ftp.response': '1', '': '220 calvin FTP server (Version wu-2.4.2-academ[BETA-15](1) Sat Nov 1 03:08:32 EST 1997) ready.\\r\\n', 'ftp.response.code': '220', 'ftp.response.arg': 'calvin FTP server (Version wu-2.4.2-academ[BETA-15](1) Sat Nov 1 03:08:32 EST 1997) ready.'}" 12 | TCP,TCP,172.16.114.148,197.218.177.69,1025,21,16384,0,16,1999-03-08 19:00:00.715330,920898000715,Unknown, 13 | DATA,TCP,172.16.114.148,197.218.177.69,1025,21,16384,0,24,1999-03-08 19:00:01.016166,920898001016,Unknown,"{'ftp.request': '1', 'ftp.response': '0', '': 'USER anonymous\\r\\n', 'ftp.request.command': 'USER', 'ftp.request.arg': 'anonymous'}" 14 | TCP,TCP,197.218.177.69,172.16.114.148,21,1025,16384,0,16,1999-03-08 19:00:01.031588,920898001031,Unknown, 15 | DATA,TCP,197.218.177.69,172.16.114.148,21,1025,16384,0,24,1999-03-08 19:00:01.064424,920898001064,Unknown,"{'ftp.request': '0', 'ftp.response': '1', '': '331 Guest login ok, send your complete e-mail address as password.\\r\\n', 'ftp.response.code': '331', 'ftp.response.arg': 'Guest login ok, send your complete e-mail address as password.'}" 16 | TCP,TCP,172.16.114.148,197.218.177.69,1025,21,16384,0,16,1999-03-08 19:00:01.075241,920898001075,Unknown, 17 | DATA,TCP,172.16.114.148,197.218.177.69,1025,21,16384,0,24,1999-03-08 19:00:01.655914,920898001655,Unknown,"{'ftp.request': '1', 'ftp.response': '0', '': 'PASS megans@crow.eyrie.af.mil\\r\\n', 'ftp.request.command': 'PASS', 'ftp.request.arg': 'megans@crow.eyrie.af.mil'}" 18 | TCP,TCP,197.218.177.69,172.16.114.148,21,1025,16384,0,16,1999-03-08 19:00:01.671492,920898001671,Unknown, 19 | DATA,TCP,197.218.177.69,172.16.114.148,21,1025,16384,0,24,1999-03-08 19:00:01.732489,920898001732,Unknown,"{'ftp.request': '0', 'ftp.response': '1', '': '230 Guest login ok, access restrictions apply.\\r\\n', 'ftp.response.code': '230', 'ftp.response.arg': 'Guest login ok, access restrictions apply.'}" 20 | DATA,TCP,172.16.114.148,197.218.177.69,1025,21,16384,0,24,1999-03-08 19:00:01.732916,920898001732,Unknown,"{'ftp.request': '1', 'ftp.response': '0', '': 'SYST\\r\\n', 'ftp.request.command': 'SYST'}" 21 | DATA,TCP,197.218.177.69,172.16.114.148,21,1025,16384,0,24,1999-03-08 19:00:01.736048,920898001736,Unknown,"{'ftp.request': '0', 'ftp.response': '1', '': '215 UNIX Type: L8\\r\\n', 'ftp.response.code': '215', 'ftp.response.arg': 'UNIX Type: L8'}" 22 | TCP,TCP,172.16.114.148,197.218.177.69,1025,21,16384,0,16,1999-03-08 19:00:01.755094,920898001755,Unknown, 23 | DATA,TCP,172.16.114.148,197.218.177.69,1025,21,16384,0,24,1999-03-08 19:00:03.068166,920898003068,Unknown,"{'ftp.request': '1', 'ftp.response': '0', '': 'PORT 172,16,114,148,4,2\\r\\n', 'ftp.request.command': 'PORT', 'ftp.request.arg': '172,16,114,148,4,2', 'ftp.active.cip': '172.16.114.148', 'ftp.active.port': '1026'}" 24 | DATA,TCP,197.218.177.69,172.16.114.148,21,1025,16384,0,24,1999-03-08 19:00:03.069317,920898003069,Unknown,"{'ftp.request': '0', 'ftp.response': '1', '': '200 PORT command successful.\\r\\n', 'ftp.response.code': '200', 'ftp.response.arg': 'PORT command successful.'}" 25 | DATA,TCP,172.16.114.148,197.218.177.69,1025,21,16384,0,24,1999-03-08 19:00:03.069917,920898003069,Unknown,"{'ftp.request': '1', 'ftp.response': '0', '': 'LIST\\r\\n', 'ftp.request.command': 'LIST'}" 26 | TCP,TCP,197.218.177.69,172.16.114.148,20,1026,0,0,2,1999-03-08 19:00:03.073199,920898003073,Unknown, 27 | TCP,TCP,172.16.114.148,197.218.177.69,1026,20,0,0,18,1999-03-08 19:00:03.073469,920898003073,Unknown, 28 | TCP,TCP,197.218.177.69,172.16.114.148,20,1026,16384,0,16,1999-03-08 19:00:03.074193,920898003074,Unknown, 29 | DATA,TCP,197.218.177.69,172.16.114.148,21,1025,16384,0,24,1999-03-08 19:00:03.074646,920898003074,Unknown,"{'ftp.request': '0', 'ftp.response': '1', '': '150 Opening ASCII mode data connection for /bin/ls.\\r\\n', 'ftp.response.code': '150', 'ftp.response.arg': 'Opening ASCII mode data connection for /bin/ls.'}" 30 | TCP,TCP,172.16.114.148,197.218.177.69,1025,21,16384,0,16,1999-03-08 19:00:03.084826,920898003084,Unknown, 31 | DNS,UDP,192.168.1.10,172.16.112.20,53,53,0,0,-1,1999-03-08 19:00:04.535457,920898004535,Unknown, 32 | DNS,UDP,172.16.112.20,192.168.1.10,53,53,0,1,-1,1999-03-08 19:00:04.536365,920898004536,Unknown, 33 | TCP,TCP,195.115.218.108,172.16.112.100,1024,25,0,0,2,1999-03-08 19:00:04.543994,920898004543,Unknown, 34 | TCP,TCP,172.16.112.100,195.115.218.108,25,1024,0,0,20,1999-03-08 19:00:04.546298,920898004546,Unknown, 35 | DATA-TEXT-LINES,TCP,197.218.177.69,172.16.114.148,20,1026,16384,8,24,1999-03-08 19:00:04.889270,920898004889,Unknown, 36 | DATA,TCP,197.218.177.69,172.16.114.148,21,1025,16384,0,24,1999-03-08 19:00:04.889344,920898004889,Unknown,"{'ftp.request': '0', 'ftp.response': '1', '': '226 Transfer complete.\\r\\n', 'ftp.response.code': '226', 'ftp.response.arg': 'Transfer complete.'}" 37 | DATA-TEXT-LINES,TCP,197.218.177.69,172.16.114.148,20,1026,16384,1,24,1999-03-08 19:00:04.889487,920898004889,Unknown, 38 | TCP,TCP,197.218.177.69,172.16.114.148,20,1026,0,0,17,1999-03-08 19:00:04.889556,920898004889,Unknown, 39 | TCP,TCP,172.16.114.148,197.218.177.69,1026,20,16384,0,16,1999-03-08 19:00:04.889701,920898004889,Unknown, 40 | TCP,TCP,172.16.114.148,197.218.177.69,1025,21,16384,0,16,1999-03-08 19:00:04.904438,920898004904,Unknown, 41 | TCP,TCP,172.16.114.148,197.218.177.69,1026,20,0,0,17,1999-03-08 19:00:04.909967,920898004909,Unknown, 42 | TCP,TCP,197.218.177.69,172.16.114.148,20,1026,16384,0,16,1999-03-08 19:00:04.910662,920898004910,Unknown, 43 | DATA,TCP,172.16.114.148,197.218.177.69,1025,21,16384,0,24,1999-03-08 19:00:05.955524,920898005955,Unknown,"{'ftp.request': '1', 'ftp.response': '0', '': 'CWD usr\\r\\n', 'ftp.request.command': 'CWD', 'ftp.request.arg': 'usr'}" 44 | DATA,TCP,197.218.177.69,172.16.114.148,21,1025,16384,0,24,1999-03-08 19:00:05.957512,920898005957,Unknown,"{'ftp.request': '0', 'ftp.response': '1', '': '250 CWD command successful.\\r\\n', 'ftp.response.code': '250', 'ftp.response.arg': 'CWD command successful.'}" 45 | TCP,TCP,172.16.114.148,197.218.177.69,1025,21,16384,0,16,1999-03-08 19:00:05.974218,920898005974,Unknown, 46 | NTP,UDP,172.16.112.50,172.16.112.10,123,123,16384,0,-1,1999-03-08 19:00:06.627149,920898006627,Unknown, 47 | NTP,UDP,172.16.112.10,172.16.112.50,123,123,16384,0,-1,1999-03-08 19:00:06.627631,920898006627,Unknown, 48 | DATA,TCP,172.16.114.148,197.218.177.69,1025,21,16384,0,24,1999-03-08 19:00:06.785126,920898006785,Unknown,"{'ftp.request': '1', 'ftp.response': '0', '': 'PORT 172,16,114,148,4,3\\r\\n', 'ftp.request.command': 'PORT', 'ftp.request.arg': '172,16,114,148,4,3', 'ftp.active.cip': '172.16.114.148', 'ftp.active.port': '1027'}" 49 | DATA,TCP,197.218.177.69,172.16.114.148,21,1025,16384,0,24,1999-03-08 19:00:06.785949,920898006785,Unknown,"{'ftp.request': '0', 'ftp.response': '1', '': '200 PORT command successful.\\r\\n', 'ftp.response.code': '200', 'ftp.response.arg': 'PORT command successful.'}" 50 | DATA,TCP,172.16.114.148,197.218.177.69,1025,21,16384,0,24,1999-03-08 19:00:06.786247,920898006786,Unknown,"{'ftp.request': '1', 'ftp.response': '0', '': 'LIST\\r\\n', 'ftp.request.command': 'LIST'}" 51 | TCP,TCP,197.218.177.69,172.16.114.148,20,1027,0,0,2,1999-03-08 19:00:06.788913,920898006788,Unknown, 52 | TCP,TCP,172.16.114.148,197.218.177.69,1027,20,0,0,18,1999-03-08 19:00:06.789191,920898006789,Unknown, 53 | TCP,TCP,197.218.177.69,172.16.114.148,20,1027,16384,0,16,1999-03-08 19:00:06.789890,920898006789,Unknown, 54 | DATA,TCP,197.218.177.69,172.16.114.148,21,1025,16384,0,24,1999-03-08 19:00:06.794466,920898006794,Unknown,"{'ftp.request': '0', 'ftp.response': '1', '': '150 Opening ASCII mode data connection for /bin/ls.\\r\\n', 'ftp.response.code': '150', 'ftp.response.arg': 'Opening ASCII mode data connection for /bin/ls.'}" 55 | TCP,TCP,172.16.114.148,197.218.177.69,1025,21,16384,0,16,1999-03-08 19:00:06.814035,920898006814,Unknown, 56 | DATA-TEXT-LINES,TCP,197.218.177.69,172.16.114.148,20,1027,16384,5,24,1999-03-08 19:00:06.849273,920898006849,Unknown, 57 | DATA,TCP,197.218.177.69,172.16.114.148,21,1025,16384,0,24,1999-03-08 19:00:06.849358,920898006849,Unknown,"{'ftp.request': '0', 'ftp.response': '1', '': '226 Transfer complete.\\r\\n', 'ftp.response.code': '226', 'ftp.response.arg': 'Transfer complete.'}" 58 | TCP,TCP,197.218.177.69,172.16.114.148,20,1027,0,0,17,1999-03-08 19:00:06.849424,920898006849,Unknown, 59 | TCP,TCP,172.16.114.148,197.218.177.69,1027,20,16384,0,16,1999-03-08 19:00:06.849586,920898006849,Unknown, 60 | TCP,TCP,172.16.114.148,197.218.177.69,1027,20,0,0,17,1999-03-08 19:00:06.850565,920898006850,Unknown, 61 | TCP,TCP,197.218.177.69,172.16.114.148,20,1027,16384,0,16,1999-03-08 19:00:06.851239,920898006851,Unknown, 62 | TCP,TCP,172.16.114.148,197.218.177.69,1025,21,16384,0,16,1999-03-08 19:00:06.864022,920898006864,Unknown, 63 | DATA,TCP,172.16.114.148,197.218.177.69,1025,21,16384,0,24,1999-03-08 19:00:08.106710,920898008106,Unknown,"{'ftp.request': '1', 'ftp.response': '0', '': 'CWD bin3\\r\\n', 'ftp.request.command': 'CWD', 'ftp.request.arg': 'bin3'}" 64 | TCP,TCP,197.218.177.69,172.16.114.148,21,1025,16384,0,16,1999-03-08 19:00:08.120186,920898008120,Unknown, 65 | DATA,TCP,197.218.177.69,172.16.114.148,21,1025,16384,0,24,1999-03-08 19:00:08.173797,920898008173,Unknown,"{'ftp.request': '0', 'ftp.response': '1', '': '250 CWD command successful.\\r\\n', 'ftp.response.code': '250', 'ftp.response.arg': 'CWD command successful.'}" 66 | TCP,TCP,172.16.114.148,197.218.177.69,1025,21,16384,0,16,1999-03-08 19:00:08.193748,920898008193,Unknown, 67 | NTP,UDP,172.16.112.100,172.16.112.10,1066,123,0,0,-1,1999-03-08 19:00:08.637962,920898008637,Unknown, 68 | NTP,UDP,172.16.112.10,172.16.112.100,123,1066,16384,0,-1,1999-03-08 19:00:08.638308,920898008638,Unknown, 69 | DATA,TCP,172.16.114.148,197.218.177.69,1025,21,16384,0,24,1999-03-08 19:00:09.255137,920898009255,Unknown,"{'ftp.request': '1', 'ftp.response': '0', '': 'PORT 172,16,114,148,4,4\\r\\n', 'ftp.request.command': 'PORT', 'ftp.request.arg': '172,16,114,148,4,4', 'ftp.active.cip': '172.16.114.148', 'ftp.active.port': '1028'}" 70 | DATA,TCP,197.218.177.69,172.16.114.148,21,1025,16384,0,24,1999-03-08 19:00:09.256177,920898009256,Unknown,"{'ftp.request': '0', 'ftp.response': '1', '': '200 PORT command successful.\\r\\n', 'ftp.response.code': '200', 'ftp.response.arg': 'PORT command successful.'}" 71 | DATA,TCP,172.16.114.148,197.218.177.69,1025,21,16384,0,24,1999-03-08 19:00:09.256533,920898009256,Unknown,"{'ftp.request': '1', 'ftp.response': '0', '': 'LIST\\r\\n', 'ftp.request.command': 'LIST'}" 72 | TCP,TCP,197.218.177.69,172.16.114.148,20,1028,0,0,2,1999-03-08 19:00:09.259457,920898009259,Unknown, 73 | TCP,TCP,172.16.114.148,197.218.177.69,1028,20,0,0,18,1999-03-08 19:00:09.259743,920898009259,Unknown, 74 | TCP,TCP,197.218.177.69,172.16.114.148,20,1028,16384,0,16,1999-03-08 19:00:09.260443,920898009260,Unknown, 75 | DATA,TCP,197.218.177.69,172.16.114.148,21,1025,16384,0,24,1999-03-08 19:00:09.265053,920898009265,Unknown,"{'ftp.request': '0', 'ftp.response': '1', '': '150 Opening ASCII mode data connection for /bin/ls.\\r\\n', 'ftp.response.code': '150', 'ftp.response.arg': 'Opening ASCII mode data connection for /bin/ls.'}" 76 | TCP,TCP,172.16.114.148,197.218.177.69,1025,21,16384,0,16,1999-03-08 19:00:09.283523,920898009283,Unknown, 77 | DATA-TEXT-LINES,TCP,197.218.177.69,172.16.114.148,20,1028,16384,8,24,1999-03-08 19:00:09.290054,920898009290,Unknown, 78 | DATA-TEXT-LINES,TCP,197.218.177.69,172.16.114.148,20,1028,16384,11,24,1999-03-08 19:00:09.291631,920898009291,Unknown, 79 | DATA,TCP,197.218.177.69,172.16.114.148,21,1025,16384,0,24,1999-03-08 19:00:09.291716,920898009291,Unknown,"{'ftp.request': '0', 'ftp.response': '1', '': '226 Transfer complete.\\r\\n', 'ftp.response.code': '226', 'ftp.response.arg': 'Transfer complete.'}" 80 | TCP,TCP,172.16.114.148,197.218.177.69,1025,21,16384,0,16,1999-03-08 19:00:09.303519,920898009303,Unknown, 81 | TCP,TCP,172.16.114.148,197.218.177.69,1028,20,16384,0,16,1999-03-08 19:00:09.303585,920898009303,Unknown, 82 | DATA-TEXT-LINES,TCP,197.218.177.69,172.16.114.148,20,1028,16384,6,24,1999-03-08 19:00:09.305729,920898009305,Unknown, 83 | TCP,TCP,197.218.177.69,172.16.114.148,20,1028,0,0,17,1999-03-08 19:00:09.305796,920898009305,Unknown, 84 | TCP,TCP,172.16.114.148,197.218.177.69,1028,20,16384,0,16,1999-03-08 19:00:09.305952,920898009305,Unknown, 85 | TCP,TCP,172.16.114.148,197.218.177.69,1028,20,0,0,17,1999-03-08 19:00:09.307350,920898009307,Unknown, 86 | TCP,TCP,197.218.177.69,172.16.114.148,20,1028,16384,0,16,1999-03-08 19:00:09.308000,920898009308,Unknown, 87 | DATA,TCP,172.16.114.148,197.218.177.69,1025,21,16384,0,24,1999-03-08 19:00:10.394223,920898010394,Unknown,"{'ftp.request': '1', 'ftp.response': '0', '': 'TYPE I\\r\\n', 'ftp.request.command': 'TYPE', 'ftp.request.arg': 'I'}" 88 | DATA,TCP,197.218.177.69,172.16.114.148,21,1025,16384,0,24,1999-03-08 19:00:10.395232,920898010395,Unknown,"{'ftp.request': '0', 'ftp.response': '1', '': '200 Type set to I.\\r\\n', 'ftp.response.code': '200', 'ftp.response.arg': 'Type set to I.'}" 89 | TCP,TCP,172.16.114.148,197.218.177.69,1025,21,16384,0,16,1999-03-08 19:00:10.413283,920898010413,Unknown, 90 | DATA,TCP,172.16.114.148,197.218.177.69,1025,21,16384,0,24,1999-03-08 19:00:12.504609,920898012504,Unknown,"{'ftp.request': '1', 'ftp.response': '0', '': 'PORT 172,16,114,148,4,5\\r\\n', 'ftp.request.command': 'PORT', 'ftp.request.arg': '172,16,114,148,4,5', 'ftp.active.cip': '172.16.114.148', 'ftp.active.port': '1029'}" 91 | DATA,TCP,197.218.177.69,172.16.114.148,21,1025,16384,0,24,1999-03-08 19:00:12.505571,920898012505,Unknown,"{'ftp.request': '0', 'ftp.response': '1', '': '200 PORT command successful.\\r\\n', 'ftp.response.code': '200', 'ftp.response.arg': 'PORT command successful.'}" 92 | DATA,TCP,172.16.114.148,197.218.177.69,1025,21,16384,0,24,1999-03-08 19:00:12.505964,920898012505,Unknown,"{'ftp.request': '1', 'ftp.response': '0', '': 'RETR ctags\\r\\n', 'ftp.request.command': 'RETR', 'ftp.request.arg': 'ctags'}" 93 | TCP,TCP,197.218.177.69,172.16.114.148,20,1029,0,0,2,1999-03-08 19:00:12.508255,920898012508,Unknown, 94 | TCP,TCP,172.16.114.148,197.218.177.69,1029,20,0,0,18,1999-03-08 19:00:12.508544,920898012508,Unknown, 95 | TCP,TCP,197.218.177.69,172.16.114.148,20,1029,16384,0,16,1999-03-08 19:00:12.509217,920898012509,Unknown, 96 | -------------------------------------------------------------------------------- /samples/darpa_99.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/slgobinath/pcap-processor/efd71a80208b1101c591910fa30e0a474eb9bbdc/samples/darpa_99.pcap -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | import setuptools 4 | 5 | REQUIRES = [ 6 | "pyshark", 7 | "kafka-python", 8 | "grpcio", 9 | "grpcio-tools" 10 | ] 11 | 12 | _ROOT = os.path.abspath(os.path.dirname(__file__)) 13 | 14 | with open(os.path.join(_ROOT, 'README.md')) as f: 15 | LONG_DESCRIPTION = f.read() 16 | 17 | setuptools.setup( 18 | name="pcap-processor", 19 | version="0.0.1", 20 | description="Read and process pcap files using this nifty tool.", 21 | long_description=LONG_DESCRIPTION, 22 | long_description_content_type="text/markdown", 23 | author="Gobinath Loganathan", 24 | author_email="slgobinath@gmail.com", 25 | url="https://github.com/slgobinath/pcap-processor", 26 | download_url="https://github.com/slgobinath/pcap-processor/releases", 27 | packages=setuptools.find_packages(), 28 | install_requires=REQUIRES, 29 | setup_requires=['setuptools>=38.6.0'], 30 | entry_points={'console_scripts': ['pcap-processor = pcap_processor.__main__:main']}, 31 | keywords='pcap utility csv json', 32 | classifiers=[ 33 | "Operating System :: POSIX :: Linux", 34 | "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", 35 | "Development Status :: 5 - Production/Stable", 36 | "Intended Audience :: End Users/Desktop", 37 | "Topic :: Utilities"] + [('Programming Language :: Python :: %s' % x) for x in 38 | '3 3.4 3.5 3.6'.split()] 39 | ) 40 | --------------------------------------------------------------------------------