OJ / gobuster

Directory/File, DNS and VHost busting tool written in Go
Apache License 2.0
9.28k stars 1.16k forks source link

Don't print escape sequence when no-color flag is set #482

Closed dozernz closed 5 months ago

dozernz commented 5 months ago

Gobuster prints a terminal escape sequence "\r\x1b[2K" at the start of each output finding to clear the terminal line, even when there is no TTY. The escape codes can cause trouble when piped to some CLI tools.

This PR prevents the escape code from being printed when the 'no-color' flag is set. Here's how the output differs:

# ./gobuster dns --quiet -w /tmp/wl  --do google.com -i | hexdump -C
00000000  0d 1b 5b 32 4b 77 77 77  2e 67 6f 6f 67 6c 65 2e  |..[2Kwww.google.|
00000010  63 6f 6d 20 49 50 73 3a  20 32 36 30 37 3a 66 38  |com IPs: 2607:f8|
00000020  62 30 3a 34 30 30 35 3a  38 31 33 3a 3a 32 30 30  |b0:4005:813::200|
00000030  34 2c 31 34 32 2e 32 35  30 2e 31 38 39 2e 31 36  |4,142.250.189.16|
00000040  34 0a 0d 1b 5b 32 4b 73  69 74 65 73 2e 67 6f 6f  |4...[2Ksites.goo|
00000050  67 6c 65 2e 63 6f 6d 20  49 50 73 3a 20 32 36 30  |gle.com IPs: 260|
00000060  37 3a 66 38 62 30 3a 34  30 30 35 3a 38 30 32 3a  |7:f8b0:4005:802:|
00000070  3a 32 30 30 65 2c 31 34  32 2e 32 35 31 2e 34 36  |:200e,142.251.46|
00000080  2e 32 33 38 0a 0d 1b 5b  32 4b 66 65 65 64 73 2e  |.238...[2Kfeeds.|
00000090  67 6f 6f 67 6c 65 2e 63  6f 6d 20 49 50 73 3a 20  |google.com IPs: |
000000a0  31 30 38 2e 31 37 30 2e  32 31 37 2e 31 36 30 0a  |108.170.217.160.|
000000b0
# ./gobuster dns --no-color --quiet -w /tmp/wl  --do google.com -i | hexdump -C
00000000  0d 77 77 77 2e 67 6f 6f  67 6c 65 2e 63 6f 6d 20  |.www.google.com |
00000010  49 50 73 3a 20 32 36 30  37 3a 66 38 62 30 3a 34  |IPs: 2607:f8b0:4|
00000020  30 30 35 3a 38 30 31 3a  3a 32 30 30 34 2c 31 34  |005:801::2004,14|
00000030  32 2e 32 35 30 2e 37 32  2e 31 39 36 0a 0d 73 69  |2.250.72.196..si|
00000040  74 65 73 2e 67 6f 6f 67  6c 65 2e 63 6f 6d 20 49  |tes.google.com I|
00000050  50 73 3a 20 32 36 30 37  3a 66 38 62 30 3a 34 30  |Ps: 2607:f8b0:40|
00000060  30 35 3a 38 30 65 3a 3a  32 30 30 65 2c 31 34 32  |05:80e::200e,142|
00000070  2e 32 35 30 2e 31 38 39  2e 31 37 34 0a 0d 66 65  |.250.189.174..fe|
00000080  65 64 73 2e 67 6f 6f 67  6c 65 2e 63 6f 6d 20 49  |eds.google.com I|
00000090  50 73 3a 20 31 30 38 2e  31 37 30 2e 32 31 37 2e  |Ps: 108.170.217.|
000000a0  31 36 30 0a                                       |160.|
000000a4
firefart commented 5 months ago

the control characters are from the progress bar. If you use the —no-progress flag this should remove them

dozernz commented 5 months ago

I still see them being output even with the --no-progress flag, in both the dev and master branches.

# ./gobuster dns  --no-progress --quiet -w /tmp/wl  --do google.com -i | xxd
2024/01/29 21:40:50 maxprocs: Leaving GOMAXPROCS=2: CPU quota undefined
00000000: 0d1b 5b32 4b73 6974 6573 2e67 6f6f 676c  ..[2Ksites.googl
00000010: 652e 636f 6d20 4950 733a 2032 3630 373a  e.com IPs: 2607:
firefart commented 5 months ago

thanks this is now fixed on the dev branch when used with --no-progress

dozernz commented 5 months ago

Great, thanks!