1

I'm doing a challenge where I have to feed a password (which I have) and a 4 digit passcode (which can only be found via brute-forcing all 10000 possibilities) to a netcat daemon. Currently I'm doing

#!/bin/bash
PWD='HpNYTlstOGHyQXmg6gzctqAwOmw1NiPQ'
for n in `seq 1 9999`;
do
    STR=`echo $PWD $n | nc localhost 30002`
    echo "passcode $n: $STR"
done

but this is very slow: it does maybe 1 passcode a second. Could I do something like

#!/bin/bash
PWD='HpNYTlstOGHyQXmg6gzctqAwOmw1NiPQ'
nc localhost 30002 #somehow pipe the output to a file without closing it
for n in `seq 1 9999`;
do
    echo "$PWD $n" #echo a line into the stdin of nc
    #set STR equal to whatever was outputted from nc
    echo "passcode $n: $STR"
done

When I use nc manually, I can send and recieve multiple lines in one nc instance. However, it seems that I can only send one line in bash, which doesn't seem right. How can I send multiple lines, one at a time, to nc?

0

1 Answer 1

5

at the end of for loop:

done | nc localhost 30002

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.