Sunday, December 27, 2015

BASH script for creating lookup cards

So I came up with this idea to create lookup cards. This is my own idea for premcoputed hash password lookups. Basically you read through your wordlist and create a file named for each hash. Then if you want to look up the hash you just you use cat <hash> and it will cat out the file. Once you start to have a lot of these files it will take linux a while to find them or count and index them. When you have like a million files in a folder and you ls through them it takes for ever. So probably the best way to go about this to index the files in other files. Sort them into some kind of order. Maybe loop through and sort them by the their first few characters into files then create a directory.

Anyhow this is a fast way to lookup the hashes. You can create a folder for each wordlist for each hash type. So looking up a hash is as easy as this.

cat /root/wordlists/rockyou/md5/d6a6bc0db10694a2d90e3a69648f3a03

Cat will return the plaintext hacker because the plaintext is the only thing stored in the file d6a6bc0db10694a2d90e3a69648f3a03 if that makes sense.

This look up method is as fast or faster than any other precomputed lookup method I have tried and it doesn't require any special programs to lookup the hashes.

Example:
#!/bin/bash
cat all.txt | while read line
do

echo $line | openssl sha1 |sed -e "s/(stdin)= //g" > temp1.txt
echo $line > temp2.txt
cat temp1.txt temp2.txt > temp3.txt
donkey=$(head -n 1 temp3.txt)
cat temp3.txt > "${donkey}.txt"
rm temp1.txt temp2.txt temp3.txt
done

BASH read from a file and do something with it.

#!/bin/bash
cat $filename |   # Supply input from a file.
while read line   # As long as there is another line to read ...
do

echo $line

done

BASH merging wordlists

I'm taking a break from C++ because I'm at that point in my code folder where I keep some batch and python scripts. I thought this might be relevant. So here's something I did when I was working with big wordlists and I was just running out of RAM. I had to split the wordlists down into more manageable chunks, sort them and merge them back together.

#!/bin/bash
count=0
nums=$(ls -l | grep -v ^l | wc -l)
echo "Processing $(ls -l | grep -v ^l | wc -l) original files"

for i in $( ls ); do

 echo "Processing $i"

 # this will sort each text file alphnumerically and cut strings shorter than 8 characters and loner than 63 $i

((count ++))
echo "creating temp file"
mv $i temp.txt
echo "deleting strings containing more than 63 characters"
cat temp.txt | nawk '{str=$0; if (gsub(".", "") <= 63) print str}' > temp1.txt
echo "deleting temp file"
rm temp.txt
echo "deleting strings containing less than 8 characters"
cat temp1.txt | nawk '{str=$0; if (gsub(".", "") >= 8) print str}' > temp2.txt
echo "deleting temp file"
rm temp1.txt
echo "sorting file alphanumerically and deleting duplicates"
cat temp2.txt | sort -i -u > $i
echo "deleting temp file"
rm temp2.txt
echo "$count / $nums complete"
done
echo "merging files with alphanumeric sort and deleting duplicates"
echo "$( ls )"
echo "This will take some time"
cat *txt | sort -i -u > newmergedfile.txt
mkdir newdir
mv newmergedfile.txt newdir
echo "removing original text files"
rm *txt


echo "the new file contains $(wc -l < newdir/newmergedfile.txt) 8-63 character strings and is $(wc -c < newdir/newmergedfile.txt) bytes"

Dictionary expander written in C (not mine)

