Skip to content

Commit

Permalink
Merge pull request #31 from knownsec/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
wh0am1i authored Mar 24, 2021
2 parents 4e9dcbe + 157d390 commit 06e957b
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 24 deletions.
3 changes: 2 additions & 1 deletion zoomeye/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@

__name__ = 'zoomeye'
__package__ = 'zoomeye'
__version__ = '2.0.4.2'
__version__ = ' 2.0.4.3'
__site__ = "https://www.zoomeye.org/doc"
26 changes: 15 additions & 11 deletions zoomeye/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
sys.path.insert(1, module_path)

from zoomeye import core
from zoomeye import __version__
from zoomeye.config import BANNER


def get_version():
return "ZoomEye-python version number {}".format(__version__)
print(BANNER)


class ZoomEyeParser(argparse.ArgumentParser):
Expand All @@ -36,19 +36,19 @@ def main():
:return:
"""

parser = ZoomEyeParser()
parser = ZoomEyeParser(prog='zoomeye')
subparsers = parser.add_subparsers()
# show ZoomEye-python version number
parser.add_argument(
"-v",
"--version",
action="store_true",
help="show program's version number and exit"
)

# zoomeye account info
parser_info = subparsers.add_parser("info", help="Show ZoomEye account info")
parser_info.set_defaults(func=core.info)
# show version number
parser.add_argument(
'-v', '--version',
action='version',
version=get_version(),
help="Show program's version number and exit"
)

# query zoomeye data
parser_search = subparsers.add_parser(
Expand Down Expand Up @@ -88,7 +88,7 @@ def main():
type=str,
help=('''
Output more clearer search results by set filter field,
field: [app,version,device,port,city,country,asn,banner,*]
field: [app,version,device,port,city,country,asn,banner,time,*]
''')
)
parser_search.add_argument(
Expand Down Expand Up @@ -190,6 +190,10 @@ def main():

args = parser.parse_args()

if args.version:
get_version()
exit(0)

try:
args.func(args)
except AttributeError:
Expand Down
21 changes: 20 additions & 1 deletion zoomeye/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Author: liuf5
*/
"""
import string
from zoomeye import __version__, __site__


# save api key file and json web token file path
Expand Down Expand Up @@ -38,3 +38,22 @@
"\x1b[91m", "\x1b[92m"]

COLOR_RESET = "\x1b[0m"

