Skip to main content
Wrapped code.
Source Link
agc
  • 7.4k
  • 4
  • 25
  • 54

A for loop is unnecessary. Use strings to output a filename and a decimal offset, then pipe any strings of at least three chars long to egrep:

strings -n 3 -f -t d ./* 2> /dev/null | 
egrep '[[:alnum:][:punct:]]*(secret|password|key|credential|http)[['\
'[[:alnum:][:punct:]]*$' 

Three chars instead of the default four is needed so as not to miss "key".

Since we lack sample input files, here's a demo showing the first ten hits in the /bin/ directory:

strings -n 3 -f -t d /bin/* 2> /dev/null |  
egrep '[[:alnum:][:punct:]]*(secret|password|key|credential|http)[['\
'[[:alnum:][:punct:]]*$' | 
head

Output on my system:

/bin/bash:   78590 rl_discard_keymap
/bin/bash:   78720 rl_executing_key
/bin/bash:   79076 rl_bind_key
/bin/bash:   79847 emacs_standard_keymap
/bin/bash:   79905 _rl_keymap
/bin/bash:   81110 _rl_executing_keyseq_size
/bin/bash:   81598 rl_bind_keyseq_if_unbound
/bin/bash:   81640 rl_bind_keyseq
/bin/bash:   81736 bind_keyseq_to_unix_command
/bin/bash:   81863 _rl_dispatching_keymap

A for loop is unnecessary. Use strings to output a filename and a decimal offset, then pipe any strings of at least three chars long to egrep:

strings -n 3 -f -t d ./* 2> /dev/null | 
egrep '[[:alnum:][:punct:]]*(secret|password|key|credential|http)[[:alnum:][:punct:]]*$' 

Three chars instead of the default four is needed so as not to miss "key".

Since we lack sample input files, here's a demo showing the first ten hits in the /bin/ directory:

strings -n 3 -f -t d /bin/* 2> /dev/null |  
egrep '[[:alnum:][:punct:]]*(secret|password|key|credential|http)[[:alnum:][:punct:]]*$' | 
head

Output on my system:

/bin/bash:   78590 rl_discard_keymap
/bin/bash:   78720 rl_executing_key
/bin/bash:   79076 rl_bind_key
/bin/bash:   79847 emacs_standard_keymap
/bin/bash:   79905 _rl_keymap
/bin/bash:   81110 _rl_executing_keyseq_size
/bin/bash:   81598 rl_bind_keyseq_if_unbound
/bin/bash:   81640 rl_bind_keyseq
/bin/bash:   81736 bind_keyseq_to_unix_command
/bin/bash:   81863 _rl_dispatching_keymap

A for loop is unnecessary. Use strings to output a filename and a decimal offset, then pipe any strings of at least three chars long to egrep:

strings -n 3 -f -t d ./* 2> /dev/null | 
egrep '[[:alnum:][:punct:]]*(secret|password|key|credential|http)'\
'[[:alnum:][:punct:]]*$' 

Three chars instead of the default four is needed so as not to miss "key".

Since we lack sample input files, here's a demo showing the first ten hits in the /bin/ directory:

strings -n 3 -f -t d /bin/* 2> /dev/null |  
egrep '[[:alnum:][:punct:]]*(secret|password|key|credential|http)'\
'[[:alnum:][:punct:]]*$' | 
head

Output on my system:

/bin/bash:   78590 rl_discard_keymap
/bin/bash:   78720 rl_executing_key
/bin/bash:   79076 rl_bind_key
/bin/bash:   79847 emacs_standard_keymap
/bin/bash:   79905 _rl_keymap
/bin/bash:   81110 _rl_executing_keyseq_size
/bin/bash:   81598 rl_bind_keyseq_if_unbound
/bin/bash:   81640 rl_bind_keyseq
/bin/bash:   81736 bind_keyseq_to_unix_command
/bin/bash:   81863 _rl_dispatching_keymap
Code tweak.
Source Link
agc
  • 7.4k
  • 4
  • 25
  • 54

A for loop is unnecessary. Use strings to output a filename and a decimal offset, then pipe thoseany strings of at least three chars long to egrep:

strings -n 3 -f -t d ./* 2> /dev/null | 
egrep '[[:alnum:][:punct:]]*(secret|password|key|credential|http)[[:alnum:][:punct:]]*$' 

Three chars instead of the default four is needed so as not to miss "key".

Since we lack sample input files, here's a demo showing the first ten hits in the /bin/ directory:

strings -n 3 -f -t d /bin/* 2> /dev/null |  
egrep '[[:alnum:][:punct:]]*(secret|password|key|credential|http)[[:alnum:][:punct:]]*$' | 
head

Output on my system:

/bin/bash:   78590 rl_discard_keymap
/bin/bash:   78720 rl_executing_key
/bin/bash:   79076 rl_bind_key
/bin/bash:   79847 emacs_standard_keymap
/bin/bash:   79905 _rl_keymap
/bin/bash:   8164081110 rl_bind_keyseq_rl_executing_keyseq_size
/bin/bash:   8186381598 _rl_dispatching_keymaprl_bind_keyseq_if_unbound
/bin/bash:   8244181640 rl_binding_keymaprl_bind_keyseq
/bin/bash:   8361181736 rl_set_keybind_keyseq_to_unix_command
/bin/bash:   8465781863 rl_set_keymap_rl_dispatching_keymap

A for loop is unnecessary. Use strings to output a filename and a decimal offset, then pipe those to egrep:

strings -f -t d ./* 2> /dev/null | 
egrep '[[:alnum:]]*(secret|password|key|credential|http)[[:alnum:]]*$' 

Since we lack sample input files, here's a demo showing the first ten hits in the /bin/ directory:

strings -f -t d /bin/* 2> /dev/null |  
egrep '[[:alnum:]]*(secret|password|key|credential|http)[[:alnum:]]*$' | 
head

Output on my system:

/bin/bash:   78590 rl_discard_keymap
/bin/bash:   78720 rl_executing_key
/bin/bash:   79076 rl_bind_key
/bin/bash:   79847 emacs_standard_keymap
/bin/bash:   79905 _rl_keymap
/bin/bash:   81640 rl_bind_keyseq
/bin/bash:   81863 _rl_dispatching_keymap
/bin/bash:   82441 rl_binding_keymap
/bin/bash:   83611 rl_set_key
/bin/bash:   84657 rl_set_keymap

A for loop is unnecessary. Use strings to output a filename and a decimal offset, then pipe any strings of at least three chars long to egrep:

strings -n 3 -f -t d ./* 2> /dev/null | 
egrep '[[:alnum:][:punct:]]*(secret|password|key|credential|http)[[:alnum:][:punct:]]*$' 

Three chars instead of the default four is needed so as not to miss "key".

Since we lack sample input files, here's a demo showing the first ten hits in the /bin/ directory:

strings -n 3 -f -t d /bin/* 2> /dev/null |  
egrep '[[:alnum:][:punct:]]*(secret|password|key|credential|http)[[:alnum:][:punct:]]*$' | 
head

Output on my system:

/bin/bash:   78590 rl_discard_keymap
/bin/bash:   78720 rl_executing_key
/bin/bash:   79076 rl_bind_key
/bin/bash:   79847 emacs_standard_keymap
/bin/bash:   79905 _rl_keymap
/bin/bash:   81110 _rl_executing_keyseq_size
/bin/bash:   81598 rl_bind_keyseq_if_unbound
/bin/bash:   81640 rl_bind_keyseq
/bin/bash:   81736 bind_keyseq_to_unix_command
/bin/bash:   81863 _rl_dispatching_keymap
Source Link
agc
  • 7.4k
  • 4
  • 25
  • 54

A for loop is unnecessary. Use strings to output a filename and a decimal offset, then pipe those to egrep:

strings -f -t d ./* 2> /dev/null | 
egrep '[[:alnum:]]*(secret|password|key|credential|http)[[:alnum:]]*$' 

Since we lack sample input files, here's a demo showing the first ten hits in the /bin/ directory:

strings -f -t d /bin/* 2> /dev/null |  
egrep '[[:alnum:]]*(secret|password|key|credential|http)[[:alnum:]]*$' | 
head

Output on my system:

/bin/bash:   78590 rl_discard_keymap
/bin/bash:   78720 rl_executing_key
/bin/bash:   79076 rl_bind_key
/bin/bash:   79847 emacs_standard_keymap
/bin/bash:   79905 _rl_keymap
/bin/bash:   81640 rl_bind_keyseq
/bin/bash:   81863 _rl_dispatching_keymap
/bin/bash:   82441 rl_binding_keymap
/bin/bash:   83611 rl_set_key
/bin/bash:   84657 rl_set_keymap