Skip to main content

xargs

Pipe HEREDOC to xargs

When creating a HEREDOC, you can use any keyword to denote the start and end of the HEREDOC block. In this case, I used the keyword HEREDOC but any word can be substituted in its place.

# -I % indicates the "placeholder" value for the current item in the pipeline
# Each line of the HEREDOC -- 10.6.6.1, 10.6.6.2, 10.6.6.3 -- is piped to xargs as stdin
# xargs processes each item one at a time and runs the specified command against stdin
# In this case, the command is a nmap scan of the top 1,000 ports of target IP
cat << HEREDOC | xargs -I % nmap -Pn --top-ports 1000 -oN % %
10.6.6.1
10.6.6.2
10.6.6.3
HEREDOC

Multi-Threading with xargs

awk '{print $0}' ~/Pentest/WordLists/rockyou.txt | 
xargs -0 -P 10 -I {} bash -c "/usr/bin/tool --password='{}' locked_file.ext && echo 'Password is: {}'"

A generic example of using a password list and tool to brute force a password