BANNER = """\033[01;33m
,----,
.' .`| ____ ,---,.
.' .' ; ,' , `. ,' .' |
,---, ' .' ,---. ,---. ,-+-,.' _ |,---.' |
| : ./ ' ,'\ ' ,'\ ,-+-. ; , ||| | .'
; | .' / / / | / / | ,--.'|' | ||: : |-, .--, ,---. \033[01;37m{%s }\033[01;33m
`---' / ; . ; ,. :. ; ,. :| | ,', | |,: | ;/| /_ ./| / \
/ ; / ' | |: :' | |: :| | / | |--' | : .' , ' , ' : / / |
; / /--,' | .; :' | .; :| : | | , | | |-,/___/ \: |. ' / |
/ / / .`|| : || : || : | |/ ' : ;/| . \ ' |' ; /|
./__; : \ \ / \ \ / | | |`-' | | \ \ ; :' | / |
| : .' `----' `----' | ;/ | : .' \ \ ;| : |
; | .' '---' | | ,' : \ \\ \ / \033[01;37m %s \033[01;33m
`---' `----' \ ' ; `----'
`--` \033[0m\033[4;37m\033[0m
""" % (__version__, __site__)
12 changes: 6 additions & 6 deletions zoomeye/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def regexp_data(self, keys):
"""
keys = keys.split(",")
result = []
self.zoomeye.data_list = self.dork_data[:self.num]
self.zoomeye.data_list = self.dork_data

data_list = self.zoomeye.data_list
return regexp(keys, fields_tables_host, data_list)
Expand Down Expand Up @@ -390,13 +390,13 @@ def cli_filter(self, keys, save=False):
# the filter condition is app, port
# ex: ip,port,app
else:
equal_data = self.dork_data[:self.num]
equal_data = self.dork_data
# get result
result = filter_search_data(not_equal, fields_tables_host, equal_data)
equal = ','.join(not_equal)
if save:
return equal, result
show.print_filter(equal, result)
show.print_filter(equal, result[:self.num], has_equal)

def save(self, fields):
"""
Expand Down Expand Up @@ -611,9 +611,9 @@ def filter_fields(self, fields):
not_equal.append(field_item)
# match filters that contain specific data
if len(has_equal) != 0:
result_data = regexp(has_equal, fields_tables_history_host, data[:self.num])
result_data = regexp(has_equal, fields_tables_history_host, data)
else:
result_data = data[:self.num]
result_data = data
# no regexp data
if len(result_data) == 0:
return
Expand All @@ -625,4 +625,4 @@ def filter_fields(self, fields):
"filter command has unsupport fields [{}], support fields has [{}]".format(item, support_fields),
color='red')
exit(0)
show.print_filter_history(not_equal, result_data)
show.print_filter_history(not_equal, result_data[:self.num], has_equal)
35 changes: 30 additions & 5 deletions zoomeye/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Author: liuf5
*/
"""
import datetime
import re
from colorama import init

from zoomeye import config, data, plotlib
Expand Down Expand Up @@ -110,11 +110,12 @@ def print_data(data_list):
printf("total: {}".format(total))


def print_filter(keys, data):
def print_filter(keys, data_list, condition=None):
"""
used to display user filtered data on the terminal
:param keys: user input key, is str
:param data: filter data ,is list
:param data_list: filter data ,is list
:param condition: list,
:return:
"""
total = 0
Expand All @@ -125,10 +126,19 @@ def print_filter(keys, data):
printf("{}".format(title), color="green")

# print data
for i in data:
for i in data_list:
items = ""
for j in i:
j_hex = convert_str(str(j))
# match to content highlight
if condition:
for item in condition:
k, v = item.split('=')
result_re = re.search(v, j_hex, re.I | re.M)
if result_re:
# replace to highlight
color_content = "\033[31m{}\033[0m".format(result_re.group())
j_hex = j_hex.replace(result_re.group(), color_content)
items += "{:<30}".format(j_hex)
total += 1
printf(items)
Expand Down Expand Up @@ -244,6 +254,9 @@ def print_host_data(host_data):
"""
:param host_data, list,
"""
# host data is None
if len(host_data) == 0:
return
# parser hostname,country,city... information
first_item = host_data[0]
all_data, port_count = data.filter_history_data(data.fields_tables_history_host.keys(), host_data)
Expand Down Expand Up @@ -272,17 +285,20 @@ def print_host_data(host_data):
printf(content)


def print_filter_history(fileds, hist_data):
def print_filter_history(fileds, hist_data, condition=None):
"""
print user filter history data,
:param fileds list,user input field
:param hist_data dict, from ZoomEye API get data
:param condition list, filter condition
"""
filter_title = ''
first_item = hist_data[0]
# filter data
all_data, port_count = data.filter_history_data(fileds, hist_data, omit=False)
printf(first_item.get('ip'))
dict_first_item = data.ZoomEyeDict(first_item)
# parser filter data title
for dict_item in data.tables_history_info.keys():
result = dict_first_item.find(data.tables_history_info.get(dict_item))
if result == "" or result is None or result == "Unknown":
Expand All @@ -299,5 +315,14 @@ def print_filter_history(fileds, hist_data):
for data_item in all_data:
content = ""
for item_item in data_item:
# match to content highlight
if condition:
for condition_item in condition:
k, v = condition_item.split('=')
re_result = re.search(str(v), str(item_item), re.I | re.M)
content = "\033[31m{}\033[0m".format(re_result.group())
# replace to highlight
if re_result:
item_item = item_item.replace(re_result.group(), content)
content += "{:<27}".format(item_item)
printf(content)

0 comments on commit 06e957b

Please sign in to comment.