Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def add_target(self, target):
ret = False
if isinstance(target, bytes):
target = target.decode()
if isinstance(target, str):
kb.targets.add(target)
ret = True
else:
err_msg = "[PLUIGIN] invalid target format: {0}".format(target)
logger.error(err_msg)
return ret
def check_token(self):
if self.token_is_available():
return True
else:
user = input("Fofa API user:")
new_token = getpass.getpass("Fofa API token:")
self.token = new_token
self.user = user
if self.token_is_available():
self.write_conf()
return True
else:
logger.error("The Fofa api token is incorrect. "
"Please enter the correct api token.")
self.check_token()
def command_setg(self, *args, **kwargs):
key, _, value = args[0].partition(" ")
if key in self.current_module.global_options:
self.current_module.setg_option(key, value)
logger.info("{} => {}".format(key, value))
else:
logger.error("You can't set option '{}'.\n"
"Available options: {}".format(key, self.current_module.options))
def exception_handled_function(thread_function, args=(), silent=False):
try:
thread_function(*args)
except KeyboardInterrupt:
kb.thread_continue = False
kb.thread_exception = True
raise
except Exception as ex:
if not silent:
logger.error("thread {0}: {1}".format(threading.currentThread().getName(), str(ex)))
if conf.verbose > 1:
traceback.print_exc()
def wrapper(self, *args, **kwargs):
if not self.current_module:
logger.error("You have to activate any module with 'use' command.")
return
return fn(self, *args, **kwargs)
self.token,
urllib.parse.quote(
dork),
page)
resp = requests.get(url)
if resp and resp.status_code == 200 and "total" in resp.json():
content = resp.json()
for match in content['matches']:
ans = match['ip_str']
if 'port' in match:
ans += ':' + str(match['port'])
search_result.add(ans)
else:
logger.error("[PLUGIN] Shodan:{}".format(resp.text))
except Exception as ex:
logger.error(str(ex))
return search_result
elif cmd.lower() == "clear":
clear_history()
data_to_stdout("[i] history cleared\n")
elif cmd.lower() in ("x", "q", "exit", "quit", "bye"):
break
client.conn.send(str.encode(cmd + '\n'))
resp = poll_cmd_execute(client)
data_to_stdout(resp)
except Exception as ex:
logger.error(str(ex))
data_to_stdout("Connection Lost\n")
break
return True
def check_environment():
try:
os.path.isdir(module_path())
except Exception:
err_msg = "your system does not properly handle non-ASCII paths. "
err_msg += "Please move the pocsuite's directory to the other location"
logger.critical(err_msg)
raise SystemExit
listen_host = "::"
else:
s = socket.socket(socket.AF_INET, protocol)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
try:
s.bind((listen_host, listen_port))
except socket.error:
s.close()
# import traceback
# traceback.print_exc()
return None
if protocol == socket.SOCK_STREAM:
msg = "listening on {0}:{1}".format(listen_host, listen_port)
logger.log(CUSTOM_LOGGING.SYSINFO, msg)
s.listen(5)
return s