You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class ImportBlocker(object):
def init(self, *args):
self.module_names = args
def find_module(self, fullname, path=None):
if fullname in self.module_names:
return self
return None
def load_module(self, name):
raise ImportError("%s is blocked and cannot be imported" % name)
A rule set downloaded from the web, can exhibit malicious activity.
The solution is to block import of some python modules (e.g. httplib) and override some builtin functions (e.g. open()).
Keywords: sys.meta_path, find_module, load_module
Recipe: http://xion.org.pl/2012/05/06/hacking-python-imports/
class ImportBlocker(object):
def init(self, *args):
self.module_names = args
import sys
sys.meta_path = [ImportBlocker("httplib")]
The text was updated successfully, but these errors were encountered: