-1

I created a Perl script that would use an online website to crack MD5 hashes after the user inputs the hashes. I am partially successful as I am able to get the response from the website, though I need to parse the HTML and display the hash, and corresponding password in clear text to the user. The following is the output snippet I get now:

<strong>21232f297a57a5a743894a0e4a801fc3</strong>: admin</p>

Using regex buddy, I was able to use the following expression [a-z0-9]{32} to match the hash part alone. I need the final output in the following format:

21232f297a57a5a743894a0e4a801fc3: admin

Any help would be appreciated. Thank you!

bAd bOy
  • 33
  • 1
  • 7
  • Take a look at http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags. – simbabque Feb 20 '14 at 13:23
  • 1
    I don't understand the scenario: if it is your website, and the user is already using form elements, why can't you just use the POST / GET parameter? – cypherabe Feb 20 '14 at 13:28
  • Thanks Mpapec. That worked! Cypherabe: It is not my website. I am just using an online hash cracking service. The hash is however sent via the tool and response is parsed. – bAd bOy Feb 21 '14 at 02:16

3 Answers3

2

I think you'd be much better off using HTML::Parser to simply/reliably parse that HTML. Otherwise you're into the nightmare of parsing HTML with regexps, and you'll find that doesn't work reliably.

Brian Agnew
  • 261,477
  • 36
  • 323
  • 432
  • 1. Find a *regex HTML* question. 2. Post a comment answer "use a parser". 3. ???? 4. Profit!! ;p – Qtax Feb 20 '14 at 13:22
  • 2
    I'd like to think actually pointing the OP to a specific Perl HTML parsing module is a little more than that – Brian Agnew Feb 20 '14 at 13:23
  • 1
    I prefer pointing them to [THE parsing HTML question](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags)... :) – simbabque Feb 20 '14 at 13:24
  • Thanks Brian. I am pretty new to Perl. I would require time to figure out using the different modules available. For now, I got this working using the little regex tip from Mpapec. – bAd bOy Feb 21 '14 at 02:21
  • @bAd bOy - I'd perhaps rephrase that as an answer and accept it (or get Mpapec to do it!) – Brian Agnew Feb 21 '14 at 10:03
1

There are a few tools that can handle both fetching and parsing the page for you available on CPAN. One of them is Web::Scraper. Tell it what page to fetch and which nodes (in xpath or CSS syntax) you want, and it will get them for you. I'll not give an example as I don't know your URL.

There is a good blogpost about this on blogs.perl.org by stas that uses a different module that might also be helpful.

simbabque
  • 52,309
  • 8
  • 74
  • 127
0

Here it is:

$str = q{<strong>21232f297a57a5a743894a0e4a801fc3</strong>: admin</p>};
@arr = $str =~ m{<strong>(.+)</strong>(.+)</p>};
print(join("", @arr), "\n");
ulan
  • 23
  • 3