@@ -1054,6 +1054,8 @@ def parse_diverter_config(self):
1054
1054
self .getconfigval ('processblacklist' ).split (',' )]
1055
1055
self .logger .debug ('Blacklisted processes: %s' , ', ' .join (
1056
1056
[str (p ) for p in self .blacklist_processes ]))
1057
+ if self .logger .level == logging .INFO :
1058
+ self .logger .info ('Hiding logs from blacklisted processes' )
1057
1059
1058
1060
# Only redirect whitelisted processes
1059
1061
if self .is_configured ('processwhitelist' ):
@@ -1202,7 +1204,18 @@ def handle_pkt(self, pkt, callbacks3, callbacks4):
1202
1204
pc = PidCommDest (pid , comm , pkt .proto , pkt .dst_ip0 , pkt .dport0 )
1203
1205
if pc .isDistinct (self .last_conn , self .ip_addrs [pkt .ipver ]):
1204
1206
self .last_conn = pc
1205
- self .logger .info ('%s' % (str (pc )))
1207
+ # As a user may not wish to see any logs from a blacklisted
1208
+ # process, messages are logged with level DEBUG. Executing
1209
+ # FakeNet in the verbose mode will print these logs
1210
+ is_process_blacklisted , _ , _ = self .isProcessBlackListed (
1211
+ pkt .proto ,
1212
+ process_name = comm ,
1213
+ dport = pkt .dport0
1214
+ )
1215
+ if is_process_blacklisted :
1216
+ self .logger .debug ('%s' % (str (pc )))
1217
+ else :
1218
+ self .logger .info ('%s' % (str (pc )))
1206
1219
1207
1220
# 2: Call layer 3 (network) callbacks
1208
1221
for cb in callbacks3 :
@@ -1825,9 +1838,8 @@ def logNbi(self, sport, nbi, proto, application_layer_proto,
1825
1838
is_ssl_encrypted ):
1826
1839
"""Collects the NBIs from all listeners into a dictionary.
1827
1840
1828
- All listeners (currently only HTTPListener) use this
1829
- method to notify the diverter about any NBI captured
1830
- within their scope.
1841
+ All listeners use this method to notify the diverter about any NBI
1842
+ captured within their scope.
1831
1843
1832
1844
Args:
1833
1845
sport: int port bound by listener
@@ -1956,7 +1968,7 @@ def generate_html_report(self):
1956
1968
"""
1957
1969
if getattr (sys , 'frozen' , False ) and hasattr (sys , '_MEIPASS' ):
1958
1970
# Inside a Pyinstaller bundle
1959
- fakenet_dir_path = os .getcwd ( )
1971
+ fakenet_dir_path = os .path . dirname ( sys . executable )
1960
1972
else :
1961
1973
fakenet_dir_path = os .fspath (Path (__file__ ).parents [1 ])
1962
1974
@@ -1972,7 +1984,44 @@ def generate_html_report(self):
1972
1984
output_file .write (template .render (nbis = self .nbis ))
1973
1985
1974
1986
self .logger .info (f"Generated new HTML report: { output_filename } " )
1975
-
1987
+
1988
+ def isProcessBlackListed (self , proto , sport = None , process_name = None , dport = None ):
1989
+ """Checks if a process is blacklisted.
1990
+ Expected arguments are either:
1991
+ - process_name and dport, or
1992
+ - sport
1993
+ """
1994
+ pid = None
1995
+
1996
+ if self .single_host_mode and proto is not None :
1997
+ if process_name is None or dport is None :
1998
+ if sport is None :
1999
+ return False , process_name , pid
2000
+
2001
+ orig_sport = self .proxy_sport_to_orig_sport_map .get ((proto , sport ), sport )
2002
+ session = self .sessions .get (orig_sport )
2003
+ if session :
2004
+ pid = session .pid
2005
+ process_name = session .comm
2006
+ dport = session .dport0
2007
+ else :
2008
+ return False , process_name , pid
2009
+
2010
+ # Check process blacklist
2011
+ if process_name in self .blacklist_processes :
2012
+ self .pdebug (DIGN , ('Ignoring %s packet from process %s ' +
2013
+ 'in the process blacklist.' ) % (proto ,
2014
+ process_name ))
2015
+ return True , process_name , pid
2016
+
2017
+ # Check per-listener blacklisted process list
2018
+ if self .listener_ports .isProcessBlackListHit (
2019
+ proto , dport , process_name ):
2020
+ self .pdebug (DIGN , ('Ignoring %s request packet from ' +
2021
+ 'process %s in the listener process ' +
2022
+ 'blacklist.' ) % (proto , process_name ))
2023
+ return True , process_name , pid
2024
+ return False , process_name , pid
1976
2025
1977
2026
1978
2027
class DiverterListenerCallbacks ():
@@ -2011,3 +2060,7 @@ def mapProxySportToOrigSport(self, proto, orig_sport, proxy_sport,
2011
2060
self .__diverter .mapProxySportToOrigSport (proto , orig_sport , proxy_sport ,
2012
2061
is_ssl_encrypted )
2013
2062
2063
+ def isProcessBlackListed (self , proto , sport ):
2064
+ """Check if the process is blacklisted.
2065
+ """
2066
+ return self .__diverter .isProcessBlackListed (proto , sport = sport )
0 commit comments