Skip to content

Commit a7420e4

Browse files
authored
Merge pull request #265 from SylvainM98/test/pattern-improvements
Improve pattern system: tests, code fixes, and count_patterns()
2 parents 5997af2 + 9429ee7 commit a7420e4

7 files changed

Lines changed: 758 additions & 81 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ Scan multiple emails/usernames from a file (one email/username per line):
102102
user-scanner -ef emails.txt # bulk email scan
103103
user-scanner -uf usernames.txt # bulk username scan
104104
```
105+
106+
### Pattern generation
107+
See [Pattern Syntax](docs/PATTERNS.md) for more details
108+
105109
---
106110
### Library mode for email_scan
107111
Only available for `user-scanner>=1.2.0`

docs/PATTERNS.md

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
# Pattern Syntax Guide
2+
3+
The pattern system allows you to generate multiple username or email variations from a single compact pattern definition. This is useful for searching variations of a username/email similar to your desire.
4+
5+
## Quick Start
6+
7+
Use patterns directly with the `-u` (username) or `-e` (email) flags:
8+
9+
```bash
10+
# Scan "johna", "johnb", "johnc"
11+
user-scanner -u "john[a-c]"
12+
13+
# Scan up to 50 permutations instead of default 100
14+
user-scanner -u "john[0-9]{0-2}" -s 50
15+
16+
# Scan multiple variations with case differences
17+
user-scanner -u "[jJ]ohn[0-9]{1-2}"
18+
19+
# With emails
20+
user-scanner -e "user[a-z]{0-1}@example.com"
21+
```
22+
23+
The `-s` flag (short for `--stop`) limits how many permutations are scanned. By default, only the first 100 are checked.
24+
25+
## Pattern Syntax
26+
27+
### Character Sets: `[chars]`
28+
29+
Define a character set using square brackets. Characters between the brackets will each become a separate variation.
30+
31+
**Examples:**
32+
33+
```
34+
john[abc] → "johna", "johnb", "johnc"
35+
user[0-9] → "user0", "user1", ..., "user9"
36+
test[a-zA-Z] → "testa", "testb", ..., "testZ"
37+
site[_.-] → "site_", "site.", "site-"
38+
```
39+
40+
**Character Range Syntax:**
41+
42+
- `[a-z]` - lowercase letters a through z
43+
- `[A-Z]` - uppercase letters A through Z
44+
- `[0-9]` - digits 0 through 9
45+
- `[a-zA-Z0-9]` - combined ranges
46+
- `[abc]` - literal characters a, b, c
47+
48+
**Note**: "-" must be placed at the beginning or at the end of the range to be interpreted as a character.
49+
50+
### Length Control: `[chars]{len}`
51+
52+
Specify the length of expansions from a character set.
53+
54+
**Examples:**
55+
56+
```
57+
john[a-z]{0-2} → "john", "johna", "johnb", ..., "johnz", "johnaa", ..., "johnzz"
58+
code[0-9]{2} → "code00", "code01", ..., "code99"
59+
user[a-c]{1;3} → "usera", "userb", "userc", "useraa", ..., "userccc"
60+
text[0-1]{1-3} → "text0", "text1", "text00", "text01", "text10", "text11", ..., "text111"
61+
```
62+
63+
**Length Syntax:**
64+
65+
- `{n}` - exactly n characters
66+
- `{n-m}` - between n and m characters (inclusive)
67+
- `{n;m}` - exactly n or m characters
68+
- `{0-n}` - zero to n characters
69+
70+
## Common Use Cases
71+
72+
### Username Variations with Numbers
73+
74+
```bash
75+
user-scanner -u "john[0-9]{0-3}"
76+
```
77+
78+
Scans up to 100 variations: `john`, `john0``john9`, `john00``john99`, `john000``john999`
79+
80+
### Multiple Name Parts with Case Variations
81+
82+
```bash
83+
user-scanner -u "[jJ]ohn[0-9]{0-2}"
84+
```
85+
86+
Scans variations like: `john`, `John`, `john0``john99`, `John0``John99`
87+
88+
### Underscore and Dot Variations
89+
90+
```bash
91+
user-scanner -u "user[_.]name"
92+
```
93+
94+
Scans: `user_name`, `user.name`
95+
96+
### Email with Variations
97+
98+
```bash
99+
user-scanner -e "user[a-z]{0-1}@example.com"
100+
```
101+
102+
Scans email addresses: `user@example.com`, `usera@example.com``userz@example.com`
103+
104+
### Limiting Scan Results
105+
106+
Use the `-s` or `--stop` flag to limit how many permutations are checked:
107+
108+
```bash
109+
# Check only 10 permutations instead of default 100
110+
user-scanner -u "john[0-9]{0-3}" -s 10
111+
```
112+
113+
The tool will show you how many permutations are available:
114+
115+
```
116+
[+] Scanning 10 of 1111 permutations
117+
```
118+
119+
### Viewing Available Permutations
120+
121+
The tool automatically shows how many variations were found and scans up to the limit you set.
122+
123+
## Performance Tips
124+
125+
1. **Start with limits** - Always use `-s` to limit how many permutations you scan:
126+
127+
```bash
128+
user-scanner -u "pattern[0-9]{0-3}" -s 25
129+
```
130+
131+
2. **Check pattern complexity** - A pattern like `[a-z]{5}` would generate 11,881,376 combinations. Start small and increase gradually.
132+
133+
3. **Use moderate ranges** - Keep character sets and length ranges reasonable:
134+
- Good: `[a-c]{0-2}` (~15 variations)
135+
- Risky: `[a-z]{0-3}` (~18,278 variations)
136+
137+
4. **Combine with other filters** - Use `-c` (category) or `-m` (module) to narrow the scope:
138+
139+
```bash
140+
user-scanner -u "user[a-z]{0-1}" -c social -s 50
141+
```
142+
143+
5. **Add delays between requests** - Use the `--delay` flag to avoid rate limiting:
144+
```bash
145+
user-scanner -u "test[0-9]{1-2}" --delay 1.0
146+
```
147+
148+
## CLI Examples
149+
150+
### Simple usernames with numbers
151+
152+
```bash
153+
user-scanner -u "johnny[0-9]{0-2}"
154+
```
155+
156+
### Case variations
157+
158+
```bash
159+
user-scanner -u "[jJ]ohn[0-9]{1-2}"
160+
```
161+
162+
### Multiple separators
163+
164+
```bash
165+
user-scanner -u "john[._-]doe"
166+
```
167+
168+
### Complex pattern with limited scans
169+
170+
```bash
171+
user-scanner -u "user[a-z]{0-1}[0-9]{0-2}" -s 50
172+
```
173+
174+
### Email pattern variations
175+
176+
```bash
177+
user-scanner -e "[jJ]ohn[_.]doe@example.com"
178+
```
179+
180+
### Combining with other flags
181+
182+
```bash
183+
# Scan a pattern with verbose output and delay between requests
184+
user-scanner -u "admin[0-9]{1-2}" -v --delay 0.5 -s 25
185+
186+
# Scan with a specific category
187+
user-scanner -u "user[a-c]" -c social -s 50
188+
```
189+
190+
## Pattern Limitations
191+
192+
- Do not nest brackets: `[[a-z]]` is invalid
193+
- Ranges must go from lower to higher ASCII values (e.g., `[z-a]` is invalid)
194+
- The pattern engine is designed for generating variations, not complex regex-like patterns

tests/test_helpers.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,6 @@
1010
from user_scanner.core.result import Result
1111

1212

13-
def test_generate_permutations():
14-
perms = helpers.generate_permutations("user", "ab", limit=None)
15-
assert "user" in perms
16-
# All permutations must be valid
17-
assert all(
18-
p == "user" or (p.startswith("user") and len(p) > len("user")) for p in perms
19-
)
20-
21-
assert len(perms) > 1
22-
23-
24-
def test_generate_permutations_email():
25-
perms = helpers.generate_permutations(
26-
"john@email.com", "abc", limit=None, is_email=True
27-
)
28-
assert "john@email.com" in perms
29-
assert all(
30-
p == "john@email.com"
31-
or (
32-
p.startswith("john")
33-
and len(p) > len("john@email.com")
34-
and p.endswith("@email.com")
35-
)
36-
for p in perms
37-
)
38-
assert len(perms) > 1
39-
40-
4113
def test_get_site_name():
4214
def module(name: str) -> SimpleNamespace:
4315
return SimpleNamespace(**{"__name__": name})

0 commit comments

Comments
 (0)