@@ -87,7 +87,7 @@ def _process_packet(session: Session, packet: Packet, must_inspect_strings: bool
87
87
logger .info (session , "Credit card '{}' found: '{}'" .format (credit_card .name , credit_card .number ))
88
88
89
89
90
- def _process_packets_from (packets_input : Capture , manager : SessionsManager , must_inspect_strings : bool ):
90
+ def _process_packets_from (packets_input : Capture , manager : SessionsManager , must_inspect_strings : bool = False ):
91
91
"""
92
92
Loops over available packets, retrieves its session and handles potential exceptions.
93
93
@@ -131,7 +131,8 @@ def _process_packets_from(packets_input: Capture, manager: SessionsManager, must
131
131
clean_before_exit ()
132
132
133
133
134
- def process_pcap (filename : str , must_inspect_strings = False , tshark_filter = None , debug = False , decode_as = None ) -> SessionsManager :
134
+ def process_pcap (filename : str , must_inspect_strings = False , tshark_filter = None , debug = False ,
135
+ decode_as = None , creds_found_callback = None ) -> SessionsManager :
135
136
"""
136
137
Initialize the processing of a pcap file and retrieve results of the analysis.
137
138
This is one of the main entry points most people will want to use.
@@ -154,6 +155,9 @@ def process_pcap(filename: str, must_inspect_strings=False, tshark_filter=None,
154
155
decode_as : Dict[str, str]
155
156
Associate a protocol to a port so that tshark processes packets correctly.
156
157
158
+ creds_found_callback : Callable[[Credentials], None]
159
+ The function to call every time new credentials are found. Credentials are passed as parameter.
160
+
157
161
Returns
158
162
-------
159
163
A `SessionsManager` instance which gives to ability to the user of that function to retrieve
@@ -162,6 +166,7 @@ def process_pcap(filename: str, must_inspect_strings=False, tshark_filter=None,
162
166
163
167
logger .DEBUG_MODE = debug
164
168
sessions_manager = SessionsManager ()
169
+ Session .creds_found_callback = creds_found_callback
165
170
166
171
with pyshark .FileCapture (filename , display_filter = tshark_filter , decode_as = decode_as , debug = debug ) as pcap :
167
172
logger .info ("Processing packets in '{}'" .format (filename ))
@@ -184,7 +189,8 @@ def process_pcap(filename: str, must_inspect_strings=False, tshark_filter=None,
184
189
return sessions_manager
185
190
186
191
187
- def active_processing (interface : str , must_inspect_strings = False , tshark_filter = None , debug = False , decode_as = None , pcap_output = None ):
192
+ def active_processing (interface : str , must_inspect_strings = False , tshark_filter = None , debug = False , decode_as = None ,
193
+ pcap_output = None , creds_found_callback = None ):
188
194
"""
189
195
Initialize packets capturing on a given interface file.
190
196
This is one of the main entry points most people will want to use.
@@ -209,11 +215,15 @@ def active_processing(interface: str, must_inspect_strings=False, tshark_filter=
209
215
210
216
pcap_output : str
211
217
Captured packets will be output to that file path.
218
+
219
+ creds_found_callback : Callable[[Credentials], None]
220
+ The function to call every time new credentials are found. Credentials are passed as parameter.
212
221
"""
213
222
214
223
logger .DEBUG_MODE = debug
215
224
216
225
sessions = SessionsManager (remove_outdated = True )
226
+ Session .creds_found_callback = creds_found_callback
217
227
218
228
signal .signal (signal .SIGINT , signal_handler )
219
229
0 commit comments