def copyright():
copyright = """
=[ {0}smali-code-injector v1.1-dev{1} ]
+ -- --=[ Alexandre Teyar @Ares ]
+ -- --=[ Pentester at Ambersail Ltd. ]
+ -- --=[ GitHub: https://github.com/AresS31 ]
""".format(Fore.YELLOW, Fore.RESET)
print("{}".format(copyright))
python类RESET的实例源码
def load_plugins(self):
logger = logging.getLogger(__name__)
if not os.path.isdir(plugin_dir):
return
possible_plugins = os.listdir(plugin_dir)
for filename in possible_plugins:
if not os.path.isfile(os.path.join(plugin_dir, filename)):
continue
split = filename.split('.')
if not (len(split) > 1 and split[-1] == "py"):
continue
name = "".join(split[:-1])
module_info = imp.find_module(name, [plugin_dir])
try:
module = imp.load_module(name, *module_info)
dir_list = dir(module)
if ("get_label" in dir_list) and ("run_command" in dir_list):
self.plugins.append(module)
else:
logger.error(Fore.RED + "'%s' is not a valid plugin!" + Fore.RESET, filename)
except Exception as e:
logger.error(Fore.RED + "%s error while loading plugin '%s': \n %s" + Fore.RESET,
type(e).__name__, filename, e)
finally:
module_info[0].close()
# Return a list of loaded plugins
def print_major_alarms(mj):
"""
Args:
mj (int): Counts of major alarms
Returns:
str: Colorized information by using colorama
"""
if mj > 0:
return Back.RED + Fore.WHITE + str(mj) + Fore.RESET + Back.RESET
else:
return Fore.GREEN + str(mj) + Fore.RESET
def print_minor_alarms(mn):
"""
Args:
mn (int): Counts of minor alarms
Returns:
str: Colorized information by using colorama
"""
if mn > 0:
return Fore.RED + str(mn) + Fore.RESET
else:
return Fore.GREEN + str(mn) + Fore.RESET
def print_warnings(wn):
"""
Args:
wn (int): Counts of warnings
Returns:
str: Colorized information by using colorama
"""
if wn > 0:
return Fore.YELLOW + str(wn) + Fore.RESET
else:
return Fore.GREEN + str(wn) + Fore.RESET
def run(self):
try:
arp_header = struct.unpack('!2s2s1s1s2s6s4s6s4s', self.arpdata[14:42])
if hexlify(arp_header[4]) == "0002" and hexlify(arp_header[5]) != self.GW_MAC.replace(":","") and socket.inet_ntoa(arp_header[6]) == self.GW_IP:
try:
if hexlify(arp_header[5]) not in Attacker:
Attacker.append(hexlify(arp_header[5]))
print "="*50
print foreground.RED + "ARP Poison Detected" + foreground.RESET
print "="*50
print "******************_ARP_HEADER_******************"
print "Hardware Type: ", hexlify(arp_header[0])
print "Protocol Type: ", hexlify(arp_header[1])
print "Hardware Size: ", hexlify(arp_header[2])
print "Protocol Size: ", hexlify(arp_header[3])
print "Opcode: ", opcodes[hexlify(arp_header[4])]
print "Attacker's MAC : ", foreground.RED + hexlify(arp_header[5]) + foreground.RESET
print "Source IP : ", socket.inet_ntoa(arp_header[6])
print "Destination MAC : ", hexlify(arp_header[7])
print "Destination IP : ", socket.inet_ntoa(arp_header[8])
else:
pass
except:
pass
except:
pass
def success(self, msg, *args, **kwargs):
self._log(SUCCESS, BEERS_EMOJI + ' ' + Fore.LIGHTWHITE_EX + msg + Fore.RESET, args, **kwargs)
def addition(self, msg, *args, **kwargs):
self._log(ADDITION, BEERS_EMOJI + ' ' + Fore.LIGHTWHITE_EX + msg + Fore.RESET, args, **kwargs)
def do_match(self, s):
"""Matches patterns in a string by using regex."""
if six.PY2:
file_name = raw_input(Fore.RED + "Enter file name?:\n" + Fore.RESET)
pattern = raw_input(Fore.GREEN + "Enter string:\n" + Fore.RESET)
else:
file_name = input(Fore.RED + "Enter file name?:\n" + Fore.RESET)
pattern = input(Fore.GREEN + "Enter string:\n" + Fore.RESET)
file_name = file_name.strip()
if file_name == "":
print("Invalid Filename")
else:
system("grep '" + pattern + "' " + file_name)
def do_movies(self, s):
"""Jarvis will find a good movie for you."""
if six.PY2:
movie_name = raw_input(
Fore.RED + "What do you want to watch?\n" + Fore.RESET)
else:
movie_name = input(
Fore.RED + "What do you want to watch?\n" + Fore.RESET)
system("ims " + movie_name)
def postcmd(self, stop, line):
"""Hook that executes after every command."""
if self.first_reaction:
self.prompt = (
Fore.RED +
"{} What can i do for you?\n".format(PROMPT_CHAR) + Fore.RESET
)
self.first_reaction = False
if self.enable_voice:
self.speech.text_to_speech("What can i do for you?\n")
def test_calc(self):
# Test a basic calculation
calc("2 powER 7 PLUS (6.7 Minus 3) diVided BY 0.45 bY 3", self.jarvis)
sys.stdout.seek(0)
output = sys.stdout.read().strip()
result = Fore.BLUE + str(2 ** 7 + (6.7 - 3) / 0.45 / 3) + Fore.RESET
self.assertEqual(output, result)
# And now for something a little more _complex_
sys.stdout = StringIO()
calc("(1 pluS 9.1j)^3.14129 mINUS 2.712", self.jarvis)
sys.stdout.seek(0)
output = sys.stdout.read().strip()
result = Fore.BLUE + str((1 + 9.1j)**3.14129 - 2.712) + Fore.RESET
self.assertEqual(output, result)
def read_file(name, default=None):
if os.path.exists(name):
try:
with open(name, "r+") as f:
return json.load(f)
except ValueError:
print(
Fore.RED + "Storage file not in right format. Backup stored as {0}.bak".format(name) + Fore.RESET)
os.rename(name, name + ".bak")
return default
def print_after(path):
print(Fore.LIGHTBLUE_EX + "\nFolders after cleaning\n" + Fore.RESET)
for files in os.listdir(path):
print(files, sep=',\t')
print(Fore.LIGHTMAGENTA_EX + "\nCLEANED\n" + Fore.RESET)
def commentary(desc):
mid = match_id(desc)
data = c.commentary(mid)
comm = {}
comm['matchinfo'] = "{}, {}".format(data['matchinfo']['mnum'], data['matchinfo']['mchdesc'])
comm['status'] = "{}, {}".format(data['matchinfo']['mchstate'].title(), data['matchinfo']['status'])
comm['commentary'] = data['commentary']
text = ''
text += Fore.LIGHTYELLOW_EX + comm['matchinfo'] + '\n' + comm['status'] + '\n\n' + Fore.RESET
for com in comm['commentary']:
text += "{}\n\n".format(com)
return text
def locate_me():
hcity = get_location()['city']
print(Fore.BLUE + "You are at " + hcity + Fore.RESET)
def weather(city=None):
if not city:
city = get_location()['city']
# Checks country
country = get_location()['country_name']
# If country is US, shows weather in Fahrenheit
if country == 'United States':
send_url = (
"http://api.openweathermap.org/data/2.5/weather?q={0}"
"&APPID=ab6ec687d641ced80cc0c935f9dd8ac9&units=imperial".format(
city)
)
unit = ' ºF in '
# If country is not US, shows weather in Celsius
else:
send_url = (
"http://api.openweathermap.org/data/2.5/weather?q={0}"
"&APPID=ab6ec687d641ced80cc0c935f9dd8ac9&units=metric".format(
city)
)
unit = ' ºC in '
r = requests.get(send_url)
j = json.loads(r.text)
# check if the city entered is not found
if 'message' in j and j['message'] == 'city not found':
print(Fore.BLUE + "City Not Found" + Fore.RESET)
return False
else:
temperature = j['main']['temp']
description = j['weather'][0]['main']
print(Fore.BLUE + "It's " + str(temperature) + unit +
str(city) + " (" + str(description) + ")" + Fore.RESET)
return True
def search_near(things, city=0):
if city:
print(Fore.GREEN + "Hold on!, I'll show " + things +
" near " + city + Fore.RESET)
url = "https://www.google.com/maps/search/{0}+{1}".format(things, city)
else:
print(Fore.GREEN + "Hold on!, I'll show " +
things + " near you" + Fore.RESET)
url = "https://www.google.com/maps/search/{0}/@{1},{2}".format(
things, get_location()['latitude'], get_location()['longitude'])
webbrowser.open(url)
def main(self, s):
# Trim input command to get only the location
loc = s.replace('weather', '').replace('in ', '').strip()
# Checks country
country = mapps.get_location()['country_name']
# If country is US, shows weather in Fahrenheit
if country == 'United States':
send_url = (
"http://api.openweathermap.org/data/2.5/weather?q={0}"
"&APPID=ab6ec687d641ced80cc0c935f9dd8ac9&units=imperial".format(
loc)
)
unit = ' ºF in '
# If country is not US, shows weather in Celsius
else:
send_url = (
"http://api.openweathermap.org/data/2.5/weather?q={0}"
"&APPID=ab6ec687d641ced80cc0c935f9dd8ac9&units=metric".format(loc)
)
unit = ' ºC in '
r = requests.get(send_url)
j = json.loads(r.text)
if 'message' in list(j.keys()) and ('city not found' in j['message'] or 'Nothing to geocode' in j['message']):
return pinpoint.main(Memory(), self, s)
temperature = j['main']['temp']
description = j['weather'][0]['main']
location = j['name']
print(Fore.BLUE + "It's " + str(temperature) + unit +
str(location.title()) + " (" + str(description) + ")" + Fore.RESET)
def critical(string):
print(Fore.RED + string + Fore.RESET)