PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : [C++] md5 cracker using wordlist by kekke



Suicide
16.08.2007, 15:55
md5.cpp


#include "md5.h"
#include <iostream>
#include <fstream>

using namespace encrypt;
using namespace std;

int main()
{
cout << "Input hash here: ";
string hash;
getline(cin, hash);
ifstream wordlist("words.txt");
md5 *m;

while(!wordlist.eof())
{
string buffer;
getline(wordlist, buffer);
m = new md5(buffer);
if(m->hash() == hash)
{
cout << "Hash cracked, it is " << buffer << endl;
break;
}
else
cout << "Hash not matching" << endl;
}

cout << "Quitting!\n";
cin.get();
}

namespace encrypt {

void md5::reset()
{
final = false;
memset(m_digest, 0, 16);
memset(m_buffer, 0, 64);
m_len = m_left = 0;
// md5 magic values
m_a = 0x67452301;
m_b = 0xefcdab89;
m_c = 0x98badcfe;
m_d = 0x10325476;
}

void md5::insert(const unsigned char *data, const int size)
{
if (final) return;
const unsigned char *ptr = data;
unsigned char buf[64];
int left;
for (left = (size + m_left); left >= 64; left -= 64) {
if (m_left) {
memcpy(buf, m_buffer, m_left);
memcpy(buf+m_left, ptr, 64-m_left);
ptr += 64-m_left;
m_left = 0;
} else {
memcpy(buf, ptr, 64);
ptr += 64;
}
round(buf);
m_len += 64;
}
if (left) {
m_left = left;
memcpy(m_buffer, ptr, left);
}
}

void md5::finalize()
{
if (final) return;
unsigned char buf[64], pad[64] = {
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
memcpy(buf, m_buffer, m_left);
memcpy(buf+m_left, pad, 64-m_left);
m_len += m_left;
decode(buf+56, m_len << 3);
decode(buf+60, m_len >> 29);
round(buf);
decode(m_digest, m_a);
decode(m_digest+4, m_b);
decode(m_digest+8, m_c);
decode(m_digest+12, m_d);

final = true;
}

void md5::round(const unsigned char *data)
{
unsigned int in[16], a, b, c, d;

a = m_a;
b = m_b;
c = m_c;
d = m_d;

for (int i = 0; i < 16; i++) in[i] = encode(data+i*4);

/* Round 1 */
FF(a, b, c, d, in[ 0], 7, 3614090360u); /* 1 */
FF(d, a, b, c, in[ 1], 12, 3905402710u); /* 2 */
FF(c, d, a, b, in[ 2], 17, 606105819u); /* 3 */
FF(b, c, d, a, in[ 3], 22, 3250441966u); /* 4 */
FF(a, b, c, d, in[ 4], 7, 4118548399u); /* 5 */
FF(d, a, b, c, in[ 5], 12, 1200080426u); /* 6 */
FF(c, d, a, b, in[ 6], 17, 2821735955u); /* 7 */
FF(b, c, d, a, in[ 7], 22, 4249261313u); /* 8 */
FF(a, b, c, d, in[ 8], 7, 1770035416u); /* 9 */
FF(d, a, b, c, in[ 9], 12, 2336552879u); /* 10 */
FF(c, d, a, b, in[10], 17, 4294925233u); /* 11 */
FF(b, c, d, a, in[11], 22, 2304563134u); /* 12 */
FF(a, b, c, d, in[12], 7, 1804603682u); /* 13 */
FF(d, a, b, c, in[13], 12, 4254626195u); /* 14 */
FF(c, d, a, b, in[14], 17, 2792965006u); /* 15 */
FF(b, c, d, a, in[15], 22, 1236535329u); /* 16 */

/* Round 2 */
GG(a, b, c, d, in[ 1], 5, 4129170786u); /* 17 */
GG(d, a, b, c, in[ 6], 9, 3225465664u); /* 18 */
GG(c, d, a, b, in[11], 14, 643717713u); /* 19 */
GG(b, c, d, a, in[ 0], 20, 3921069994u); /* 20 */
GG(a, b, c, d, in[ 5], 5, 3593408605u); /* 21 */
GG(d, a, b, c, in[10], 9, 38016083u); /* 22 */
GG(c, d, a, b, in[15], 14, 3634488961u); /* 23 */
GG(b, c, d, a, in[ 4], 20, 3889429448u); /* 24 */
GG(a, b, c, d, in[ 9], 5, 568446438u); /* 25 */
GG(d, a, b, c, in[14], 9, 3275163606u); /* 26 */
GG(c, d, a, b, in[ 3], 14, 4107603335u); /* 27 */
GG(b, c, d, a, in[ 8], 20, 1163531501u); /* 28 */
GG(a, b, c, d, in[13], 5, 2850285829u); /* 29 */
GG(d, a, b, c, in[ 2], 9, 4243563512u); /* 30 */
GG(c, d, a, b, in[ 7], 14, 1735328473u); /* 31 */
GG(b, c, d, a, in[12], 20, 2368359562u); /* 32 */

/* Round 3 */
HH(a, b, c, d, in[ 5], 4, 4294588738u); /* 33 */
HH(d, a, b, c, in[ 8], 11, 2272392833u); /* 34 */
HH(c, d, a, b, in[11], 16, 1839030562u); /* 35 */
HH(b, c, d, a, in[14], 23, 4259657740u); /* 36 */
HH(a, b, c, d, in[ 1], 4, 2763975236u); /* 37 */
HH(d, a, b, c, in[ 4], 11, 1272893353u); /* 38 */
HH(c, d, a, b, in[ 7], 16, 4139469664u); /* 39 */
HH(b, c, d, a, in[10], 23, 3200236656u); /* 40 */
HH(a, b, c, d, in[13], 4, 681279174u); /* 41 */
HH(d, a, b, c, in[ 0], 11, 3936430074u); /* 42 */
HH(c, d, a, b, in[ 3], 16, 3572445317u); /* 43 */
HH(b, c, d, a, in[ 6], 23, 76029189u); /* 44 */
HH(a, b, c, d, in[ 9], 4, 3654602809u); /* 45 */
HH(d, a, b, c, in[12], 11, 3873151461u); /* 46 */
HH(c, d, a, b, in[15], 16, 530742520u); /* 47 */
HH(b, c, d, a, in[ 2], 23, 3299628645u); /* 48 */

/* Round 4 */
II(a, b, c, d, in[ 0], 6, 4096336452u); /* 49 */
II(d, a, b, c, in[ 7], 10, 1126891415u); /* 50 */
II(c, d, a, b, in[14], 15, 2878612391u); /* 51 */
II(b, c, d, a, in[ 5], 21, 4237533241u); /* 52 */
II(a, b, c, d, in[12], 6, 1700485571u); /* 53 */
II(d, a, b, c, in[ 3], 10, 2399980690u); /* 54 */
II(c, d, a, b, in[10], 15, 4293915773u); /* 55 */
II(b, c, d, a, in[ 1], 21, 2240044497u); /* 56 */
II(a, b, c, d, in[ 8], 6, 1873313359u); /* 57 */
II(d, a, b, c, in[15], 10, 4264355552u); /* 58 */
II(c, d, a, b, in[ 6], 15, 2734768916u); /* 59 */
II(b, c, d, a, in[13], 21, 1309151649u); /* 60 */
II(a, b, c, d, in[ 4], 6, 4149444226u); /* 61 */
II(d, a, b, c, in[11], 10, 3174756917u); /* 62 */
II(c, d, a, b, in[ 2], 15, 718787259u); /* 63 */
II(b, c, d, a, in[ 9], 21, 3951481745u); /* 64 */

m_a += a;
m_b += b;
m_c += c;
m_d += d;
}

}

md5.h


// md5.hh

#ifndef ENCRYPT_MD5_HH
#define ENCRYPT_MD5_HH

#include <string>
using std::string;

namespace encrypt {

/*! \brief Message Digest 5 implementation
*/
class md5 {
unsigned int m_len, m_left;
unsigned char m_digest[16];
unsigned char m_buffer[64];
unsigned int m_a, m_b, m_c, m_d;
bool final;
public:
/*! \brief basic constructor
*/
md5() { reset(); };
/*! \brief construct md5 from a string, useful for passwords
*/
md5(string pass) {
reset();
insert(reinterpret_cast<const unsigned char*>(pass.c_str()), pass.length());
finalize();
};
/*! \brief resets the class to allow reusing
*/
void reset();
/*! \brief insert data to be hashed
*/
void insert(const unsigned char *data, const int size);
/*! \brief writes out remaining bytes and constructs the hash
* \note you need to call reset to be able to use the class for another hash
*/
void finalize();
/*! \brief compare operators oh joy
*/
const bool operator==(const md5 &l) const { if (memcmp(m_digest, l.m_digest, 16)) return false; else return true; }
/*! \brief compare operators oh joy
*/
const bool operator!=(const md5 &l) const { return !(*this == l); }
/*! \brief get the md5 hash in human readable format (hex)
*/
const std::string hash() const {
string hash(32, '0');
for (int i = 0; i < 16; ++i) {
char c = m_digest[i] & 0x0f;
c += c > 0x09 ? 'a' - 10 : '0';
hash[i*2+1] = c;
c = (m_digest[i] & 0xf0) >> 4;
c += c > 0x09 ? 'a' - 10 : '0';
hash[i*2] = c;
}
return hash;
}
/*! \brief get the raw hash
*/
const unsigned char* digest() const { return m_digest; }
private:
void round(const unsigned char *data);
const unsigned int F(const unsigned int x, const unsigned int y, const unsigned int z) { return (x & y) | (~x & z); }
const unsigned int G(const unsigned int x, const unsigned int y, const unsigned int z) { return (x & z) | (y & ~z); }
const unsigned int H(const unsigned int x, const unsigned int y, const unsigned int z) { return x ^ y ^ z; }
const unsigned int I(const unsigned int x, const unsigned int y, const unsigned int z) { return y ^ (x | ~z); }
unsigned int rot_left(const unsigned int x, const int n) { return (x << n) | (x >> (32-n)); }
void FF(unsigned int &a, const unsigned int b, const unsigned int c, const unsigned int d, const unsigned int x, const unsigned int s, const unsigned int ac) {
a += F(b, c, d) + x + ac;
a = rot_left(a, s);
a += b;
}
void GG(unsigned int &a, const unsigned int b, const unsigned int c, const unsigned int d, const unsigned int x, const unsigned int s, const unsigned int ac) {
a += G(b, c, d) + x + ac;
a = rot_left(a, s);
a += b;
}
void HH(unsigned int &a, const unsigned int b, const unsigned int c, const unsigned int d, const unsigned int x, const unsigned int s, const unsigned int ac) {
a += H(b, c, d) + x + ac;
a = rot_left(a, s);
a += b;
}
void II(unsigned int &a, const unsigned int b, const unsigned int c, const unsigned int d, const unsigned int x, const unsigned int s, const unsigned int ac) {
a += I(b, c, d) + x + ac;
a = rot_left(a, s);
a += b;
}
unsigned int encode(const unsigned char *data) { return data[0] | data[1] << 8 | data[2] << 16 | data[3] << 24; }
void decode(unsigned char* data, const unsigned int in) {
data[0] = in & 0xFF;
data[1] = (in >> 8) & 0xFF;
data[2] = (in >> 16) & 0xFF;
data[3] = (in >> 24) & 0xFF;
}
};

}

#endif

errox
17.08.2007, 20:53
ist das nicht der source code, der von dem enwicklertypen geschriebn wurde?

mietzetatze
17.08.2007, 21:03
Entwicklertyp?H4X0R007?Der ist eine 14jähriger Hobbyprogger wie ich!Entwickler tse....:D Wenn du es schaffst Programme wie 3ds max usw. zu proggen dann kann man denjenigen auch ENTWICKLER NENNEN :D

errox
18.08.2007, 14:14
http://de.wikipedia.org/wiki/Message-Digest_Algorithm_5

styl0r^
19.08.2007, 00:09
Lol,
Nachdem ich das Ding compiled und ausgeführt hab, hats mir grade so dermaßen den Speicher zerrissen, dass ich neustarten musste...