1

I have 10 php files like

0.php , 1.php, 2.php etc

All those files contains an auth form which send two inputs username and password to itself via post.

After login there is a message displayed.

I am trying to write a script which fills out the login form for each page and then echo the message from each page on a new line.

I know that I can fill the form using wget or curl but I am not so sure how.

I tried with curl -u username:password /host/files/0.php but seems that it just displays the html output of that file.

I am thinking of writing a shell script which does the followind:

pages = [0.php; 1.php; etc...]
foreach page in pages
        access page via curl or wget, fill in the form with username and password    which are the same for all files
        echo respons
        newline

How can I achieve this?

1 Answer 1

1

What you were doing "-u username:password" is as far as I know a HTTP basic authentication which is different from filling out a form and sending it via POST. This should work:

#!/bin/bash
pages="0.php 1.php 2.php"

for page in ${pages}; do
  wget -q --post-data 'user=username&password=password' --save-cookies cookies "http://server/${page}"
  wget -O- --load-cookies cookies -p "http://server/${page}"
done
4
  • This seems to be the right approach. But seems that it stills output the form html instead of what happens after filling that form with username and password Jan 12, 2015 at 20:34
  • Try the updated solution. It saves the cookies set after the authentication attempt, then reuses them in the subsequent request. Jan 12, 2015 at 22:02
  • What about using curl -d "user=user&pass=pass" server ?.. Jan 13, 2015 at 1:13
  • Feel free to examine man pages of both wget and curl for the differences, now that you know how to do this with wget. Especially that this specific example is in the wget's man page. Jan 13, 2015 at 6:12

Not the answer you're looking for? Browse other questions tagged .