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;
}