Skip to content

Commit

Permalink
version 2.1.3#dev update
Browse files Browse the repository at this point in the history
1. add --repeat function
2. simplify global filter code
  • Loading branch information
LandGrey committed May 16, 2019
1 parent 76c52e9 commit d89b056
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 84 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pydictor

[![build](https://img.shields.io/badge/build-passing-brightgreen.svg)](https://www.github.com/landgrey/pydictor) [![Python 2.7&3.4](https://img.shields.io/badge/python-2.7&3.4-yellow.svg)](https://www.python.org/) ![release](https://img.shields.io/badge/version-2.1.2-orange.svg) ![License](https://img.shields.io/badge/license-GPLv3-red.svg)
[![build](https://img.shields.io/badge/build-passing-brightgreen.svg)](https://www.github.com/landgrey/pydictor) [![Python 2.7&3.4](https://img.shields.io/badge/python-2.7&3.4-yellow.svg)](https://www.python.org/) ![release](https://img.shields.io/badge/version-2.1.3-orange.svg) ![License](https://img.shields.io/badge/license-GPLv3-red.svg)

**README.md [中文版](README_CN.md)**

Expand Down Expand Up @@ -48,7 +48,7 @@ A: 1.it always can help you
```
git clone --depth=1 --branch=master https://www.github.com/landgrey/pydictor.git
cd pydictor/
chmod 755 pydictor.py
chmod +x pydictor.py
python pydictor.py
```

Expand Down Expand Up @@ -106,7 +106,7 @@ python pydictor.py
| regex | F7 | filter by regex |
| level | F8 | set the word list rule level |
| leet | F9 | enable 1337 mode |

| repeat | F10 | filter by consecutive repeat times of letter、digital、special chars |

#### encode function supported encodings and encryptions

Expand Down Expand Up @@ -138,7 +138,13 @@ python pydictor.py
#### types function
`Usage : --types [letters_types_range] [digital_types_range] [special_types_range]`

`Example: --types "<=8" "<=4" "=0"`
`Example: --types "<=8" "<=4" "==0"`


#### repeat function
`Usage : --repeat [letters_repeat_times] [digital_repeat_times] [special_repeat_times]`

`Example: --repeat "<=3" ">=3" "==0"`


#### regex function
Expand Down
12 changes: 9 additions & 3 deletions README_CN.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# pydictor
[![build](https://img.shields.io/badge/build-passing-brightgreen.svg)](https://www.github.com/landgrey/pydictor) [![Python 2.7&3.4](https://img.shields.io/badge/python-2.7&3.4-yellow.svg)](https://www.python.org/) ![release](https://img.shields.io/badge/version-2.1.2-orange.svg) ![License](https://img.shields.io/badge/license-GPLv3-red.svg)
[![build](https://img.shields.io/badge/build-passing-brightgreen.svg)](https://www.github.com/landgrey/pydictor) [![Python 2.7&3.4](https://img.shields.io/badge/python-2.7&3.4-yellow.svg)](https://www.python.org/) ![release](https://img.shields.io/badge/version-2.1.3-orange.svg) ![License](https://img.shields.io/badge/license-GPLv3-red.svg)

**README.md [English](README.md)**

Expand Down Expand Up @@ -48,7 +48,7 @@ A: 1.生成密码它总会帮到你
```
git clone --depth=1 --branch=master https://www.github.com/landgrey/pydictor.git
cd pydictor/
chmod 755 pydictor.py
chmod +x pydictor.py
python pydictor.py
```

Expand Down Expand Up @@ -110,7 +110,7 @@ python pydictor.py
| regex | F7 | 正则筛选 |
| level | F8 | 字典级别筛选 |
| leet | F9 | 1337 模式 |

| repeat | F10 | 字母、数字、特殊字符连续出现次数范围筛选 |

#### 支持的编码或加密方式

Expand Down Expand Up @@ -145,6 +145,12 @@ python pydictor.py
`示例: --types "<=8" "<=4" "=0"`


#### repeat 功能
`用法 : --repeat [字母连续出现次数范围] [数字连续出现次数范围] [特殊字符连续出现次数范围]`

`示例: --repeat "<=3" ">=3" "==0"`


#### regex 功能
`用法 : --regex [正则表达式]`

Expand Down
33 changes: 27 additions & 6 deletions core/SEDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# coding:utf-8
#
"""
Copyright (c) 2016-2017 LandGrey (https://github.com/LandGrey/pydictor)
Copyright (c) 2016-2019 LandGrey (https://github.com/LandGrey/pydictor)
License: GNU GENERAL PUBLIC LICENSE Version 3
"""

Expand All @@ -14,11 +14,10 @@

from core.EXTEND import extend_enter
from lib.fun.decorator import magic
from lib.fun.filter import filterforfun
from lib.data.data import paths, pystrs, pyoptions
from lib.fun.osjudger import is_Windows, is_Linux, is_Mac
from lib.data.text import help_dict, helpmsg, pydictor_art_text
from lib.fun.fun import cool, unique, finishprinter, walks_all_files, mybuildtime, finalsavepath, fun_name
from lib.fun.fun import cool, walks_all_files, mybuildtime, finalsavepath, fun_name
from rules.EB import EB
from rules.NB import NB
from rules.SB import SB
Expand Down Expand Up @@ -131,6 +130,10 @@ def do_show(self, key, setflag=False):
(pyoptions.letter_types, pyoptions.digital_types, pyoptions.special_types,
description="types")))

print(cool.orange("{description:11}: letter: [ {0:5}] digital: [ {1:5}] special: [ {2:5} ]".format
(pyoptions.letter_repeat, pyoptions.digital_repeat, pyoptions.special_repeat,
description="repeat")))

print(cool.orange("{description:11}: [{0}]".format(pyoptions.level, description="level")))

if pyoptions.sedb_leet:
Expand Down Expand Up @@ -207,6 +210,7 @@ def do_occur(self, key):
print(cool.fuchsia("[!] usage: occur letter digital special" + pyoptions.CRLF) +
cool.blue("[?] exp: occur <=6 >4 >=0") + pyoptions.CRLF)
else:
pyoptions.occur_is_filter = True
letter = chunk[0].strip('"').strip("'")
digital = chunk[1].strip('"').strip("'")
special = chunk[2].strip('"').strip("'")
Expand All @@ -223,6 +227,7 @@ def do_types(self, key):
print(cool.fuchsia("[!] usage: types letter digital special" + pyoptions.CRLF) +
cool.blue("[?] exp: types <=6 >4 >=0") + pyoptions.CRLF)
else:
pyoptions.types_is_filter = True
letter = chunk[0].strip('"').strip("'")
digital = chunk[1].strip('"').strip("'")
special = chunk[2].strip('"').strip("'")
Expand All @@ -233,11 +238,29 @@ def do_types(self, key):
(cool.green(pyoptions.letter_types), cool.green(pyoptions.digital_types),
cool.green(pyoptions.special_types)) + pyoptions.CRLF)

def do_repeat(self, key):
chunk = key.split(' ')
if len(chunk) != 3:
print(cool.fuchsia("[!] usage: repeat letter digital special" + pyoptions.CRLF) +
cool.blue("[?] exp: repeat <=6 >4 >=0") + pyoptions.CRLF)
else:
pyoptions.repeat_is_filter = True
letter = chunk[0].strip('"').strip("'")
digital = chunk[1].strip('"').strip("'")
special = chunk[2].strip('"').strip("'")
pyoptions.letter_repeat = letter if letter != "" else pyoptions.letter_repeat
pyoptions.digital_repeat = digital if digital != "" else pyoptions.digital_repeat
pyoptions.special_repeat = special if special != "" else pyoptions.special_repeat
print("[+] letter repeat: {0} digital types: {1} special types: {2}".format
(cool.green(pyoptions.letter_repeat), cool.green(pyoptions.digital_repeat),
cool.green(pyoptions.special_repeat)) + pyoptions.CRLF)

def do_regex(self, key):
chunk = key.split(' ')
if len(chunk) != 1:
print(cool.fuchsia("[!] usage: regex filter-string" + pyoptions.CRLF))
else:
pyoptions.regex_is_filter = True
pyoptions.filter_regex = chunk[0]
print("[+] regex: {0}".format(cool.green(pyoptions.filter_regex)) + pyoptions.CRLF)

Expand Down Expand Up @@ -293,14 +316,12 @@ def do_output(self, key):
except WindowsError:
print(pyoptions.CRLF + cool.red("[-] Cannot create result file: %s " % paths.results_path))
finally:
this_name = '%s_%s%s' % (pystrs.SEDB_prefix, mybuildtime(), pyoptions.filextension) \
this_name = 'SEDB_%s%s' % (mybuildtime(), pyoptions.filextension) \
if paths.results_file_name == None else paths.results_file_name
print("[+] store path: {0}".format(cool.green(os.path.join(paths.results_path, this_name
if paths.results_file_name != None else ''))) + pyoptions.CRLF)

def do_run(self, args):
storepath = finalsavepath(fun_name())

pystrs.startime = time.time()
results = []
paths.results_file_name = None
Expand Down
24 changes: 18 additions & 6 deletions lib/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# coding:utf-8
#
"""
Copyright (c) 2016-2017 LandGrey (https://github.com/LandGrey/pydictor)
Copyright (c) 2016-2019 LandGrey (https://github.com/LandGrey/pydictor)
License: GNU GENERAL PUBLIC LICENSE Version 3
"""

Expand Down Expand Up @@ -56,7 +56,7 @@ def init_pystrs():
# start time
pystrs.startime = time.time()

pystrs.version = '2.1.2#dev'
pystrs.version = '2.1.3#dev'

# build configuration file element description
pystrs.conf_head = "head"
Expand Down Expand Up @@ -141,15 +141,27 @@ def init_pyoptions():
pyoptions.encode = "none"
pyoptions.minlen = 0
pyoptions.maxlen = 4
pyoptions.default_occurs = "<=99"
pyoptions.letter_occur = pyoptions.default_occurs
pyoptions.digital_occur = pyoptions.default_occurs
pyoptions.special_occur = pyoptions.default_occurs

pyoptions.default_occur = "<=99"
pyoptions.occur_is_filter = False
pyoptions.letter_occur = pyoptions.default_occur
pyoptions.digital_occur = pyoptions.default_occur
pyoptions.special_occur = pyoptions.default_occur

pyoptions.default_types = ">=0"
pyoptions.types_is_filter = False
pyoptions.letter_types = pyoptions.default_types
pyoptions.digital_types = pyoptions.default_types
pyoptions.special_types = pyoptions.default_types

pyoptions.default_repeat = ">=0"
pyoptions.repeat_is_filter = False
pyoptions.letter_repeat = pyoptions.default_repeat
pyoptions.digital_repeat = pyoptions.default_repeat
pyoptions.special_repeat = pyoptions.default_repeat

pyoptions.filter_regex = ".*?"
pyoptions.regex_is_filter = False

# the lower the more items
pyoptions.level = 3
Expand Down
6 changes: 3 additions & 3 deletions lib/data/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# coding:utf-8
#
"""
Copyright (c) 2016-2017 LandGrey (https://github.com/LandGrey/pydictor)
Copyright (c) 2016-2019 LandGrey (https://github.com/LandGrey/pydictor)
License: GNU GENERAL PUBLIC LICENSE Version 3
"""

Expand Down Expand Up @@ -31,8 +31,8 @@
[+]show option [+]set option arguments [+]rm option
[+]len minlen maxlen [+]head prefix [+]tail suffix
[+]encode type [+]occur L d s [+]types L d s
[+]regex string [+]level code [+]leet code
[+]output directory [+]run
[+]repeat L d s [+]regex string [+]level code
[+]leet code [+]output directory [+]run
----------------------------[ {3} ]----------------------------
[+]{4} [+]{5} [+]{6}
Expand Down
17 changes: 2 additions & 15 deletions lib/fun/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# coding:utf-8
# author: LandGrey
"""
Copyright (c) 2016-2017 LandGrey (https://github.com/LandGrey/pydictor)
Copyright (c) 2016-2019 LandGrey (https://github.com/LandGrey/pydictor)
License: GNU GENERAL PUBLIC LICENSE Version 3
"""

Expand All @@ -19,20 +19,7 @@ def magic(func):
try:
with open(storepath, "a") as f:
for item in unique(func()):
item = filterforfun(item, head=pyoptions.head, tail=pyoptions.tail,
lenght_is_filter=pyoptions.args_pick,
minlen=pyoptions.minlen, maxlen=pyoptions.maxlen,
regex_is_filter=True, regex=pyoptions.filter_regex,
encode_is_filter=True, encode=pyoptions.encode,
occur_is_filter=True,
letter_occur=pyoptions.letter_occur,
digital_occur=pyoptions.digital_occur,
special_occur=pyoptions.special_occur,
types_is_filter=True,
letter_types=pyoptions.letter_types,
digital_types=pyoptions.digital_types,
special_types=pyoptions.special_types,
)
item = filterforfun(item)
if item:
f.write(item + pyoptions.CRLF)
finishprinter(storepath)
Expand Down
91 changes: 62 additions & 29 deletions lib/fun/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
# coding:utf-8
#
"""
Copyright (c) 2016-2017 LandGrey (https://github.com/LandGrey/pydictor)
Copyright (c) 2016-2019 LandGrey (https://github.com/LandGrey/pydictor)
License: GNU GENERAL PUBLIC LICENSE Version 3
"""

import re
import string
from lib.fun.fun import cool
from itertools import groupby
from collections import Counter
from lib.data.data import pyoptions

Expand All @@ -28,11 +29,8 @@ def headtail_filter(item, head='', tail=''):
return item


def encode_filter(item, encode='none', encode_is_filter=False):
if item and encode_is_filter:
return pyoptions.operator.get(encode)(item)
else:
return item
def encode_filter(item, encode='none'):
return pyoptions.operator.get(encode)(item)


def occur_filter(item, letter_occur=pyoptions.letter_occur, digital_occur=pyoptions.digital_occur,
Expand Down Expand Up @@ -121,7 +119,53 @@ def types_filter(item, letter_types=pyoptions.letter_types, digital_types=pyopti
'=': d_types == d_wanttypes, '==': d_types == d_wanttypes, }
special_map = {'<': s_types < s_wanttypes, '<=': s_types <= s_wanttypes,
'>': s_types > s_wanttypes, '>=': s_types >= s_wanttypes,
'=': s_types == s_wanttypes, '==': s_types == s_wanttypes,}
'=': s_types == s_wanttypes, '==': s_types == s_wanttypes, }
if letter_map[l_op] and digital_map[d_op] and special_map[s_op]:
return item
else:
return item


def repeat_filter(item, letter_repeat=pyoptions.letter_repeat, digital_repeat=pyoptions.digital_repeat,
special_repeat=pyoptions.special_repeat, repeat_is_filter=False):
if item and repeat_is_filter:
l_repeat = d_repeat = s_repeat = 0
l_op = d_op = s_op = '>='
l_wantrepeat = d_wantrepeat = s_wantrepeat = 0
pattern = '((<|>|=)=?)(\d*)$'
letter_match = re.match(pattern, letter_repeat)
digital_match = re.match(pattern, digital_repeat)
special_match = re.match(pattern, special_repeat)
if letter_match and letter_match.group():
l_op = letter_match.group(1)
l_wantrepeat = int(letter_match.group(len(letter_match.groups())))
if digital_match and digital_match.group():
d_op = digital_match.group(1)
d_wantrepeat = int(digital_match.group(len(digital_match.groups())))
if special_match and special_match.group():
s_op = special_match.group(1)
s_wantrepeat = int(special_match.group(len(special_match.groups())))
groups = groupby(item)
repeat_dict = [{label: sum(1 for _ in group)} for label, group in groups]
for r in repeat_dict:
key = r.keys()[0]
value = r.values()[0]
if key in string.ascii_letters:
l_repeat = max(l_repeat, value)
elif key in string.digits:
d_repeat = max(d_repeat, value)
elif key in string.printable[62:-5]:
s_repeat = max(s_repeat, value)

letter_map = {'<': l_repeat < l_wantrepeat, '<=': l_repeat <= l_wantrepeat,
'>': l_repeat > l_wantrepeat, '>=': l_repeat >= l_wantrepeat,
'=': l_repeat == l_wantrepeat, '==': l_repeat == l_wantrepeat, }
digital_map = {'<': d_repeat < d_wantrepeat, '<=': d_repeat <= d_wantrepeat,
'>': d_repeat > d_wantrepeat, '>=': d_repeat >= d_wantrepeat,
'=': d_repeat == d_wantrepeat, '==': d_repeat == d_wantrepeat, }
special_map = {'<': s_repeat < s_wantrepeat, '<=': s_repeat <= s_wantrepeat,
'>': s_repeat > s_wantrepeat, '>=': s_repeat >= s_wantrepeat,
'=': s_repeat == s_wantrepeat, '==': s_repeat == s_wantrepeat, }
if letter_map[l_op] and digital_map[d_op] and special_map[s_op]:
return item
else:
Expand Down Expand Up @@ -189,26 +233,15 @@ def pos_change(position, init_pos, is_start=True):
return _


def filterforfun(item,
head=pyoptions.head, tail=pyoptions.tail,
minlen=pyoptions.minlen, maxlen=pyoptions.maxlen,
letter_occur=pyoptions.default_occurs,
digital_occur=pyoptions.default_occurs,
special_occur=pyoptions.special_occur,
letter_types=pyoptions.default_types,
digital_types=pyoptions.default_types,
special_types=pyoptions.default_types,
regex=pyoptions.filter_regex, encode=pyoptions.encode,
lenght_is_filter=False, encode_is_filter=False,
occur_is_filter=False, types_is_filter=False,
regex_is_filter=False, ):

item = headtail_filter(item, head=head, tail=tail)
item = lenght_filter(item, minlen=minlen, maxlen=maxlen, lenght_is_filter=lenght_is_filter)
item = occur_filter(item, letter_occur=letter_occur, digital_occur=digital_occur,
special_occur=special_occur, occur_is_filter=occur_is_filter)
item = types_filter(item, letter_types=letter_types, digital_types=digital_types,
special_types=special_types, types_is_filter=types_is_filter)
item = regex_filter(item, regex=regex, regex_is_filter=regex_is_filter)
item = encode_filter(item, encode=encode, encode_is_filter=encode_is_filter)
def filterforfun(item):
item = headtail_filter(item, head=pyoptions.head, tail=pyoptions.tail)
item = lenght_filter(item, minlen=pyoptions.minlen, maxlen=pyoptions.maxlen, lenght_is_filter=pyoptions.args_pick)
item = occur_filter(item, letter_occur=pyoptions.letter_occur, digital_occur=pyoptions.digital_occur,
special_occur=pyoptions.special_occur, occur_is_filter=pyoptions.occur_is_filter)
item = types_filter(item, letter_types=pyoptions.letter_types, digital_types=pyoptions.digital_types,
special_types=pyoptions.special_types, types_is_filter=pyoptions.types_is_filter)
item = repeat_filter(item, letter_repeat=pyoptions.letter_repeat, digital_repeat=pyoptions.digital_repeat,
special_repeat=pyoptions.special_repeat, repeat_is_filter=pyoptions.repeat_is_filter)
item = regex_filter(item, regex=pyoptions.filter_regex, regex_is_filter=pyoptions.regex_is_filter)
item = encode_filter(item, encode=pyoptions.encode)
return item
Loading

0 comments on commit d89b056

Please sign in to comment.