/****************************************************************************/
/* (C) Copyright 1992 Universidade Estadual de Campinas (UNICAMP)           */
/*                    Campinas, SP, Brazil                                  */
/*                                                                          */
/* Authors:                                                                 */
/*                                                                          */
/*   Tomasz Kowaltowski  - CS Dept, UNICAMP <tomasz@dcc.unicamp.ansp.br>    */
/*   Claudio L. Lucchesi - CS Dept, UNICAMP <lucchesi@dcc.unicamp.ansp.br>  */
/*   Jorge Stolfi        - DEC Systems Research Center <stolfi@src.dec.com> */
/*                                                                          */
/* This file can be freely distributed, modified, and used for any          */
/*   non-commercial purpose, provided that this copyright and authorship    */
/*   notice be included in any copy or derived version of this file.        */
/*                                                                          */
/* DISCLAIMER: This software is offered ``as is'', without any guarantee    */
/*   as to fitness for any particular purpose.  Neither the copyright       */
/*   holder nor the authors or their employers can be held responsible for  */
/*   any damages that may result from its use.                              */
/****************************************************************************/

/* Last modified on Sun Aug  2 01:57:14 PDT 1992 by stolfi                  */

/* Expands a shrunken wordlist.
 *
 * Usage: expanddict.c < foo.shrunk > foo
 *
 * This program assumes each line of stdin contains a word,
 * consisting of a "prefix length", a "suffix" and a newline.
 * The prefix length is an integer in [0..35], encoded as a single
 * byte [0-9A-Z], which represents that many characters from
 * the beginning of the previous word. (In particular, the
 * prefix lengt of the first word is zero.)  The suffix
 * is simply the rest of the word.
 *
 * For instance, the word list
 *
 *    baby
 *    back
 *    backs
 *    backstage
 *    backup
 *    bath
 *    cobalt
 *    cobra
 *
 * would be encoded as
 *
 *    0baby
 *    2ck
 *    4s
 *    5tage
 *    4up
 *    2th
 *    0cobalt
 *    3ra
 *
 */

#include <stdio.h>

#define MAXLENGTH 1000

void main()
{
  int c, n, i;
  char w[MAXLENGTH];
  int w_len = 0;
  int bytes_read = 0;
  int bytes_written = 0;
  int words = 0;
 
  /* Loop on words: */
  while ((c = getchar()) != EOF)
    {
      ++bytes_read;
      if ((c >= '0') && (c <= '9'))
        n = c - '0';
      else if ((c >= 'A') && (c <= 'Z'))
        n = c - 'A' + 10;
      else
        { fprintf(stderr, "** bad prefix char at byte %d\n", bytes_read);
          exit(1);
        }
       
      if (n > w_len)
        { fprintf(stderr, "** bad prefix length at byte %d\n", bytes_read);
          exit(1);
        }
     
      /* Copy prefix from previous word: */
      for (i = 0; i < n; i++)
        { putchar(w[i]);
          ++bytes_written;
        };
       
      /* Copy and save rest of word: */
      while ((c = getchar()) != '\n')
        { ++bytes_read;
          putchar(c);
          ++bytes_written;
          if (n >= MAXLENGTH)
            { fprintf(stderr, "** word too long at byte %d\n", bytes_read);
              exit(1);
            }
          w[n] = c;
          ++n;
        }
      w_len = n;
       
      /* Copy newline: */
      ++bytes_read;
      putchar('\n');
      ++bytes_written;
      ++words;
    }
 
  /* Finalize: */
  fprintf(stderr, "%8d words\n", words);
  fprintf(stderr, "%8d bytes read\n", bytes_read);
  fprintf(stderr, "%8d bytes written\n", bytes_written);

  fclose(stdout);
  fclose(stderr);
}

Comparing strings in C++



#include <iostream>
#include <vector>
using namespace std;
int main ()
{
  std::string password = "hash";
  std::string pass = "hash";

  if ( password==pass){ std::cout << "password found "<< password << endl;
  return 0;
  }else{
cout << "password and pass are not equal" << endl;
}return 0;
}

Unfinished brute force example

Unfinished brute force example doesn't compare inputs just outputs hashes. There's a finished version of this program into another post. Like I said cleaning out my code folder.

//Simplest possible brute force program
//stuff to include
#include <string>
#include <sstream>
#include <iostream>
#include <cctype>
#include <fstream>
#include <stdio.h>
#include <string.h>
#include <openssl/md5.h>
using namespace std;

