{"id":25539,"date":"2020-02-19T13:55:22","date_gmt":"2020-02-19T08:25:22","guid":{"rendered":"https:\/\/www.armourinfosec.com\/?p=25539"},"modified":"2020-03-30T13:27:26","modified_gmt":"2020-03-30T07:57:26","slug":"performing-rule-based-attack-using-hashcat","status":"publish","type":"post","link":"https:\/\/www.armourinfosec.com\/performing-rule-based-attack-using-hashcat\/","title":{"rendered":"Performing Rule Based Attack Using Hashcat"},"content":{"rendered":"
This post will focus on Performing Rule Based Attack Using Hashcat. It’s a way of using a dictionary or multiple dictionaries of words in order to crack a password in Kali Linux. Recently I was writing a blog on hashcat to cracking the hashes but the blog was going long so i thought about to write another blog to explain more about hashcat attacks,so that you can easily crack the has.So the rule-based attack is one of the most complicated of all the attack modes.The reason for this is very simple.the rule-based attack is like a programming language<\/strong> designed for password candidate generation. It has functions to modify,cut or extend words and has conditional operators to skip some, etc.That makes it the most flexible,accurate and efficient attack.<\/p>\n Why re-invent the wheel? Simple answer: regular expressions are too slow. Typically we have to generate 1.000.000.000<\/strong> (or more) fresh password candidates in less than 10 ms<\/strong> before hashing algorithms start to become idle, and then again and again, second after second. Just take a look at your GPU speed display to get an idea of it.<\/p>\n <\/p>\n To start, we will create some rules to do basic manipulation of the characters.<\/p>\n From the above table, we will put in our rules file the lowercase, uppercase and capitalize functions:<\/p>\n The colon entry instructs hashcat to try the original word.We’ll be including this so we can compare how many passwords were cracked using unmodified passwords from the wordlist.<\/p>\n We\u2019ll also append to the end of the passwords the characters one to\u00a0nine individually:<\/p>\n To express multiple functions in a single rule, you can separate them with a space like the following:<\/p>\n In this case we are appending characters one, two and three to the end of our passwords.(i.e. the password is root it will convert to root1234 ), And if you want to append multi combination (i.e. $5 $ 5 it will be root55)<\/p>\n You can substitute one character for another, by doing the following:<\/p>\n Where X is the character to replace and Y is the new character.<\/p>\n For this demonstration,we will substitute the following letters for their commonly used alternatives:<\/p>\n To express these as rules in a hashcat file, it looks like:<\/p>\n The final rules we’ll add inserts the word “root” before and after the password:<\/p>\n From the above, notice we’ve also included “Root” with a capital “R” before the password.<\/p>\n Now that we have covered the different rules we\u2019re going to use, make sure you have created a file called \u201crules\u201d that contains the following rules<\/p>\n The lines beginning with a “#” are used to indicate to hashcat that the line is a comments.<\/p>\n Now that we have our rules file and providing you have the Root hashes and rockyou password dictionary, we are ready to start cracking the password hashes.<\/p>\n In order to log\u00a0the effectiveness of our rules, we\u2019ll make use of hashcat’s debug\u00a0commands. The debug option in hashcat works\u00a0by logging a rule to a file every time it successfully cracks a password.<\/p>\n To run our rule-based attack, we will use the following command:<\/p>\n <\/p>\n -m 0<\/td>\n The attack mode (Wordlist + Rule)<\/p>\n Identify the hash as MD5.<\/p>\n <\/td>\n<\/tr>\n <\/p>\n –force<\/td>\n To\u00a0 run hashcat forcefully<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n <\/p>\n After following the steps above, when you run the command the output will look like..<\/p>\n <\/p>\n however we do not know how many passwords each rule cracked.To find this information, this is where our debug file comes in. If we look at its contents right now…<\/p>\n Matched rules in cracking It is worth mentioning that hashcat contains some rule files by default.These are located in the “rules” folder of your hashcat installation:<\/p>\n In this guide, we created \u00a0and used our own custom rules in hashcat to perform a rule-based attack. We started by covering what rule-based attacks are and why they are used. We then proceeded to create our own rules and use the rockyou dictionary to crack MD5 hashes.<\/p>\n","protected":false},"excerpt":{"rendered":" Performing Rule Based Attack Using Hashcat This post will focus on Performing Rule Based Attack Using Hashcat. It’s a way…<\/p>\n","protected":false},"author":1,"featured_media":25631,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,90],"tags":[],"yoast_head":"\n
\n<\/span><\/p>\nRule-based Attack<\/h3>\n
Why not stick to regular expressions<\/h3>\n
Compatibility to other rule engines<\/h3>\n
\n\n
\n Name<\/strong><\/td>\n Function<\/strong><\/td>\n Description<\/strong><\/td>\n Example Rule<\/strong><\/td>\n Input Word<\/strong><\/td>\n Output Word<\/strong><\/td>\n<\/tr>\n<\/thead>\n\n \n Nothing<\/td>\n :<\/td>\n Do nothing<\/td>\n :<\/td>\n p@ssW0rd<\/td>\n p@ssW0rd<\/td>\n<\/tr>\n \n Lowercase<\/td>\n l<\/td>\n Lowercase all letters<\/td>\n l<\/td>\n p@ssW0rd<\/td>\n p@ssw0rd<\/td>\n<\/tr>\n \n Uppercase<\/td>\n u<\/td>\n Uppercase all letters<\/td>\n u<\/td>\n p@ssW0rd<\/td>\n P@SSW0RD<\/td>\n<\/tr>\n \n Capitalize<\/td>\n c<\/td>\n Capitalize the first letter and lower the rest<\/td>\n c<\/td>\n p@ssW0rd<\/td>\n P@ssw0rd<\/td>\n<\/tr>\n \n Append Character<\/td>\n $X<\/td>\n Append character X to end<\/td>\n $1<\/td>\n p@ssW0rd<\/td>\n p@ssW0rd1<\/td>\n<\/tr>\n \n Prepend Character<\/td>\n ^X<\/td>\n Prepend character X to front<\/td>\n ^1<\/td>\n p@ssW0rd<\/td>\n 1p@ssW0rd<\/td>\n<\/tr>\n \n Replace<\/td>\n sXY<\/td>\n Replace all instances of X with Y<\/td>\n ss$<\/td>\n p@ssW0rd<\/td>\n p@$$W0rd<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n Writing our rule-set:<\/h3>\n
:\r\nl\r\nu\r\nc<\/pre>\n
$1\r\n$2\r\n$3\r\n$4\r\n$5\r\n$6\r\n$7\r\n$8\r\n$9<\/pre>\n
$1 $2 $3 $4<\/pre>\n
sXY<\/pre>\n
\n
sa@\r\nse3\r\nsl1\r\nsa@ se3 sl1\r\nsa@ se3 ss&<\/pre>\n
^R ^o ^o ^t\r\n^r ^o ^o ^t\r\n$r $o $o $t<\/pre>\n
:\r\n#Lowercase\r\nl\r\n#Uppercase\r\nu\r\n#Capitalise first character\r\nc\r\n#Add '1' to the end\r\n$1\r\n#Add '2' to the end\r\n$2\r\n#Add '3' to the end\r\n$3\r\n#Add '4' to the end\r\n$4\r\n#Add '5' to the end\r\n$5\r\n#Add '6' to the end\r\n$6\r\n#Add '7' to the end\r\n$7\r\n#Add '8' to the end\r\n$8\r\n#Add '9' to the end\r\n$9\r\n#Add '123' to the end\r\n$1 $2 $3\r\n#Substitute 'a' for '@'\r\nsa@\r\n#Substitute 'e' for '3'\r\nse3\r\n#substitute 'l' for '1'\r\nsl1\r\n#Substitute 'a' for '@', 'e' for '3', 'l' for '1'\r\nsa@ se3 sl1\r\n#Add the word 'root' to the beginning\r\n^R ^o ^o ^t\r\n#Add the word 'root' to the beginning\r\n^r ^o ^o ^t\r\n#Add the word 'root' to the end\r\n$r $o $o $t<\/pre>\n
Running the\u00a0Rule-Based Attack<\/h3>\n
hashcat -a 0 -m 0 target_hash\/mayhem.hash \/usr\/share\/wordlists\/rockyou.txt -r rules --debug-mode=1 --debug-file=matched.rule --force\r\n<\/pre>\n
<\/p>\n
\n\n
\n Argument<\/strong><\/td>\n Meaning<\/strong><\/td>\n<\/tr>\n \n -a 0<\/p>\n <\/p>\n \n target_hash\/mayhem.hash<\/td>\n The hash file to use.<\/td>\n<\/tr>\n \n \/usr\/share\/wordlists\/rockyou.txt<\/td>\n The rockyou wordlist.<\/td>\n<\/tr>\n \n -r rules<\/td>\n Points hashcat to our rules file called \u201crules\u201d.<\/td>\n<\/tr>\n \n –debug-mode=1<\/td>\n Writes the rule whenever it successfully cracks a password.<\/td>\n<\/tr>\n \n –debug-file=matched.rule<\/p>\n The name of the debug file where the matched rules are stored.Store every password when it cracked.<\/p>\n
<\/span><\/figcaption><\/figure>\n<\/p>\n
cat matched.rule\r\nsort matched.rule | uniq \u2013c<\/pre>\n
<\/p>\n
\n<\/span>So i got the output of hashes,hope this will help you to resolve queries of cracking the hash with hashcat.As previously mentioned, only the commonly used rule functions were covered in this tutorial. To view a full list of available rule functions, you can do so on the hashcat website here<\/a>.Additionally recommend you to..<\/p>\nUsing Existing Rule Files<\/h3>\n
ls -l \/usr\/share\/hashcat\/rules\/<\/pre>\n
Summary<\/h2>\n