Package: networksage-tools
networksage-toolsThis repository contains publicly-released tools that will be helpful when interacting with the NetworkSage platform. Note that to upload anything to NetworkSage, you will require either a free or paid API key. To request an API key, please register for an account athttps://networksage.seclarity.io/register.What is NetworkSage?The NetworkSage platform, first and foremost, acts as a lightweight, privacy-maintaining enrichment layer for your network traffic. It takes network flows (which we callSecflows), categorizes them with one of a couple dozen labels (see ourGlossaryfor details), and compares them with the global dataset of known activity. For every Secflow, it returns:how common it is globallywhich categorization it hasany metadata the security community has providedTo visually illustrate, refer to the following (taken from a publicsamplewe found while creating our firstThreat Report).When this sample was uploaded to NetworkSage, all Secflows were automatically categorized and their global commonality was identified:In addition, many of thoseDestinations(an IP or Domain name plus its port) had additional metadata provided by the security community. That information was made available inline:Some of the categories associated with certain Secflows also indicated specificBehaviorwas happening. That information (also provided by the community) was shared for more in-depth knowledge:Finally, some of the Behaviors (when seen in a particular order within some period of time) actually identified more complex interactions that we callEvents:InstallationNote that this package requireslibpcap-devto be installed on your system. Please use your system's package manager (such asapton Ubuntu) to installlibpcap-dev:sudoapt-getinstalllibpcap-devWhile Windows isn't yet supported due to issues with underlying libraries (specificallypcapy), we'd welcome anyone who wants to document the steps to make it work. At the very minimum, you will need the following:A C++ compiler. Microsoft Visual Studio Build Tools is known to work.
Npcap's SDK, which is a replacement for the WinPCAP developer's kit.To install thenetworksage-toolspackage, simply type the following:pipinstallnetworksage-toolsAvailable ModulesThere are multiple modules available within this package. Details about each are below.A. Streaming Secflow Collectormodule name:streamingThis module allows you to directly capture network traffic as unenriched Secflows (Secflows without flow category labels). This is beneficial for a number of reasons:Secflows areextremelylightweight, so you can actually do this continuously in the background without affecting system performance (i.e. you can collect network telemetry continuously on your endpoints)!Secflows have no identifying data, so you can avoid worrying about accidentally leaking information (URIs, passwords, keys, etc...)To import this module into your project, type the following:fromnetworksage_tools.streamingimportstreamingUsageTo capture Secflows continuously using this module from your project, enter the following (note that you'll need to be root to capture packets):streaming.start(<interface_name>,<duration_in_seconds>,<optional_verbosity>)Note that the above will run in perpetuity, capturing packets from the interface you specified (such as "enp0s3" on Ubuntu systems). Every time the specified duration you provided is reached (if you provide no value, it defaults to 300 seconds), a sample will be created and uploaded to your NetworkSage account. Providing the optionalis_verbosevalue will print a small amount of information about the number of flows and its UUID.B. Standalone Convertermodule name:converterThis module allows you to convert captured network traffic from any of our supported formats (currently PCAP, PCAPNG, Zeek, and Interflow) into unenriched Secflows (Secflows without flow category labels). This is useful if you already have network telemetry that you'd like to upload to NetworkSage, but you don't want to upload the original file (for privacy, size, or other reasons).To import this module into your project, type the following:fromnetworksage_tools.converterimportconvertUsageTo convert a PCAP or PCAPNG file into an unenriched Secflow file, simply enter the following:convert.convert_pcap(<path_to_pcap_file>)To convert a Zeek Conn log into an unenriched Secflow file, simply enter the following:convert.convert_zeek(<path_to_conn_log>,zeek_dnsfile_location=<optional_path_to_dns_log>)If you have (and would like to include) DNS information that was captured by Zeek, provide thedns.login addition to theconn.log. Naming will be much enhanced by doing so.NOTE:As of v1.1.4 of this package, we now support Zeek and Interflow JSON files in two formats.Comma-Separated List of JSON records (preferred):[{json_record_1},{json_record_2}]One JSON record per line:{json_record_1}{json_record_2}As of v1.0.0 of this package, we now support Zeek files inJSONand plaintextTSV(i.e. the OG) formats. If you are uploading plaintext logs, please make sure that yourconn.logfiles have the following fields in the following order (Field #lines are annotations for clarity below and shouldNOTbe included in the file):Field#12345tsuidid.orig_hid.orig_pid.resp_hField#678910id.resp_pprotoservicedurationorig_bytesField#11121314resp_bytesconn_statelocal_origlocal_respField#1516171819missed_byteshistoryorig_pktsorig_ip_bytesresp_pktsField#2021resp_ip_bytestunnel_parentsAnexampleofaflowlinefromtheconnlogisasfollows("field #"linesaremyannotation):Field#1231601060272.439360CC9S3G178KjzSMTGRk192.168.100.224Field#456789137192.168.100.255137udpdns12.114023Field#101112131415161711860S0--0D23Field#18192021183000-Fordns.logfiles (again, if you'renotusing JSON), make sure that the file matches the following:Field#12345678tsuidid.orig_hid.orig_pid.resp_hid.resp_pprototrans_idField#910111213141516rttqueryqclassqclass_nameqtypeqtype_namercodercode_nameField#1718192021222324AATCRDRAZanswersTTLsrejectedNotethatallfieldnamesarenotused.Ifyoudonothaveafield,pleasegiveitanappropriatedefaultvalueasdefinedbytheZeekformat(https://docs.zeek.org/en/master/logs/dns.html).NOTE:As of v1.1.0 of this package, we now support Interflow logs in JSON format.To convert an Interflow log into an unenriched Secflow file, simply enter the following:convert.convert_interflow(<path_to_interflow_log>)Any DNS Interflows should also be passed in within the Interflow log.Note that there are MANY fields in Interflow that will not be a part of this converter, as they are not necessary to convert to Secflow. The log file is expected to contain a comma-separated list of Interflow records in JSON format. For non-DNS records, below is an example Interflow record that includes only the fields we need:[{"timestamp":1656517273641,"duration":401,"_id":"6c0liABC8qtQm3loQr7H","msg_class":"interflow_traffic","srcip":"172.18.40.120","srcport":55503,"dstip":"142.251.40.65","dstip_host":"ci3.googleusercontent.com","dstport":80,"proto_name":"tcp","outbytes_total":0,"inpkts_delta":5,"outpkts_delta":0,"inbytes_total":17765}]Supported File FormatsNetworkSage currently supports uploading the following files (which will be converted into our Secflow format):PCAPPCAPNGZeek (conn.log and dns.log in TSV or JSON formatting; see prior section for details)Interflow (as a comma-separated list of JSON)SecflowIf you have a format that you'd like us to support, please review ourFAQsand contactsupport at seclarity [.] io.Getting InvolvedWe havea lotof plans to change the face of security. If you want to be involved as a contributor or to be a part of the community we're building, we highly encourage you to join ourSlack!LicenseThis software is provided under the Apache Software License. See the accompanying LICENSE file for more information.