mirror of https://github.com/n1nj4sec/pupy.git
This commit is contained in:
commit
351c345ed4
|
@ -15,16 +15,20 @@ class SearchModule(PupyModule):
|
|||
terminate = None
|
||||
|
||||
def init_argparse(self):
|
||||
self.arg_parser = PupyArgumentParser(prog="search", description=self.__doc__)
|
||||
example = 'Examples:\n'
|
||||
example += '>> run search .*ini passw.*=.*\n'
|
||||
example += '>> run search .* passw.*=.* -I\n'
|
||||
|
||||
self.arg_parser = PupyArgumentParser(prog="search", description=self.__doc__, epilog=example)
|
||||
self.arg_parser.add_argument('-p', '--path', default='.', help='root path to start (default: current path)')
|
||||
self.arg_parser.add_argument('-m','--max-size', type=int, default=20000000, help='max file size (default 20 Mo)')
|
||||
self.arg_parser.add_argument('-b', '--binary', action='store_true', help='search content inside binary files')
|
||||
self.arg_parser.add_argument('-L', '--links', action='store_true', help='follow symlinks')
|
||||
self.arg_parser.add_argument('-D', '--download', action='store_true', help='download found files (imply -N)')
|
||||
self.arg_parser.add_argument('-N', '--no-content', action='store_true', help='if string matches, output just filename')
|
||||
self.arg_parser.add_argument('-I', '--insensitive', action='store_true', default=False, help='no case sensitive')
|
||||
self.arg_parser.add_argument('filename', type=str, metavar='filename', help='regex to search (filename)')
|
||||
self.arg_parser.add_argument('strings', nargs='*', default=[], type=str,
|
||||
metavar='string', help='regex to search (content)')
|
||||
self.arg_parser.add_argument('strings', nargs='*', default=[], type=str, metavar='string', help='regex to search (content)')
|
||||
|
||||
def run(self, args):
|
||||
self.terminate = threading.Event()
|
||||
|
@ -38,7 +42,10 @@ class SearchModule(PupyModule):
|
|||
max_size=args.max_size,
|
||||
root_path=args.path,
|
||||
follow_symlinks=args.links,
|
||||
no_content=args.no_content
|
||||
no_content=args.no_content,
|
||||
case=args.insensitive,
|
||||
binary=args.binary,
|
||||
terminate=self.terminate
|
||||
)
|
||||
|
||||
download_folder = None
|
||||
|
@ -54,7 +61,8 @@ class SearchModule(PupyModule):
|
|||
return
|
||||
|
||||
if args.strings and not args.no_content:
|
||||
self.success('{}: {}'.format(*res))
|
||||
if type(res) == tuple:
|
||||
self.success('{}: {}'.format(*res))
|
||||
else:
|
||||
if args.download and download is not None and ros is not None:
|
||||
dest = res.replace('!', '!!').replace('/', '!').replace('\\', '!')
|
||||
|
|
|
@ -12,11 +12,17 @@ import rpyc
|
|||
class Search():
|
||||
def __init__(self, path,
|
||||
strings=[], max_size=20000000, root_path='.', no_content=False,
|
||||
binary=False, follow_symlinks=False, terminate=None):
|
||||
case=False, binary=False, follow_symlinks=False, terminate=None):
|
||||
self.max_size = int(max_size)
|
||||
self.follow_symlinks = follow_symlinks
|
||||
self.no_content = no_content
|
||||
self.binary = binary
|
||||
self.case = case
|
||||
|
||||
if self.case:
|
||||
i = re.IGNORECASE
|
||||
else:
|
||||
i = 0
|
||||
|
||||
path = os.path.expandvars(os.path.expanduser(path))
|
||||
|
||||
|
@ -26,17 +32,17 @@ class Search():
|
|||
self.path = None
|
||||
elif path.startswith('/'):
|
||||
root_path = os.path.dirname(path)
|
||||
self.name = re.compile(os.path.basename(path))
|
||||
self.name = re.compile(os.path.basename(path), i)
|
||||
self.path = None
|
||||
elif '/' in path:
|
||||
self.path = re.compile(path)
|
||||
self.path = re.compile(path, i)
|
||||
self.name = None
|
||||
else:
|
||||
self.name = re.compile(path)
|
||||
self.name = re.compile(path, i)
|
||||
self.path = None
|
||||
|
||||
self.strings = [
|
||||
re.compile(string) for string in strings
|
||||
re.compile(string, i) for string in strings
|
||||
]
|
||||
|
||||
self.terminate = terminate
|
||||
|
|
Loading…
Reference in New Issue