Using Hydra to dictionary-attack web-based login forms
Using Hydra to dictionary-attack web-based login forms
Hydra can be used to attack many different services including IMAP, SMB, HTTP, VNC, MS-SQL MySQL, SMTP, SSH, and many more.
(Hydra is to online-cracking of passwords, what John The Ripper is to offline-cracking of password hashes)
Often, web-based login forms authenticate using the HTTP POST method, but judging from several blogs I have read on this subject, it sounds like some people have great difficulty in getting Hydra to work effectively in this situation.
I have had a great deal of success with hydra, so here I describe how to get Hydra working with web-based form logins.
This attack is not limited to websites, and I would argue that it is more suited for gaining login access to software products that have a web UI, for example in penetration tests.
This tool should not be used to attack websites or services where you do not have permission to do so. Use this for legitimate testing purposes only.
Some differences between online and off-line password cracking
There are significant differences between online and off-line password cracking.
With off-line cracking, you have the hashes on your system, they are static, and you can try dictionary, hybrid, and brute force attacks to you hearts content. You have as long as you want, and you can try many billions of attempts in a short space of time.
The attack success is purely dependent on password strength, verses processor-power and time (and few user-chosen passwords will be strong enough to last).
With online password attacks there are more issues to consider, such as; network bandwidth, account lockouts, tar-pitting, changing passwords, detection in logs and IDS.
Online attacks are more suited to relatively small and focused dictionary attacks rather than exhaustive brute-force.
A simple Hydra SSH example
Here is a simple example of running a Hydra attack against an SSH server.
This will attack the system 192.1.68.1.26, on port 22 with the SSH protocol, 10 threads at a time, and try all the combinations of usernames and passwords supplied in the files user.txt and pass.txt (+ empty passwords and passwords the same as the username)
This can take a while, so it is best to only use usernames you know exist, and a relatively small list of passwords (many thousands rather than many millions). This attack generally works very well for simple dictionary passwords.
Web-based login forms prerequisites
For web-based forms, you have to know much more information about the form you are attacking before you start the attack. Every web-based form is slightly different, different URLs and parameters, and different responses for success or failure.
You need to know:
- The hostname/IP and URL
- Whether it is a HTTPS or HTTP service
- Whether the form supports GET or POST (or both)
- The parameters of the request
- The difference in response between success and failure
- Whether any session cookies are required to be set or maintained
- What lockout features and thresholds are enabled (if any)
For the parameters of the request, you can intercept and examine a normal login attempt with a web proxy (such as owasp-zap, webscarab or burpsuite) or use a browser plugin (such as tamperdata) or just look at the HTML form.
An example attack
The Web Security Dojo VM has various vulnerable applications that you can use to test these techniques. So looking at an example the w3af testing framework has a test login at the following location
http://192.168.1.69/w3af/bruteforce/form_login/
The important parts of the HTML form are:
<form name="input" action="dataReceptor.php" method="post">
Username:
<input type="text" name="user">
Password:
<input type="password" name="pass">
If we put in one wrong username and password combination we get:
32 comments:
-
John S.4 September 2011 19:52
Really an excellent article!
Reply
Do you know where i can get more information on how to set cookies in Hydra? I've searched the Hydra documentation, and found nothing that would help...
I'm using the DVWA VM for the tests.
Thank you. -
Hi John,
Reply
Yeah, that can be a bit fiddly, but basically you need to set a 'H=Cookie: SESSIONID=j39rf30dj30' or whatever - you might need to play around a bit to get that working.
Regards
BenReplies -
Hey, I am working on a similar issue and have been trying to figure out how to pass the cookie as well.
The Hydra documentation has the example:
"/login:user=^USER&pass=^PASS:failed:H=Authorization: Basic dT1w:H=X-Foo: Bar"
And other than the known typos in the documentation (^USER should be ^USER^ and same for pass) if I try to replicate it I get:
ERROR: Wrong syntax of optional argument: Basic dT1w
I have been doing some research, trying to figure this out without any success. It appears to not be documented anywhere, so are there any other ideas you might have?
Some things I have tried and their results:
hydra -l admin -p admin 192.168.130.142 http-get-form "/dvwa/vulnerabilities/brute/index.php:username=^USER^&password=^PASS^&Login=Login:Username and/or password incorrect.:H=Cookie=security=low; PHPSESSID=mgo7mhnlmtoa7cijjfspdd4i14"
Results: no error but didn't crack the password (which i know is admin:admin)
:H=PHPSESSID=mgo7mhnlmtoa7cijjfspdd4i14"
Results: no error but didn't crack the password.
:H='Set-Cookie:security=low; PHPSESSID=mgo7mhnlmtoa7cijjfspdd4i14'"
Results: ERROR: Wrong syntax of optional argument: security=low; PHPSESSID=mgo7mhnlmtoa7cijjfspdd4i14'
:C=/dvwa/index.php" (using the C optional argument instead, to fetch the cookie)
Results: Error: Child with pid 17899 terminating, can not connect
:C=/dvwa/login.php"
Results: Error: Child with pid 17902 terminating, can not connect
:C=security=low; PHPSESSID=mgo7mhnlmtoa7cijjfspdd4i14"
Results: Error: Child with pid 17907 terminating, can not connect
:H=Cookie=PHPSESSID=mgo7mhnlmtoa7cijjfspdd4i14"
Results: no errors but does not crack the password
:H=PHPSESSID=mgo7mhnlmtoa7cijjfspdd4i14"
Results: no errors but does not crack the password
The most interesting results I obtained, was a combination:
:C=/dvwa/index.php:H=PHPSESSID=mgo7mhnlmtoa7cijjfspdd4i14"
Results: ERROR: Wrong syntax of parameter H, must look like 'H=X-My-Header: MyValue', no http:// : H=PHPSESSID=mgo7mhnlmtoa7cijjfspdd4i14
:C=/dvwa/index.php:H=Cookie: PHPSESSID=mgo7mhnlmtoa7cijffspdd4i14"
Results: Error: Child with pid 18063 terminating, can not connect
:H=PHPSESSID: mgo7mhnlmtoa7cijjfspdd4i14"
Results: ERROR: Wrong syntax of optional argument: mgo7mhnlmtoa7cijjfspdd4i14
This lead me to trying the exact examples given:
:H=Authorization: Basic dT1w:H=X-Foo: Bar"
Results: ERROR: Wrong syntax of optional argument: Basic dT1w -
Anonymous16 October 2011 18:02
like this code:
Reply
form action="/login" method="post"
input type="hidden" name="url" value="^U"
font face="Trebuchet MS,Arial"Please reenter the password:/font input type="password" name="user"
input type="submit" value="Authenticate"
/form -
Hey great article. But when i set the bad login message, hydra doenst reconize. The site do not show a window with the message, just a red phrase under the login bar. So, Hyydra cant reconize this red message. Any suggestions?
Reply -
I am trying to login on honeywell access control netAXS through https.I know user is admin but I can remember the password.if I reset the panel I will erase all csv files and I have to imput manually.Any sugestion guys?
Reply
Thanks! -
Anonymous28 December 2011 03:49
i want 2 crack dvwa login page
Reply
it is the url :http://127.0.0.1/dvwa/vulnerabilities/brute/
how 2 crack it ? and how many user name and passwords i have 2 insert in user name password text files... becoz i know the user name password , but i want 2 learn how hydra will crack it -
Anonymous,
Reply
Right, well; you have all the clues you need above. Go through the bullet points carefully.
Hacking is all about research and experimentation, you need patience and dedication (if you don't want to do that then just go back to the TV).
All the clues are listed above. Work through the bullet points, collect all the information, and do some troubleshooting.
Ben -
Anonymous12 January 2012 09:54
i used this command.... can u tell me what i done wrong ?
command was "hydra 127.0.0.1 http-form-get "/dvwa/vulnerabilities/brute.php:user=^USER^&pass=^PASS^:incorrect" -L users.txt -P pass.txt -t 10 -w 30 -o hydra-http-get-attack.txt -
Anonymous9 February 2012 03:29
How do i find "Bad login" on site i want to brute force. Hydra response me that 10/10 password are valid. Please help
Reply -
Anonymous,
Reply
Well, everything you need to know is on this page, but I can't tell you how to tie your shoelaces because I don't know what kind of shoes you have.
Ben -
Anonymous12 February 2012 01:04
Hi Ben. Thanks for an amzing article. It helped me a lot. I wonder if you can answer one question for me; How can I deal with a form who's action parameter points to another URL instead of a page?
Reply
Here is what I mean:- The form is on http://www.somepage.com/en/login
The form HTML is as follows:-
form name="Login" id="Login" action="https://www.somepage.com/post" method="post" onsubmit="return false;"
Because I notice in your example the FORM ACTION points to another page on the same URL.
Your help is much appreciated. -
Anonymous,
Reply
If there is a difference in the response (which there is) you basically just need Hydra to spot that response.
I.e. what is the difference in the raw data of the response, and work with that.
(You can use Hydra in verbose mode, or wireshark or burp or whatever to look for the difference in detail)
Ben -
Ben,
Reply
BTW - if anyone is using this to article to try to attack websites without permission, they are way too dumb (probably too dumb to make it work anyway).
Your ISP knows every request you make, and attacks like this will "stick out like a sore thumb" when they hand your logs over to the police ;o)
Take care, be good, and remember that if you want to learn something - you will have to do some study.
Regards
Ben -
Anonymous1 March 2012 05:27
Everytime I use hydra without -l or -L I get:
Reply
Error: I need atleast the -l, -L, or -C option to know login
My wifi guest account is setup not to accept a username?
http-post-form /guestnetwork.cgi:pass=^PASS^:S=successful
?? -
Anonymous10 March 2012 10:10
Jonathan
Reply
Hey, I am working on a similar issue
root@bt:~# hydra -s 80 -l admin -P Desktop/login.txt localhost http-get-form "/vulnerabilities/brute/index.php:username=^USER^&password=^PASS^&Login=Login:Username"
Hydra v6.2 (c) 2011 by van Hauser / THC and David Maciejak - use allowed only for legal purposes.
Hydra (http://www.thc.org/thc-hydra) starting at 2012-03-10 11:58:04
[DATA] 5 tasks, 1 servers, 5 login tries (l:1/p:5), ~1 tries per task
[DATA] attacking service http-get-form on port 80
[STATUS] attack finished for localhost (waiting for children to finish)
[80][www-form] host: 127.0.0.1 login: admin password: root
[80][www-form] host: 127.0.0.1 login: admin password: pass
[80][www-form] host: 127.0.0.1 login: admin password: password
[80][www-form] host: 127.0.0.1 login: admin password: admin
[80][www-form] host: 127.0.0.1 login: admin password: user
Hydra (http://www.thc.org/thc-hydra) finished at 2012-03-10 11:58:05 -
Anonymous19 March 2012 11:15
i dont even get an error... hydra just restars even when trying your exact example
Reply -
Anonymous24 March 2012 20:15
Hi everyone,
Reply
I have insert a right password in pass.txt but I think that hyra doesn't found that password, infact I have the similar output of "Anonymous Mar 10, 2012 02:10 AM" (hydra doesn't show me the password)
I use hydra 6.5 on ubuntu and I'll want found my password on wordpress (last version) site.
Could you help me, please?
Thank you very much!! -
Guys,
Reply
You need to tell Hydra the difference between success and failure. Otherwise it will never work (it's not magic you know).
My best advice to you all, is open wireshark and LOOK at what is happening.
(then you will have a much better understanding of what is going on, which is essential if you want to progress with this sort of thing).
Regards
Ben -
Anonymous17 May 2012 10:43
root@bt:~# hydra -L /root/user.txt -P /root/pass.txt 192.168.xxx.xxx http-get-form "/dvwa/vulnerabilities/brute/index.php:username=^USER^&password=^PASS^&Login=Login:Username and/or password incorrect.:H=Cookie: security=low; PHPSESSID=xxxxxxxxxxxxxxxxxxxxxxxxxxxx" <- your session ID here
Reply -
Miss K17 May 2012 14:51
ok so basically, this is what I write: hydra -L users.txt -P words.txt -t 10 -v 1
Reply
92.168.xx.xxx https-post-form "/YYYYY/ZZZZZZ/Login.aspx:UserNa
me=^USER^&Password=^PASS^:bad login!!!:S=SUCCESS!!!!" but it just doesnt give me "bad login!!!" nor "SUCCESS!!!!". It just give me the html code of the webpage I'm trying to attack, followed by the numerous username and password combination tryouts. I'm sure I used the right username in the users.txt file and the right password in the words.txt file. What's wrong with my request? Please note that the "xx.xxx" are real numbers and the ip adress is valid, and that the Ys and the Zs are also real names and that the web page is valid. -
Apparently there is a problem with the with http-form-get feature, because when I am in debug mode I can explicitly see the message return by the server and see when the log show a good authentication, but actually hydra do not show me that the login is correct...
I can give you debug files ... -
The feature works fine.
What you need to do, is read and follow the methodology I described.
You need to tell Hydra what "success" is.
So, what is the difference in response (HTML and header) between success and failure?
Then use that. -
Anonymous22 June 2012 13:11
i don't want to add user.txt & password.txt for combinations within hydra as i don't know username and password , then how to use hydra..........
Reply -
Hydra is mainly used for performing a dictionary attack.
Reply
If that is not what you want to do, you are probably in the wrong place, and using the wrong tool.
posted on 2012-07-03 13:14 Richard.FreeBSD 阅读(4566) 评论(0) 编辑 收藏 举报
nice article, thx !
Reply