def download(url, tor=False): def create_connection(address, timeout=None, source_address=None): sock = socks.socksocket() sock.connect(address) return sock if tor: if not HAVE_SOCKS: print_error("Missing dependency, install socks (`pip install SocksiPy`)") return None socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', 9050) socket.socket = socks.socksocket socket.create_connection = create_connection try: req = Request(url) req.add_header('User-agent', 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)') res = urlopen(req) data = res.read() except HTTPError as e: print_error(e) except URLError as e: if tor and e.reason.errno == 111: print_error("Connection refused, maybe Tor is not running?") else: print_error(e) except Exception as e: print_error("Failed download: {0}".format(e)) else: return data
def download(url, tor=False): def create_connection(address, timeout=None, source_address=None): sock = socks.socksocket() sock.connect(address) return sock if tor: if not HAVE_SOCKS: print_error( "Missing dependency, install socks (`pip install SocksiPy`)") return None socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', 9050) socket.socket = socks.socksocket socket.create_connection = create_connection try: req = Request(url) req.add_header( 'User-agent', 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)') res = urlopen(req) data = res.read() except HTTPError as e: print_error(e) except URLError as e: if tor and e.reason.errno == 111: print_error("Connection refused, maybe Tor is not running?") else: print_error(e) except Exception as e: print_error("Failed download: {0}".format(e)) else: return data
def scan(self): # : create tmp file handle, name = tempfile.mkstemp(suffix=".data", prefix="exif_") #: Write data stream to tmp file with open(name, "wb") as f: f.write(self.data) #: Run exiftool on tmp file try: r = envoy.run('exiftool ' + name, timeout=15) except AttributeError: print_error('ERROR: Exif Failed.') return 'trid', dict(error='Exiftool failed to run.') else: #: return key, stdout as a dictionary return 'exif', self.format_output(r.std_out) finally: #: delete tmp file unlink(name)
def scan(self): #: create tmp file handle, name = tempfile.mkstemp(suffix=".data", prefix="trid_") #: Write data stream to tmp file with open(name, "wb") as f: f.write(self.data) #: Run exiftool on tmp file try: r = envoy.run('/opt/trid/trid ' + name, timeout=15) except AttributeError: print_error('ERROR: TrID Failed.') return 'trid', dict(error='TrID failed to run.') else: #: return key, stdout as a dictionary return 'trid', self.format_output(r.std_out.split(name)[-1]) finally: #: delete tmp file unlink(name)
def __init__(self, ip, port, apikey=''): self.ip = ip self.port = port self.apikey = apikey self.connected = True try: requests.get(url='http://{0}:{1}/metascan_rest/stat'.format(self.ip, self.port), timeout=5) except requests.exceptions.Timeout: print_error("Could not connect to Metascan Server.") print_error("Could not connect to Metascan Server.") self.connected = False except requests.exceptions.ConnectionError: print_error("Max retries exceeded.") except requests.exceptions.RequestException as e: print_error("Metascan Error: {}".format(e))
def __init__(self, ip, port, apikey=''): self.ip = ip self.port = port self.apikey = apikey self.connected = True try: requests.get(url='http://{0}:{1}/metascan_rest/stat'.format( self.ip, self.port), timeout=5) except requests.exceptions.Timeout: print_error("Could not connect to Metascan Server.") print_error("Could not connect to Metascan Server.") self.connected = False except requests.exceptions.ConnectionError: print_error("Max retries exceeded.") except requests.exceptions.RequestException as e: print_error("Metascan Error: {}".format(e))