Skip to content

Commit b5d8ddb

Browse files
author
David Garcia
committed
Provides enhaced scripting support.
Merge branch 'wvdongen-master'
2 parents 3c8841b + c3a8117 commit b5d8ddb

3 files changed

Lines changed: 46 additions & 22 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ optional arguments:
7070
--capitalize Transform 'word' into 'Word'.
7171
--strip-extension Strip word extension: word.ext into word
7272
--alpha Filter non alphanumeric words from wordlist
73+
--no-progress Don't show tested words and progress. (For dumb terminals)
74+
--no-colors Don't use output colors to keep output clean, e.g. when redirecting output to file
7375

7476
License, requests, etc: https://github.com/deibit/cansina
7577
```
@@ -84,7 +86,7 @@ Screenshot
8486
Installing dependencies
8587
=======================
8688

87-
pip install --user requests[security] or pip install -r requeriments.txt
89+
pip install --user requests[security] or pip install -r requirements.txt
8890

8991
(try removing --user and install with sudo in case of errors)
9092

cansina.py

100755100644
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ def _make_cookie_jar(_cookies):
184184
help="Strip word extension: word.ext into word", default=False, action="store_true")
185185
parser.add_argument('--alpha', dest='only_alpha',
186186
help="Filter non alphanumeric words from wordlist", default=False, action="store_true")
187+
parser.add_argument('--no-progress', dest='no_progress',
188+
help="Don't show tested words and progress. (For dumb terminals)", default=False, action="store_true")
189+
parser.add_argument('--no-colors', dest='no_colors',
190+
help="Don't use output colors to keep output clean, e.g. when redirecting output to file", default=False, action="store_true")
187191

188192
args = parser.parse_args()
189193

@@ -350,7 +354,9 @@ def _make_cookie_jar(_cookies):
350354
#
351355
# Manager queue configuration
352356
#
353-
database_name = urlparse.urlparse(target).hostname
357+
database_name = urlparse.urlparse(target).scheme + '_' + urlparse.urlparse(target).hostname
358+
if urlparse.urlparse(target).port is not None:
359+
database_name += '_' + str(urlparse.urlparse(target).port)
354360
manager = DBManager(database_name)
355361
manager_lock = threading.Lock()
356362

@@ -396,6 +402,8 @@ def _make_cookie_jar(_cookies):
396402
Console.show_full_path = full_path
397403
Console.show_content_type = show_content_type
398404
Console.header()
405+
Console.set_show_progress(False if args.no_progress else True)
406+
Console.set_show_colors(False if args.no_colors else True)
399407

400408
#
401409
# Create the thread_pool and start the daemonized threads

core/printer.py

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ class Console:
8787
visited = {}
8888
number_of_requests = 0
8989
number_of_threads = 0
90+
show_progress = True
91+
show_colors = True
92+
93+
@staticmethod
94+
def set_show_progress(show_progress):
95+
Console.show_progress = show_progress
96+
97+
def set_show_colors(show_colors):
98+
Console.show_colors = show_colors
9099

91100
@staticmethod
92101
def start_eta_queue(size):
@@ -117,22 +126,26 @@ def body(task):
117126
elif os.name == 'nt':
118127
return
119128

129+
to_format = "{1: ^3} | {2: >10} | {3: >6} | {4: >4} | {7} [{0: >2}%] - {5: ^9} - {6}"
130+
to_format_without_progress = "{0: ^3} | {1: >10} | {2: >6} | {3: >4} | {5:^} {4}"
131+
120132
color = ""
121-
if task.response_code == "200":
122-
color = GREEN
123-
if task.response_code == "401" or task.response_code == "403":
124-
color = RED
125-
if task.response_code == "404" and (not task.response_code in task.banned_response_codes):
126-
color = GRAY
127-
if task.response_code == "301" or task.response_code == "302":
128-
color = LBLUE
129-
if task.response_code.startswith('5') or task.response_code == '400':
130-
color = YELLOW
131-
if task.content_detected:
132-
color = MAGENTA
133-
134-
to_format = color + "{1: ^3} | {2: >10} | {3: >6} | {4: >4} | {7} [{0: >2}%] - {5: ^9} - {6}" + ENDC
135-
to_format_without_progress = color + "{0: ^3} | {1: >10} | {2: >6} | {3: >4} | {5:^} {4}" + ENDC
133+
if Console.show_colors:
134+
if task.response_code == "200":
135+
color = GREEN
136+
if task.response_code == "401" or task.response_code == "403":
137+
color = RED
138+
if task.response_code == "404" and (not task.response_code in task.banned_response_codes):
139+
color = GRAY
140+
if task.response_code == "301" or task.response_code == "302":
141+
color = LBLUE
142+
if task.response_code.startswith('5') or task.response_code == '400':
143+
color = YELLOW
144+
if task.content_detected:
145+
color = MAGENTA
146+
147+
to_format = color + to_format + ENDC
148+
to_format_without_progress = color + to_format_without_progress + ENDC
136149

137150
# User wants to see full path
138151
if Console.show_full_path:
@@ -171,7 +184,7 @@ def body(task):
171184
t_encode = t_encode[:abs(COLUMNS - Console.MIN_COLUMN_SIZE)]
172185

173186
# if an entry is about to be log, remove percentage and eta time
174-
if color and not task.response_code in task.banned_response_codes:
187+
if color is not None and not task.response_code in task.banned_response_codes:
175188
to_console = to_format_without_progress.format(task.response_code,
176189
task.response_size,
177190
task.number,
@@ -180,16 +193,17 @@ def body(task):
180193

181194
sys.stdout.write(to_console[:COLUMNS-2] + os.linesep)
182195
# print with progress
183-
else:
196+
elif Console.show_progress:
184197
to_console = to_format.format(percentage, task.response_code,
185198
task.response_size, task.number,
186199
int(task.response_time),
187200
Console.eta,
188201
t_encode, content_type)
189202

190-
sys.stdout.write(to_console[:COLUMNS-2])
203+
sys.stdout.write(to_console[:COLUMNS-2])
204+
sys.stdout.write('\r')
205+
191206
sys.stdout.flush()
192-
sys.stdout.write('\r')
193207

194-
if not os.name == 'nt':
208+
if not os.name == 'nt' and Console.show_progress:
195209
sys.stdout.write("\x1b[0K")

0 commit comments

Comments
 (0)