I'd like to feed a network daemon using a loop!

To be more specific: There is a network daemon listening on localhost:portx. The daemon expects me to guess a PIN between 0000 - 9999. I want to use brute force for guessing. And there is no limit to number of attempts. Is it possbile to iterate over those numbers, faster than the following approach?

for $i in {0000..9999}
    (echo "$i" | netcat portx localhost)

That's really slow because of connecting everytime. One pass takes 1 second, that's 10000 seconds in worst case.

Is there a netcat parameter to connect faster?
Or, maybe there's whole another solution?

  • Why it takes 1 second for each connection? If it's an intended pause inserted by the daemon when wrong PIN passed, there would be few options you could take to improve speed. Can the daemon accept multiple connections simultaneously? Can it accept multiple auth tries in one connection? If possible, how should PINs be sent in the stream by the client? – yaegashi Jul 23 '15 at 0:37
  • @yaegashi The daemon allows multiple auth tries in one connection. Barmar's suggestion, piping the output of loop to netcat, worked very well for me. I got the right PIN in under a second, hehe – onebyzero Jul 23 '15 at 9:27

Pipe the output of the loop to netcat:

for i in {0000..9999}
    echo "$i"
done | netcat portx localhost

This assumes that the daemon will take in multiple PINs separated by newlines.

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.