//variables we'll use the iterate through the string array in nested fashion
int a;
int b;
int c;
int d;
int e;
int f;
int g;

//our character array


//string array for characters we will iterate through
//string alphanum[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};

//main function where all of the magick happens
int main (int argc,char* argv[])

{




for (a=32; a<=126; a++){
for (b=32; b<=126; b++){
for (c=32; c<=126; c++){
for (d=32; d<=126; d++){
for (e=32; e<=126; e++){
for (f=32; f<=126; f++){
for (g=32; g<=126; g++){
//std::string s = static_cast<std::ostringstream&>(std::ostringstream().seekp(0) << alphanum[a] << alphanum[b] << alphanum[c] << alphanum[d] << alphanum[e] << alphanum[f] << alphanum[g]).str();

//std::string str1 (s);

//openssl md5 function
char A[char(a), char(b), char(c), char(d), char(e), char(f), char(g)];
A = new char[7];


//cout << "trying plaintext " << s << " |  md5 hash  "  << endl;






}
}
}
}

}

Open a port on Windows firewall C

If you need to open a port on the firewall in later versions of windows. But you'll have to be admin for it work. So not without some other shellcode. C and C++ are pretty much the same here.

C++

 #include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int main()
{

system("netsh advfirewall firewall add rule name=\"Open Port 9999\" dir=in action=allow protocol=TCP localport=9999");

    return 0;

C
#include <stdio.h>
#include <stdlib.h>

int main()
{
system("netsh advfirewall firewall add rule name=\"Open Port 9999\" dir=in action=allow protocol=TCP localport=9999");
    return 0;
}

Saturday, December 26, 2015

Photo gallery generator

I never finished it. I might get around to it.
//Simple example that converts a wordlist from plaintext to plaintext and hash pair tab delimited.
#include <string>
#include <sstream>
#include <iostream>
#include <cctype>
#include <fstream>

using namespace std;


int main (int argc, char* argv[3])

{ofstream myfile;
myfile.open (argv[2]);

{ string line; ifstream infile (argv[1]);
myfile << "<html>" << endl;
myfile << "<head><title>My Local Webpages</title> </head>" << endl;
myfile << "<body>" << endl;
myfile << "<p>" << endl;
myfile << "<table>" << endl;
myfile << "<tr>" << endl;
if (infile.is_open())

{ while ( getline (infile,line) )

myfile << "<td>" << "<img src='" << line << "'>" << "</img>" << "</td>" << endl;

infile.close();
myfile << "</tr>" << endl;
myfile << "</table>" << endl;
myfile << "</p>" << "</body>" << endl;
myfile.close();
} else cout << "Unable to open file" << endl;
}



return 0; }

yet another page generator

Yet another page generator
//Simple example that converts a wordlist from plaintext to plaintext and hash pair tab delimited.
#include <string>
#include <sstream>
#include <iostream>
#include <cctype>
#include <fstream>
#include "md5.h"
using namespace std;


int main (int argc, char* argv[3])
{


{ofstream myfile;
myfile.open (argv[2]);

{ string line; ifstream infile (argv[1]);
myfile << "<html>" << endl;
myfile << "<head>" << endl;

if (infile.is_open())

{ while ( getline (infile,line) )

myfile << "<title>" << line << "</title>" endl;
myfile << "<meta name='description' content='" << line << md5(line)<< " " << sha1(line) << " " << sha224(line) << " " << sha256(line) << " " sha384(line) << " " << sha512(line) << "'/>"
myfile << "<meta name='keywords' content='" << line << md5(line)<< "," << sha1(line) << "," << sha224(line) << "," << sha256(line) << "," sha384(line) << "," << sha512(line) << "'/>"
}
infile.close();
myfile << "</head><body><table><p>" << endl;
{ string line; ifstream infile (argv[1]);

if (infile.is_open()

{ while ( getline (infile,line) )

myfile << "<tr><td>" << "<b>" line << "</b>" << "</td></tr>" << "<tr><td>" << "<b>" (md5)line << "</b>" << "</td></tr>" << "<tr><td>" << "<b>" sha1(line) << "</b>" << "</td></tr>" << "<tr><td>" << "<b>" sh224(line) << "</b>" << "</td></tr>" << "<tr><td>" << "<b>" sh256(line) << "</b>" << "</td></tr>" << "<tr><td>" << "<b>" sh384(line) << "</b>" << "</td></tr>" << "<tr><td>" << "<b>" sh512(line) << "</b>" << "</td></tr>" << endl;


infile.close();
myfile << "</table>" << endl;
myfile << "</p>" << "</body>" << endl;
myfile.close();
} else cout << "Unable to open file" << endl;

}
}
}
return 0; }

options for hash types

I started to write a better cracker that would support more hash types and give options. Here's some of the options.

#include <string>
#include <sstream>
#include <iostream>
#include <cctype>
#include <fstream>
#include "md5.h"
#include "sha1.h"
#include "sha224.h"
#include "sha256.h"
#include "sha384.h"
#include "sha512.h"
#include <algorithm>
using namespace std;

char* getCmdOption(char ** begin, char ** end, const std::string & option)
{
    char ** itr = std::find(begin, end, option);
    if (itr != end && ++itr != end)
    {
        return *itr;
    }
    return 0;
}

bool cmdOptionExists(char** begin, char** end, const std::string& option)
{
    return std::find(begin, end, option) != end;
}

int main(int argc, char * argv[])
{

{ string line; ifstream infile (argv[2]);

if (infile.is_open())

{ while ( getline (infile,line) )

{

if(cmdOptionExists(argv, argv+argc, "-md5"))
    {
        cout << md5(line) << " " << line << endl;
    }
if(cmdOptionExists(argv, argv+argc, "-sha1"))
    {
    cout << sha1(line) << " " << line << endl;
    }
if(cmdOptionExists(argv, argv+argc, "-sha224"))
    {
        cout << sha224(line) << " " << line<< endl;
    }
if(cmdOptionExists(argv, argv+argc, "-sha256"))
    {
        cout << sha256(line) << " " << line << endl;
    }
if(cmdOptionExists(argv, argv+argc, "-sha384"))
    {
        cout << sha384(line) << " " << line<< endl;
    }
if(cmdOptionExists(argv, argv+argc, "-sha384"))
    {
        cout << sha384(line) << " " << line << endl;
    }
if(cmdOptionExists(argv, argv+argc, "-sha512"))
    {
        cout << sha512(line) << " " << line << endl;
    }
}
}
infile.close();


    }
return 0; }

turn your wordlist into a webpage.

Turn your wordlist into a webpage. I have a better example I will post later and some scripts for making this all happen. I even wrote a program for to create the site maps.

#include <string>
#include <sstream>
#include <iostream>
#include <cctype>
#include <fstream>
#include "md5.h"
#include "sha1.h"
#include "sha224.h"
#include "sha256.h"
#include "sha384.h"
#include "sha512.h"
#include <algorithm>

using namespace std;


int main (int argc, char* argv[3])
{


{ofstream myfile;
myfile.open (argv[2]);

{ string line; ifstream infile (argv[1]);
myfile << "<html>" << endl;
myfile << "<head>" << endl;

if (infile.is_open())

{ while ( getline (infile,line) )

myfile << "<title>" << line << "</title>" << endl;
myfile << "<meta name='description'" << "content='" << line << endl;
myfile << "<meta name='keywords'" << "content='" << line << "," << md5(line)<< "," << sha1(line) << "," << sha224(line) << "," << sha256(line) << "," << sha384(line) << "," << sha512(line) << "'/>" << endl;
}
infile.close();
myfile << "</head><body><table><p>" << endl;
{ string line; ifstream infile (argv[1]);

if (infile.is_open())


{ while ( getline (infile,line) )
myfile << "<tr><td>" << line << "</td></tr>" << "<tr><td>" << md5(line) << "</td></tr>" << "<tr><td><b>" << sha1(line) << "</b></tr></td>" << "<tr><td><b>" << sha224(line) << "</b></tr></td>" << "<tr><td><b>" << sha256(line) << "</b></tr></td>" << "<tr><td><b>" << sha384(line) << "</b></tr></td>" << "<tr><td><b>" << sha512(line) << "</b></tr></td>" << endl;
infile.close();
myfile << "</table>" << endl;
myfile << "</p>" << "</body>" << endl;
myfile.close();
} else cout << "Unable to open file" << endl;

}
}
}
return 0; }


Palindrome wordlist generators C++ ultra simple

I'm not going great lenghts to explain this one. I think I have a better example that I will post in a bit. I'm still cleaning out my code folder.

#include <iostream>

using namespace std;
int a;
int b;
int c;
int d;

}
}
//4 character palindromes
for (a=0; a <= 9; a++){
for (b=0; b <= 9; b++){
cout << b << a << a << b << endl;
}
}
}

SHA512 plaintext pairs

So say you want to make a lookup table for SHA512 hashes. Maybe you want to load it into a MySQL database or create plaintext hash pair lookup cards. Here's an easy way to do that. I wrote bunch of programs that do this kind of stuff. When I was looking for a faster way to look up plaintexts.

You can find the SHA512 C++ files here.
/reads a text file and ouputs plaintext hash pairs to a new file
#include <string>
#include <sstream>
#include <iostream>
#include <cctype>
#include <fstream>
#include "sha512.h"
using namespace std;

int main (int argc, char* argv[])
{
cout << "creating" << argv[2] << endl;
{ofstream myfile;
myfile.open (argv[2]);

{ string line; ifstream infile (argv[1]);

if (infile.is_open())
{

{ while ( getline (infile,line) )
{
myfile << sha512(line) << endl;
myfile << line << endl;
}


infile.close();
}

}
 else cout << "Unable to open file" << endl;

cout << argv[2] << " complete" << endl;
}
}
return 0; }

Automation with system()

The system() function is kinda nice because you can call other programs or scripts from your program with it. Really you an do this with a BASH script so you don't need to write a compiled program. But the benefit here is you can write a program and add it to /usr/bin/ and then run it from then run it. So you can create your own commands essentially. You can also do this with the alias command. Something like this:

alias airecord="ifconfig wlan0 down && macchanger -r wlan0 && ifconfig wlan0 up && gnome-terminal -e airodump-ng -w record mon0"
Also bear in mind there are aleady automated tools for cracking wifi like wifite. That's not really the point. The point is that you might have to make system calls from a program. It can save a lot of coding. Like say you want to download a zip file, extract, and run it. You can do that one line of BASH that you can call from within your program. So it's useful if you want to keep your program as small as possible. You just have to make sure that the program that you are calling is installed.

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int main()
{
system("ifconfig wlan0 down");
system("macchanger -r wlan0");
system("ifconfig wlan0 up");
system("airmon-ng start wlan0");
system("gnome-terminal -e \"airodump-ng mon0\" \" && gnome-terminal -e airodump-ng mon0\"");
    return 0;
}

Creating web directory with ls and some C++

I was saving a lot of webpages to my local machine so I could refer to them even if I was unable to access the internet. But it started getting difficult to organize them. I figured I could make a directory page with links to all of the other pages saved on my machine. That worked ok until I had several hundred pages and I was adding new pages every day. So I decided to write an a little program that would read from my list of urls. You can do this with any list of urls and create a link directory. I'll get the listing with the ls command and pipe the to a text file.
ls /root/Desktop/webpages/ > linklist.txt
 Now I'll run the program and read the linklist and output the html page with with links to all of the pages. You'll have to changes some of the filenames as some of the titles are not going to be link friendly.

I'm sure you could do this more of this automatically by reading the page title from the each file and using that as the anchor text in your links. You could also eliminate bad character combinations that might cause parsing errors for your web browser. I might get around to coding in some other features when I have time or care more.

Usage: program <infile> <outfile>
Example: directorymaker webpages.txt directory.html
//reads through a file created by ls > txt line by line and outputs it to html
#include <string>
#include <sstream>
#include <iostream>
#include <cctype>
#include <fstream>
using namespace std;

int main (int argc, char* argv[2])

//open output file (myfile) so data can be written. Names the output file
{ofstream myfile;
//argv[2] accepts the the file FILEPATH as a commandline argument. Names the output file
myfile.open (argv[2]);

//declare the variable line from our input file (argv[1]) names the FILEPATH to the input file
{ string line; ifstream infile (argv[1]);
//write out our header for html page
myfile << "<html>" << endl;
myfile << "<head><title>directory of local webpages</title></head>" << endl;
//beginning of body and table
myfile << "<body>" << endl;
myfile << "<table>" << endl;

//check if the input file is open
if (infile.is_open())

{ while ( getline (infile,line) )

myfile << "<tr><td>" << "<b>" << "<a href='" << line << "'>" << line << "</a>" << "</b>" << "</td><td>" << endl;

//close the input file
infile.close();

// write out the end of the page
myfile << "</table>" << endl;
myfile << "<p>" << "<a " << "href=" << "\"" << "index.html" << "\">" << "SHA512 hash and plaintext pairs" << "</a>" << "</p>" << endl;
myfile << "<p>" << "<a " << "href=" << "\"" << "code.html" << "\">" << "code and downloads" << "</a>" << "</p>" << endl;
myfile << "<p>" << "<a " << "href=" << "\"" << "sitemap.html" << "\">" << "site map" << "</a>" << "</p>" << endl;
myfile << "<p>" << "<a " << "href=" << "\"" << "advertise.html" << "\">" << "advertise on this site" << "</a>" << "</p>" << endl;
myfile << "<p>" << "pages by vailixi" << "</p>"<< endl;
myfile << "</body>" << endl;
//close the output file
myfile.close();
}
// if the input file cannot be found output a message
else cout << "Unable to open file" << endl;
}

return 0; }

Tuesday, December 22, 2015

Looping through ascii characters in C++

Here's a simple way to loop through all of the normally used printable ascii characters in C++. Declare and integer and step the integer through each value (32 to 126) You can use this for a lot of things. Brute force cracking or generating wordlists, email address lists, IP lists, name lists, or anything where you need to check a lot of character sequences.
#include <iostream>
int i;
using namespace std;

int main()
{
    for (i =32; i<=126; i++)

    cout << char(i) << "-" << endl;
    cout << char(9) << "-" << endl;
    return 0;
}

Simple hash plaintext pair generator

This is a simple plaintext hash pair generator. You write out your pairs and load them to a database for easy lookup. That or just make rainbow tables. Who cares? It's MD5s. You can get the header and C++ file here and and there is a code example. Zedwood's C++ MD5 Function This is probably the simplest hashing implementation in C++ you could ever find. There are a few other examples on zedwood.com.

The program opens your wordlist file and reads through it line by line and outputs the plaintext hash pairs to a new file. Once again probably the shittiest possible use of command line arguments. But it works.

//Simple example that converts a wordlist from plaintext to plaintext and hash pair tab delimited.
#include <string>
#include <sstream>
#include <iostream>
#include <cctype>
#include <fstream>
#include "md5.h"
#include <cstring>
using namespace std;


int main (int argc, char* argv[2])



{ofstream myfile;
myfile.open (argv[2]);

{ string line; ifstream infile (argv[1]);

if (infile.is_open())

{ while ( getline (infile,line) )

myfile << md5(line) << endl;
cout << line << endl;
string t = md5(line);
cout << t << endl;
}

 else cout << "Unable to open file" << endl;
}
return 0; }


Crude way to use command line arguments

I had people tell me this is not the right way to use command line arguements but it works. There's a lot of really good ways to parse command line arguments. And there are a lot better ways than this. But if you're lazy.

#include <iostream>
#include <cstring>
using namespace std;

int main(int argc,char* argv[])
{

std::string str=(argv[1]);

for(std::string::size_type i = 0; i < str.size(); ++i) {
    str(str[i]) << endl;

}

    if (str =="donkey")
    {
    cout << "punch"<< endl;

    } else cout << "kick" << endl;
    return 0;
}

Simple example of C++ and OpenSSL brute force cracking a SHA256 hash

C++/OpnenSSL brute force cracking example. This is a really simple program. Probably the more complicated bits are OpenSSL function and concatenating multiple strings to create a single string variable. Everything else is pretty straight forward. Create a string array and loop each integer variable through it to create the ascii characters we need. You can do this with char() as well if you really want to be dumping char into string is more complicated that concatinating strings so in keeping with keeping thing simple I elected to write the program this way. So basically the program is going to crack a 7character alphalower_numeric password by using nested loops and string array to generate every possible password within that keyspace. For each iteration of the loop the program will generate the SHA256 hash of that plaintext password. It will compare that hash to the hash entered as the command line argument and if the hashes match it will output the plaintext password and tell you the password was found. Pretty simple.


Keep in mind there are a lot of programs that will crack hashes. John The Ripper and OCL Hashcat are great tools. But if you run into a system that uses a hashing algorithm not included with those programs and you have to write your own brute forcing tool this example will give you some idea of a place to start.


Oh yeah almost forgot you can compile it this way. You'll need OpenSSL on another package I can't remember right off the top of my head. So apt-cache search openssl and you'll probably find it.

g++ -o simple /home/steve/Desktop/craigsforce/brutesimple/main.cpp -lssl -lcrypto

Let's have a look at the code:

//simple brute force program C++ and OpenSSL
#include <string>
#include <sstream>
#include <iostream>
#include <cctype>
#include <fstream>
#include <iomanip>
//include our openssl header
#include "/usr/include/openssl/sha.h"
using namespace std;

//variables for iterating through loop
int a;
int b;
int c;
int d;
int e;
int f;
int g;




//string array for characters we will iterate through
string alphanum[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};

//begin openssl function
string sha256(const string str)
{
    unsigned char hash[SHA256_DIGEST_LENGTH];
    SHA256_CTX sha256;
    SHA256_Init(&sha256);
    SHA256_Update(&sha256, str.c_str(), str.size());
    SHA256_Final(hash, &sha256);
    stringstream ss;
    for(int i = 0; i < SHA256_DIGEST_LENGTH; i++)
    {
        ss << hex << setw(2) << setfill('0') << (int)hash[i];
    }
    return ss.str();
}
//end openssl function

int main (int argc,char* argv[])

{

std::string crackhash=(argv[1]);


for (a=0; a<=35; a++){
for (b=0; b<=35; b++){
for (c=0; c<=35; c++){
for (d=0; d<=35; d++){
for (e=0; e<=35; e++){
for (f=0; f<=35; f++){
for (g=0; g<=35; g++){

//concatinate strings variables a, b, c, d, e, f, and g into standard string s
std::string s = static_cast<std::ostringstream&>(std::ostringstream().seekp(0) << alphanum[a] << alphanum[b] << alphanum[c] << alphanum[d] << alphanum[e] << alphanum[f] << alphanum[g]).str();
cout << "password " << s << " hash " << sha256(s) << endl;

//begin string comparison
//compare output of sha256(s) with the user input. if they are the same output the plaintext of s and password found

  std::string passhash = sha256(s);
  std::string password = s;

  if ( passhash==crackhash){ std::cout << "\n\n\n\n\n\n\n\n\n" << "password found\n"<< password << "\n" << passhash << "\n\n\n\n";
  return 0;
  }
}

//end string comparison
}
}

}
}
}
}






return 0; }