9
9
# 'rpcclient' and 'smbclient'. Other than the original enum4linux.pl, enum4linux-ng parses all output of
10
10
# the previously mentioned commands and (if the user requests so), fills the data in JSON/YAML output.
11
11
# The original enum4linux.pl had the additional dependencies 'ldapsearch' and 'polenum.py'. These are
12
- # natively implemented in enum4linux-ng. Console output is colored.
12
+ # natively implemented in enum4linux-ng. Console output is colored (can be deactivated by setting the
13
+ # environment variable NO_COLOR to an arbitrary value).
13
14
#
14
15
### CREDITS
15
16
# I'd like to thank and give credit to the people at former Portcullis Labs (now Cisco CX Security Labs), namely:
256
257
KNOWN_USERNAMES = "administrator,guest,krbtgt,domain admins,root,bin,none"
257
258
TIMEOUT = 5
258
259
259
- # global_verbose is the only global variable which should be written to
260
+ # global_verbose and global_colors should be the only variables which should be written to
260
261
global_verbose = False
262
+ global_colors = True
261
263
262
264
class Colors :
263
- reset = '\033 [0m'
264
- red = '\033 [91m'
265
- green = '\033 [92m'
266
- yellow = '\033 [93m'
267
- blue = '\033 [94m'
265
+ ansi_reset = '\033 [0m'
266
+ ansi_red = '\033 [91m'
267
+ ansi_green = '\033 [92m'
268
+ ansi_yellow = '\033 [93m'
269
+ ansi_blue = '\033 [94m'
270
+
271
+ @classmethod
272
+ def red (cls , msg ):
273
+ if global_colors :
274
+ return f"{ cls .ansi_red } { msg } { cls .ansi_reset } "
275
+ return msg
276
+
277
+ @classmethod
278
+ def green (cls , msg ):
279
+ if global_colors :
280
+ return f"{ cls .ansi_green } { msg } { cls .ansi_reset } "
281
+ return msg
282
+
283
+ @classmethod
284
+ def yellow (cls , msg ):
285
+ if global_colors :
286
+ return f"{ cls .ansi_yellow } { msg } { cls .ansi_reset } "
287
+ return msg
288
+
289
+ @classmethod
290
+ def blue (cls , msg ):
291
+ if global_colors :
292
+ return f"{ cls .ansi_blue } { msg } { cls .ansi_reset } "
293
+ return msg
268
294
269
295
class Result :
270
296
'''
@@ -2456,7 +2482,7 @@ def valid_workgroup(workgroup):
2456
2482
### Print Functions and Error Processing
2457
2483
2458
2484
def print_banner ():
2459
- print (f"{ Colors .green } ENUM4LINUX - next generation{ Colors . reset } \n " )
2485
+ print (f"{ Colors .green ( ' ENUM4LINUX - next generation' ) } \n " )
2460
2486
2461
2487
def print_heading (text , leading_newline = True ):
2462
2488
output = f"| { text } |"
@@ -2469,16 +2495,16 @@ def print_heading(text, leading_newline=True):
2469
2495
print (" " + "=" * (length - 2 ))
2470
2496
2471
2497
def print_success (msg ):
2472
- print (f" { Colors .green } [+] { msg + Colors . reset } " )
2498
+ print (Colors .green ( f" [+] { msg } " ) )
2473
2499
2474
2500
def print_hint (msg ):
2475
- print (f" { Colors .green } [H] { msg + Colors . reset } " )
2501
+ print (Colors .green ( f" [H] { msg } " ) )
2476
2502
2477
2503
def print_error (msg ):
2478
- print (f" { Colors .red } [-] { msg + Colors . reset } " )
2504
+ print (Colors .red ( f" [-] { msg } " ) )
2479
2505
2480
2506
def print_info (msg ):
2481
- print (f" { Colors .blue } [*] { msg + Colors . reset } " )
2507
+ print (Colors .blue ( f" [*] { msg } " ) )
2482
2508
2483
2509
def print_verbose (msg ):
2484
2510
print (f"[V] { msg } " )
@@ -2513,11 +2539,11 @@ def abort(msg):
2513
2539
This function is used to abort the tool run on error.
2514
2540
The given error message will be printed out and the tool will abort with exit code 1.
2515
2541
'''
2516
- print (f" { Colors .red } [!] { msg + Colors . reset } " )
2542
+ print (Colors .red ( f" [!] { msg } " ) )
2517
2543
sys .exit (1 )
2518
2544
2519
2545
def warn (msg ):
2520
- print (f "\n { Colors .yellow } [!] { msg + Colors . reset } " )
2546
+ print ("\n " + Colors .yellow ( f" [!] { msg } " ) )
2521
2547
2522
2548
def yamlize (msg , sort = False , rstrip = True ):
2523
2549
result = yaml .dump (msg , default_flow_style = False , sort_keys = sort , Dumper = Dumper )
@@ -2534,6 +2560,7 @@ def check_arguments():
2534
2560
'''
2535
2561
2536
2562
global global_verbose
2563
+ global global_colors
2537
2564
2538
2565
parser = ArgumentParser (description = """This tool is a rewrite of Mark Lowe's enum4linux.pl, a tool for enumerating information from Windows and Samba systems.
2539
2566
It is mainly a wrapper around the Samba tools nmblookup, net, rpcclient and smbclient. Other than the original tool it allows to export enumeration results
@@ -2640,6 +2667,11 @@ def check_dependencies():
2640
2667
### Run!
2641
2668
2642
2669
def main ():
2670
+ # The user can disable colored output via environment variable NO_COLOR (see https://no-color.org)
2671
+ global global_colors
2672
+ if "NO_COLOR" in os .environ :
2673
+ global_colors = False
2674
+
2643
2675
print_banner ()
2644
2676
2645
2677
# Check dependencies and process arguments, make sure yaml can handle OrdereDicts
0 commit comments